Web Services
  Home arrow Web Services arrow Page 2 - Deploying an EJB Application
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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? 
WEB SERVICES

Deploying an EJB Application
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2006-06-01

    Table of Contents:
  • Deploying an EJB Application
  • Configuring Axis to Invoke the SkatesService Session Bean
  • EJB Wrap-Up
  • JSR109 Client Code

  • 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
     
     
    ADVERTISEMENT


    Deploying an EJB Application - Configuring Axis to Invoke the SkatesService Session Bean


    (Page 2 of 4 )

    In this section, we describe how to configure the Axis server to enable Web service access to your application. Having deployed the application, you need to set up the EJB provider to be able to invoke the SkatesService bean. This means creating a WSDD that contains the relevant information.


    Figure 7.4  Apache Axis homepage

     
    Figure 7.5  Axis Happiness page

     

    If Axis was running on a separate server, you would also need to ensure that the J2EE.JAR library and the client stubs for the SkatesService bean were in the Axis classpath. The client stubs are produced as part of the deployment process; usually, the deployed EJB JAR file will contain them. However, by deploying Axis and the EJBs as part of the same enterprise application, the J2EE application server ensures that the EJB client code is available to the Axis Web application. This makes life much easier.

    Before running the following commands, create and move to a new directory. The first aim is to create a WSDL file from the SkatesService remote interface. In order to do this, you must run the Apache Java2WSDL tool. It needs both the EJB-JAR file (skatesejb.jar) and the J2EE class library (j2ee.jar):

    >set classpath=%axiscp%;.\skatesejb.jar;<appserv>\
    lib\j2ee.jar >java org.apache.axis.wsdl.Java2WSDL –lhttp://server:port/axis/services/SkatesService com.skatestown.ejb.SkatesProducts

    For this to work, you first need to set the right Axis classpath into the environment variable axiscp. In particular, you need the following files in your classpath:

    • axis.jar

    • commons-discovery.jar

    • commons-logging.jar

    • jaxrpc.jar

    • saaj.jar

    • wsdl4j.jar

    You also need to find the J2EE.JAR library, which will be in your J2EE app server's classpath. You should also set the correct servername and port for your server in the URL.

    If this works, you now have a SkatesService.wsdl file, as shown in Listing 7.4.

    Listing 7.4 SkatesService.wsdl

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions 
    targetNamespace="http://ejb.skatestown.com" 
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:apachesoap="http://xml.apache.org/xml-soap" 
    xmlns:impl="http://ejb.skatestown.com" 
    xmlns:intf="http://ejb.skatestown.com" 
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/
    encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/
    soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdl:types> <schema targetNamespace="http://ejb.skatestown.
    com" xmlns="http://www.w3.org/2001/XMLSchema"> <import namespace="http://schemas.xmlsoap.org/
    soap/encoding/"/> <complexType name="Product"> <sequence> <element name="description" nillable="true"
    type="xsd:string"/> <element name="price" type="xsd:double"/> <element name="productCode" nillable="true"
    type="xsd:string"/> </sequence> </complexType> </schema> </wsdl:types> <wsdl:message name="addProductResponse"> </wsdl:message> <wsdl:message name="viewProductRequest"> <wsdl:part name="in0" type="xsd:string"/> </wsdl:message> <wsdl:message name="viewProductResponse"> <wsdl:part name="viewProductReturn"
    type="impl:Product"/> </wsdl:message> <wsdl:message name="addProductRequest"> <wsdl:part name="in0" type="impl:Product"/> </wsdl:message> <wsdl:portType name="SkatesProducts"> <wsdl:operation name="addProduct"
    parameterOrder="in0"> <wsdl:input message="impl:addProductRequest"
    name="addProductRequest"/> <wsdl:output message="impl:addProductResponse" name="addProductResponse"/> </wsdl:operation> <wsdl:operation name="viewProduct"
    parameterOrder="in0"> <wsdl:input message="impl:viewProductRequest"
    name="viewProductRequest"/> <wsdl:output message="impl:
    viewProductResponse" name="viewProductResponse"/> </wsdl:operation> </wsdl:portType>
    <wsdl:binding name="SkatesServiceSoapBinding"
    type="impl:SkatesProducts"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/
    soap/http"/> <wsdl:operation name="addProduct"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="addProductRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/
    soap/encoding/" namespace=http://ejb.skatestown.com
    use="encoded"/> </wsdl:input> <wsdl:output name="addProductResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/
    soap/encoding/" namespace=http://ejb.skatestown.com
    use="encoded"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="viewProduct"> <wsdlsoap:operation soapAction=""/> <wsdl:input name="viewProductRequest"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/
    soap/encoding/" namespace=http://ejb.skatestown.com
    use="encoded"/> </wsdl:input> <wsdl:output name="viewProductResponse"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/
    soap/encoding/" namespace=http://ejb.skatestown.com
    use="encoded"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="SkatesProductsService"> <wsdl:port binding="impl:
    SkatesServiceSoapBinding" name="SkatesService"> <wsdlsoap:address location="http://localhost:9080/axis/
    services/SkatesService"/> </wsdl:port> </wsdl:service> </wsdl:definitions>

    In order to help deploy this file, you can now run the WSDL2Java tool. This tool creates a deploy.wsdd deployment XML file for Axis that will act as a good starting point; it also creates code with which to call the service. However, the deploy.wsdd file is designed for use with a standard Java class, so you must modify it to work with your EJB application:

    >java org.apache.axis.wsdl.WSDL2Java \
    SkatesService.wsdl -–server-side

    The deploy.wsdd file shown in Listing 7.5 is now located in com\skatestown\ejb\deploy.wsdd.

    Listing 7.5 Generated deploy.wsdd File

    <deployment
    xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/
    providers/java"> <!-- Services from SkatesServiceService WSDL
    service --> <service name="SkatesService"
    provider="java:RPC" style="rpc" use="encoded"> <parameter name="wsdlTargetNamespace" value="http://ejb.skatestown.com"/> <parameter name="wsdlServiceElement" value="SkatesServiceService"/> <parameter name="wsdlServicePort" value="SkatesService"/> <parameter name="className" value="com.skatestown.ejb.
    SkatesServiceSoapBindingImpl"/>
    <parameter name="wsdlPortType" value="SkatesService"/> <operation name="addProduct" qname="operNS:addProduct" xmlns:operNS="http://ejb.skatestown.com" > <parameter name="in0" type="tns:Product" xmlns:tns="http://ejb.skatestown.com"/> </operation> <operation name="viewProduct" qname="operNS:viewProduct" xmlns:operNS="http://ejb.skatestown.com" returnQName="viewProductReturn" returnType="rtns:Product" xmlns:rtns="http://ejb.skatestown.com" > <parameter name="in0" type="tns:string" xmlns:tns="http://www.w3.org/2001/
    XMLSchema"/> </operation> <parameter name="allowedMethods" value="addProduct viewProduct"/> <typeMapping xmlns:ns="http://ejb.skatestown.com" qname="ns:Product" type="java:com.skatestown.ejb.Product" serializer= "org.apache.axis.encoding.ser.
    BeanSerializerFactory" deserializer= "org.apache.axis.encoding.ser.
    BeanDeserializerFactory" encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"/> </service> </deployment>

    The bold sections in Listing 7.5 indicate the incorrect parts of the generated WSDD file. The provider type is java:EJB instead of Java:RPC, and instead of a className parameter, the provider requires beanJndiName and homeInterfaceName parameters, as shown here:

    <service name="SkateService" provider="java:EJB">
    <parameter name="beanJndiName"
    value="ejb/skates/SkatesProductHome"/>
    <parameter name="homeInterfaceName"
    value="com.skatestown.ejb.
    SkatesProductsHome"/> ... ... </service>

    With this file, you can now deploy the service to Axis:

    >java org.apache.axis.client.AdminClient 
    com\skatestown\ejb\deploy.wsdd 
    –lhttp://server:port/axis/servlet/AxisServlet

    The response should be

    Processing file skate.wsdd
    <Admin>Done processing</Admin>

    If you pull up a browser and browse the same servlet at http://server:port/axis/servlet/AxisServlet, you should see the SkatesService listed, as shown in Figure 7.6. You can click (wsdl) to view the WSDL.


    Figure 7.6 SkatesService listing in the Axis admin page

    To test the service, you need to generate a simple command-line client. To do so, create a new directory and rerun WSDL2Java, but this time to generate client objects:

    >java org.apache.axis.wsdl.WSDL2Java \ http://localhost:9080/axis/services/
    SkatesService?wsdl

    Now test the service application using a simple test application like that shown in Listing 7.6. Use this command to run the test:

     >javac com\skatestown\ejb\*.java
    >java com.skatestown.ejb.SkatesTest

    Listing 7.6 Test Application

    package com.skatestown.ejb;
    import java.net.URL;
    public class SkatesTest
    {
    public static void main(String args[])
    throws Exception
    {
    SkatesProductsService sps = new
    SkatesProductsServiceLocator(); SkatesProducts sp = sps.getSkatesService( new URL("http://zak:9080/axis/services/
    SkatesService")); Product p = new Product(); p.setProductCode("Supertastix58s"); p.setPrice(199.0); p.setDescription ("The latest inlines from Supertastix—are worth
    every penny!"); sp.addProduct(p); Product p2 = sp.viewProduct(p.getProductCode()); System.out.println("\nProduct code = "); System.out.println(p2.getProductCode()); System.out.println("\nPrice = "); System.out.println(p2.getPrice()); System.out.println("\nDescription = "); System.out.println(p2.getDescription()); } }

    Note that you'll need to change the host and port in this example in order for it to work.

    The results of running the test application are as follows:

    C:\book\axis>java com.skatestown.ejb.SkatesTest
    Product code =
    Supertastix58s
    Price =
    199.0
    Description =
    The latest inlines from Supertastix—these are worth
    every penny!

    More Web Services Articles
    More By Sams Publishing


       · This article is an excerpt from the book "Building Web Services with Java: Making...
     

    Buy this book now. This article is excerpted from chapter 7 of the book Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418). Check it out today at your favorite bookstore. Buy this book now.

    WEB SERVICES ARTICLES

    - Getting Started with Flex
    - Automated Billing and Faxing for the Web
    - An Introduction to Web Services
    - The Foundations of Web Services: From Novice...
    - Web Services Reengineering: Finishing Touches
    - Fault Handling with Web Services
    - Flow and Web Services
    - Process Lifecycles and Web Services
    - Business Processes and Web Services
    - Orchestrating Web Services
    - Notifications and Resources in the WS-Resour...
    - WS Notification and WS Topics in the WS Reso...
    - Introducing the Implied Resource Pattern
    - Web Services and Stateful Resources
    - Deploying an EJB Application







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