Home arrow Web Services arrow Page 2 - Deploying an EJB Application

Deploying an EJB Application

This article shows you how to deploy an EJB application, and more. Picking up where the previous article left off, it is the third of three parts. It 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).

Author Info:
By: Sams Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 10
June 01, 2006
  1. · Deploying an EJB Application
  2. · Configuring Axis to Invoke the SkatesService Session Bean
  3. · EJB Wrap-Up
  4. · JSR109 Client Code

print this article

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"?>
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

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.
<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"
<parameter name="homeInterfaceName"
SkatesProductsHome"/> ... ... </service>

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

>java org.apache.axis.client.AdminClient 

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/

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 =
Price =
Description =
The latest inlines from Supertastix—these are worth
every penny!

blog comments powered by Disqus

- Dealing with Loose Coupling in a Service-Ori...
- Loose Coupling in a Service-Oriented Archite...
- Safety, Idempotence, and the Resource-Orient...
- The Resource-Oriented Architecture in Action
- Features of the Resource-Oriented Architectu...
- The Resource-Oriented Architecture
- 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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials