Home arrow Java & J2EE arrow Page 15 - Using RPC-Style Web Services with J2EE

Summary - Java

Web Services provide functionality to the Internet, and are seen as the wave of the future. In this article, Martin Bond explains how to use Web Services protocols to join J2EE application components with any other software that supports those protocols. This excerpt is from Chapter (Day) 20, from Teach Yourself J2EE in 21 Days, second edition, by Martin Bond, et. al. (Sams, 2003, ISBN: 0672325586)

TABLE OF CONTENTS:
  1. Using RPC-Style Web Services with J2EE
  2. Web Service Overview
  3. Web Service Technologies and Protocols
  4. Web Services for J2EE
  5. RPC-Oriented Web Services
  6. Creating a Simple Service
  7. The WSDL File
  8. Creating the Web Service WAR
  9. The Web Services Deployment Descriptor
  10. Building More Robust Web Services
  11. Exposing EJBs Through Web Service Protocols
  12. Web Service Compiler Configuration File
  13. Configuring the EJB Component
  14. Other Considerations for Web Services
  15. Summary
By: Sams Publishing
Rating: starstarstarstarstar / 13
December 08, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Today, you have seen how Web Service protocols and application styles provide a future route for many application integration projects. Web Services provide a framework for the integration of internal or external applications using HTTP and XML. You have seen that Web Service protocols provide a better solution when exposing functionality for integration than existing RPC or Web mechanisms, and you have explored the Web Service functionality offered in J2EE.

You deployed a servlet-based JAX-RPC Web Service and then called this Web Service through a proxy generated from its WSDL. You deployed an EJB-based JAX-RPC Web Service and used the WSDL generated from it to create a Web Service client. You examined how state and lifecycle are handled for Web Service implementations, and you looked at issues around complex type mapping when marshaling between Java objects and XML data types.

Q&A

  1. SOAP uses HTTP as a transport, so does this mean that it is restricted to synchronous interaction?

  2. Any transport can be used for a SOAP message as long as someone creates a binding for it. SOAP bindings have been defined for SMTP, and such bindings can be created for any other transport mechanism, such as FTP or MQSeries, regardless of whether such mechanisms are synchronous or asynchronous.

    Also, although HTTP is inherently synchronous, you can use it to pass XML documents that consist of business "messages" and that form part of a workflow. If the sender of the message is also capable of receiving such messages, it may receive a response of some form at some future point in time. This uses two synchronous interactions to create asynchronous behavior.

  3. Can I use JAX-RPC to send an XML document rather than performing an XML-based RPC call?

  4. Although it is possible to send an XML document as a parameter to an RPC call using JAX-RPC, document-centric interactions are intended to be serviced by the SOAP with Attachments API for Java (SAAJ) and the Java API for XML Messaging (JAXM). You will encounter SAAJ and JAXM in more detail tomorrow.

  5. What sort of information is contained in a WSDL document?

  6. A WSDL document contains two basic types of information. It contains the interface for the Web Service that consists of type information, message definitions (parameters and return types), operation definitions (methods that can be called), port types (groupings of methods), and bindings that define how port types are carried over different transports. A WSDL file also contains specific location information for a Web Service in the form of ports that provide a specific location for an instance of a port type and service descriptions that define groups of ports.

  7. Why can I only expose stateless session EJBs as Web Services under JAX-RPC and not other types?

  8. Although JAX-RPC provides an RPC-style interface to a Web Service, the whole ethos of Web Services is based around a stateless model of operation. The maintenance of state in traditional RPC terms relies on either an ongoing connection or a protocol-specific token being passed. Neither of these suits the style and granularity of Web Service interaction. All Web Service implementations under JAX-RPC for J2EE are required to be stateless, so only stateless session EJBs match this requirement.

Exercises

Today's exercise is to extend the JAX-RPC front end for the Agency case study so that a client can find all the applicants at a specific location. In the exercise directory under Day 20 on the accompanying Web site there is a version of the Agency case you have seen in this chapter. Your task is to add to the Service EJB a method that takes the name of a location and returns an array of strings representing the applicants registered at that location.

The provided files consist of the stateless session bean discussed in this chapter (Service) that allows you to list all the jobs at a particular location.

If you need a few pointers, you should:

  1. Update the Service.java and ServiceImplementation.java files in day20/ exercise/src/agency. You can get a list of applications for a location using the findByLocation method on the ApplicantHome interface.

  2. Build the classes using asant build-service.

  3. Open the ear file created in the build folder and add to the Service EJB an ejb reference for the applicant home interface.

  4. Verify and deploy your EAR to your J2EE RI application server (using deploytool or asant deploy-service).

  5. Update the AgencyServiceClient.java file in day20/exercise/src/client to call your new method.

  6. Build the client using asant build-client and then run it with asant run-client.

A complete solution can be found in the agency folder on the Day 20 folder on the accompanying Web site.

This chapteris fromTeach Yourself J2EE in 21 Days, second edition, byMartin Bond et. al.(Sams, 2004, ISBN: 0-672-32558-6). Check it out at your favorite bookstore today. Buy this book now.



 
 
>>> More Java & J2EE Articles          >>> More By Sams Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: