Java
  Home arrow Java arrow Page 12 - Using RPC-Style Web Services with J2EE
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Using RPC-Style Web Services with J2EE
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2004-12-08

    Table of Contents:
  • Using RPC-Style Web Services with J2EE
  • Web Service Overview
  • Web Service Technologies and Protocols
  • Web Services for J2EE
  • RPC-Oriented Web Services
  • Creating a Simple Service
  • The WSDL File
  • Creating the Web Service WAR
  • The Web Services Deployment Descriptor
  • Building More Robust Web Services
  • Exposing EJBs Through Web Service Protocols
  • Web Service Compiler Configuration File
  • Configuring the EJB Component
  • Other Considerations for Web Services
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using RPC-Style Web Services with J2EE - Web Service Compiler Configuration File
    (Page 12 of 15 )

    As with the servlet-based Web Service, you will need to provide additional information in addition to the standard J2EE deployment descriptor for this type of component. In the J2EE Reference Implementation, you again use wscompile to generate this information. The configuration file used to generate the artifacts for the agency Service bean, shown in listing 20.10, is almost identical to that for the servlet-based Web Service, as shown in Listing 20.3 (only the names have changed).

    Listing 20.10 wscompile Web Service Configuration File (config-service.xml)

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration 
    xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
    <service 
    name="AgencyService" 
    targetNamespace="urn:J2EE21Agency" 
    typeNamespace="urn:J2EE21AgencyTypes" 
    packageName="agency">
    <interface name="agency.Service"/>
    </service>
    </configuration>

    The wscompile command line is identical to that for the servlet-based Web Service, and the same files will be produced, namely the WSDL description and the mapping.xml file.

    As before, the sample code is on the Web site that accompanies this book. As it forms the basis of the exercise, you will find this example in the exercise directory for Day 20. With the code supplied on the accompanying Web site, you can use the following Ant command to build the supplied agency Web Service, which includes the creation of the WSDL and the mapping file:

    asant build

    The WSDL File

    As the interface is different from the greeting service defined earlier, the WSDL generated will also be different. As the findJobsAtLocation() method returns something other than a simple type, a complex type is defined in the types section of the WSDL description:

    <types>
    <schema targetNamespace="urn:J2EE21AgencyTypes"
    xmlns:tns="urn:J2EE21AgencyTypes"
    xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns="http://www.w3.org/2001/XMLSchema">
    <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
    <complexType name="ArrayOfstring">
    <complexContent>
    <restriction base="soap11-enc:Array">
    <attribute ref="soap11-enc:arrayType" wsdl:arrayType="string[]"/>
    </restriction>
    </complexContent>
    </complexType>
    </schema>
    </types>

    Without going into too much detail, the new type—ArrayOfString— is defined to be an unbounded array of the simple string type. This new type is defined in the scope of the urn:J2EE21Agency namespace specified for types in the wscompile configuration file. This ArrayOfString type can then be used later in the WSDL document to define the return type of the findJobsAtLocation operation:

    <message name="Service_findJobsAtLocationResponse">
    <part name="result" type="ns2:ArrayOfstring"/>
    </message>

    As you can see, the findJobsAtLocation response is defined to contain an ArrayOfString, which is scoped to namespace ns2 (ns2 is defined to be urn:J2EE21Types in the overall definitions element). Other than this, the WSDL document is very similar to the greeting service WSDL described earlier.

    The Mapping File

    As you would expect, the mapping file is also very similar to that for the greeting service. It contains nothing specific to the service being implemented by an EJB and simply reflects the changes in the interface, such as the use of the array of strings as a return type:

    <java-wsdl-mapping version="1.1" ...>
    <service-endpoint-interface-mapping>
    ...
    <service-endpoint-method-mapping>
    ...
    <wsdl-return-value-mapping>
    <method-return-value>java.lang.String[]</method-return-value>
    <wsdl-message xmlns:wsdlMsgNS="urn:J2EE21Agency">
    wsdlMsgNS:Service_findJobsAtLocationResponse
    </wsdl-message>
    <wsdl-message-part-name>result</wsdl-message-part-name>
    </wsdl-return-value-mapping>
    </service-endpoint-interface-mapping>
    ...
    </service-endpoint-method-mapping>
    ...
    </java-wsdl-mapping>

    Packaging and Deploying the Agency Web Service Using J2EE RI deploytool

    This section shows how to deploy the simple Web Service to the J2EE RI. As noted before, you will need to start up the PointBase database server and J2EE RI server before starting deploytool.

    Creating the Agency EAR

    By choosing File, Open, load up the Day20/exercise/j2ee-ri/agency.ear enterprise application archive. This defines a single group of Entity beans called Entity which will be used by the Web Service session bean. Highlight the Agency application in the explorer on the left side of the deploytool GUI and its contents will be shown on the right side, as shown in Figure 20.13.

    bond

    Figure 20.13
    Partially built Agency case study EAR.

    You will package up the Web Service in an EJB-JAR file, so choose File, New, Enterprise Bean to create a new one. Click Next to skip the introduction screen and move onto the EJB-JAR file screen. You will be creating your New JAR Module in the Application called agency, so ensure that this option is selected. Next, under JAR Naming, enter "agency-session-ejb" as the File Name.

    Now you can populate your EJB-JAR with the files you saw earlier. Under the Contents section, click the Edit button to display the Edit Contents of agency-session-ejb screen. Browse to find the class files (Service.class and ServiceBean.class), the WSDL file (AgencyService.wsdl), and the mapping file (mapping.xml). You will also need to add the interface definitions for the entity beans used that can be found under the folder Day20\exercise\classes\data. Add each of these files to the contents as shown in Figure 20.14 and click OK.

    bond

    Figure 20.14
    Adding class and configuration files to EJB-based Web Service.

    Now click Next to move onto the General screen. Select agency.ServiceBean as your Enterprise Bean Class (this will be offered from the drop-down list). Ensure that the Enterprise Bean Type is set to Stateless Session. There is no need to define home, local or remote interfaces for this Web Service bean. So click Next to move to the Configuration Options screen.

    Ensure that Expose Bean as Web Service Endpoint is selected and click Next.

    On the Choose Service screen in the Service Definition section, select AgencyService.wsdl as your WSDL File and mapping.xml as your mapping file (these will be offered from the drop-down lists). The other fields will be populated based on the information in the files as shown in Figure 20.15.

    bond

    Figure 20.15
    Service definition for EJB-based Web Service.

    Click Next to move on to the Web Service Endpoint screen. Select agency.Service as your Service Endpoint Interface. In the WSDL Port section, set the Namespace to be urn:J2EE21Agency and ensure that the Local Part becomes ServicePort. In the Sun-specific Settings section, set the Endpoint Address to be jaxrpc/ServiceBean as shown in Figure 20.16.

    bond

    Figure 20.16
    Endpoint configuration for EJB-based Web Service.

    That completes the initial configuration, so click Next followed by Finish. You should be presented with a deploytool screen that looks like Figure 20.17.

    bond

    Figure 20.17
    EJB-based Web Service viewed in deploytool.

    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 Articles
    More By Sams Publishing


       · I am trying to find out how to sign up for the mailing list (Java) but I can't seem...
     

       

    JAVA ARTICLES

    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup
    - Using RPC-Style Web Services with J2EE
    - Integrating XML with J2EE
    - Taming Tiger: Concurrent Collections

    Iron Speed
     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway