Java Tutorial - Java Scipt : Using Web Service DeploymentDescriptors as Web Services

Java Tutorial - Java Scipt :

Using Web Service DeploymentDescriptors as Web Services


Deploying Java Web services through .jws files is quick and easy, but oftentimes we’ll need something more powerful. For example, perhaps we would like to expose an existing EJB as a Web service or exercise more control over the service handlers. Apache Axis provides advanced custom deployment of Java Web services through the Web Service Deployment Descriptor (WSDD) method.

The WSDD deployment method requires you to write an XML deployment descriptor file and an undeployment descriptor file. These files tell Axis how to process a particular call to a Java Web service. Following we have a minimalWSDD deployment file for the SimpleShop service we used as an example earlierin this chapter:
SimpleShop.wsdd:

<?xml version=”1.0” encoding=”UTF-8”?>
<deployment xmlns=”http://xml.apache.org/axis/wsdd/”
xmlns:java=”http://xml.apache.org/axis/wsdd/providers/java”>
<service name=”SimpleShopWsdd” provider=”java:RPC”>
<parameter name=”className” value=”SimpleShop”/>
<parameter name=”allowedMethods” value=”*”/>
</service>
</deployment>

As you can see, this is a very basic file that maps a request to a Java class for handling. We’ll be using the SimpleShop.class file from earlier. Be sure to copy the SimpleShop.class into WEB-INF/classes so that Tomcat can
find the file. Next, check that Axis and Tomcat are running.

Okay, we’re ready to deploy the WSDD for SimpleShop now. Apache Axis has an AdminClient tool that we’ll be using.

On Windows, you use the following command:

java -classpath .;%TOMCAT_HOME%\webapps\axis\WEBINF\
lib\axis.jar;%TOMCAT_HOME%\webapps\axis\WEBINF\
lib\jaxrpc.jar;%TOMCAT_HOME%\webapps\axis\WEB-INF\lib\commons-logging.jar;%T
OMCAT_HOME%\webapps\axis\WEB-INF\lib\commonsdiscovery.
jar;%TOMCAT_HOME%\webapps\axis\WEB-INF\lib\saaj.jar
org.apache.axis.client.AdminClient SimpleShop.wsdd

On Linux, you use this command instead:

java -classpath .:$TOMCAT_HOME/webapps/axis/WEBINF/
lib/axis.jar:$TOMCAT_HOME/webapps/axis/WEBINF/
lib/jaxrpc.jar:$TOMCAT_HOME/webapps/axis/WEB-INF/lib/commons-logging.jar:$TO
MCAT_HOME/webapps/axis/WEB-INF/lib/commonsdiscovery.
jar:$TOMCAT_HOME/webapps/axis/WEB-INF/lib/saaj.jar
org.apache.axis.client.AdminClient SimpleShop.wsdd

Now, let’s check to see if deploying the SimpleShop service through WSDD worked. Open up the following URL:


Now, let’s try undeploying the service. Create the SimpleShopUndeploy. wsdd file.

<?xml version=”1.0” encoding=”UTF-8”?>
<undeployment xmlns=”http://xml.apache.org/axis/wsdd/”
xmlns:java=”http://xml.apache.org/axis/wsdd/providers/java”>
<service name=”SimpleShopWsdd” provider=”java:RPC” />
</undeployment>

Run the Axis AdminClient program again, this time with the undeployment WSDD file to remove the SimpleShop service.

On Windows, use this command:

java -classpath .;%TOMCAT_HOME%\webapps\axis\WEBINF\
lib\axis.jar;%TOMCAT_HOME%\webapps\axis\WEBINF\
lib\jaxrpc.jar;%TOMCAT_HOME%\webapps\axis\WEB-INF\lib\commons-logging.jar;%T
OMCAT_HOME%\webapps\axis\WEB-INF\lib\commonsdiscovery.
jar;%TOMCAT_HOME%\webapps\axis\WEB-INF\lib\saaj.jar
org.apache.axis.client.AdminClient SimpleShopUndeploy.wsdd

On Linux, use this command:
java -classpath .:$TOMCAT_HOME/webapps/axis/WEBINF/
lib/axis.jar:$TOMCAT_HOME/webapps/axis/WEBINF/
lib/jaxrpc.jar:$TOMCAT_HOME/webapps/axis/WEB-INF/lib/commons-logging.jar:$TO
MCAT_HOME/webapps/axis/WEB-INF/lib/commons
discovery.jar:$TOMCAT_HOME/webapps/axis/WEB-INF/lib/saaj.jar
org.apache.axis.client.AdminClient SimpleShopUndeploy.wsdd

Although it is a tad bit more complicated than deploying a Web service as a .jws file, the WSDD deployment method can do things that cannot be done with the simpler deployment method. For example, if you don’t have the
source file, you can still deploy using just the class file with the WSDD deployment method. The most useful WSDD deployment feature is the ability to specify alternate providers. For example, Axis has a java:EJB provider that hooks into EJBs.