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).
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):
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.
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:
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:
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:
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!