Back to Web Services Resources and Tutorials
In addition to JBoss 4.0, you will need the Sun application server (to use the wscompile utility and of course Java SE 5. Links are below. The versions may differ by the time you see this; results are not expected to vary, but the version numbers are provided here as a record of what versions were used during the production of this tutorial:
After installing these packages, prepend the bin directories of the J2SE and Sun app-server packages to your path, and verify that the "all" configuration of your JBoss server starts correctly.Back to Top
Starting with a WSDL FileAs was mentioned in the introduction to this tutorial, we will emphasize interoperability and the use of the WSDL file as the starting point. Create a directory to hold this project and create a subdirectory called wsdl. For this tutorial, the project directory is called tutorial. Within the wsdl directory, create a file called tutorial.wsdl.
A simple example WSDL file for this tutorial can be found here. This isn't a WSDL tutorial, so the details of the file won't be discussed here, other than to note that the portType defines a single operation, "PingRequest", the style is "document" and the use attribute is "literal". The WS-I Basic Profile 1.1 restricts style/use values to RPC/Literal and Document/Literal, while .NET tools (as of this writing) do not support RPC/Literal, so Document/Literal appears to be the best choice for interoperability.
Back to Top
Generating a Simple ServiceAs of JBoss 4.0.x, the recommended tool to use for web service generation is the wscompile tool from the Sun Application Server. This tool is found in the bin directory of the application server.
wscompile operates in 3 modes:
Create a src directory at the top level of your tutorial, then create under it two directories named client and server. Also, at the same level, create a directory called descriptors, where we will store various mapping files and deployment descriptors. At the top level of your tutorial, create a file called config.xml with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<wsdl location="wsdl/tutorial.wsdl"
packageName="com.example"
targetNamespace="http://example.com/schema/tutorial" />
</configuration>
(or get it from here).
Now, generate the server-side classes with the following:
wscompile -import -keep -d src/server -f:documentliteral,wsi config.xml -mapping descriptors/jaxrpc-mapping.xmlNote that classes are generated in the Java package com.example and that a JAX-RPC mapping file has been placed into the descriptors directory. wscompile compiles the classes, in addition to generating them. You will need to modify the server implementation class and rebuild, however.
The wscompile tool created a couple of bean classes corresponding to the complex types defined in the WSDL types section: PingRequestType.java and PingResponseType.java. Since this is just an example web service, modify the server implementation class to return a ping response that combines the ping request with some additional information:
package com.example;
public class TutorialPT_Impl implements com.example.TutorialPT, java.rmi.Remote
{
public com.example.PingResponseType pingRequest(com.example.PingRequestType request)
throws java.rmi.RemoteException
{
com.example.PingResponseType _retVal = new com.example.PingResponseType();
_retVal.setResponseParam("This is the response to request '" + request.getRequestParam() + "'");
return _retVal;
}
}
Recompile by including the jaxrpc-api.jar and jaxrpc-impl.jar
files (from the Sun application server lib directory) in your classpath. At the
top level of your tutorial directory, create a directory called
webapp/WEB-INF/classes(this means we'll be deploying the web service as a servlet) and then execute the following command from the src/server directory, appropriately substituting the path to your installation of the Sun application server:
javac -cp C:/Sun/AppServer/lib/jaxrpc-api.jar;C:/Sun/AppServer/lib/jaxrpc-impl.jar -d ../../webapp/WEB-INF/classes com/example/*.java
Back to Top
Packaging and Deploying the ServiceIn addition to the WSDL file, four deployment descriptors are need to successfully deploy your document/literal web service on JBoss 4.0.x. They are
The ws4ee-deployment.xml file is the JBossWS version of the Axis deploy.wsdd file; it is needed to supply type mappings for your document element classes. The absence or misconfiguration of this file is a common reason for postings related to deployment problems. For this tutorial, the file (which can be found here) looks as follows:
<deployment xmlns='http://xml.apache.org/axis/wsdd/'
xmlns:java='http://xml.apache.org/axis/wsdd/providers/java'
xmlns:soap='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:xsi='http://www.w3.org/2000/10/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<typeMapping xmlns:tutorial="http://example.com/schema/tutorial"
serializer="org.jboss.axis.encoding.ser.BeanSerializerFactory"
encodingStyle=""
qname="tutorial:PingRequest"
deserializer="org.jboss.axis.encoding.ser.BeanDeserializerFactory"
type="java:com.example.PingRequestType" />
<typeMapping xmlns:tutorial="http://example.com/schema/tutorial"
serializer="org.jboss.axis.encoding.ser.BeanSerializerFactory"
encodingStyle=""
qname="tutorial:PingResponse"
deserializer="org.jboss.axis.encoding.ser.BeanDeserializerFactory"
type="java:com.example.PingResponseType" />
</deployment>
This file specifies which Java classes are used to serialize and deserialize the
request and response documents of the web service.
It is now time to package and deploy the web service. The four descriptors mentioned above should be in the WEB-INF directory of the webapp; additionally, the WSDL file should be in a directory called wsdl under WEB-INF. The server class files should be in a directory called classes under the WEB-INF directory. The exploded view should look as follows:
webappDir
WEB-INF
- web.xml
- webservices.xml
- jaxrpc-mapping.xml
- ws4ee-deployment.xml
classes
com
example
- PingRequestType.class
- PingResponseType.class
- TutorialPT.class
- TutorialPT_Impl.class
- TutorialService.class
wsdl
- tutorial.wsdl
To package the webservice into a file called tutorial.war, execute the
following command from the tutorial's top-level directory:
jar cvf tutorial.war -C webapp .This file can then be dropped onto the deploy directory of your running JBoss 4.0.x server configuration. To verify that the web service has deployed correctly, go to the ws4ee webapp on JBoss at
http://host:port/ws4ee(substitute your hostname and port number) and click on "View the list of deployed Web services". The next page, called "And now... Some Services" should show your web service in a listing similar to
Back to Top
Back to Web Services Resources and Tutorials