Document Version 1.0
Copyright © 2012-2013 email@example.com
JAX-WS Web Service example, JAX-WS web service deployment Tomcat, JAX-WS web service deployment JBoss Glassfish, web service tutorial
However, dependend on if the underly container is a JEE container or Servlet container, the packaging, deplyoment, and even accessing of JAX-WS is also slightly different. In this post, we will show what are the differences exactly by implementing a simple web service, first deploly it in JBoss 7 application server, and than migrate to Servlet Container Tomcat 7.
1. Create a Dynamic Web Project in Eclipse
As development tool we will use "Eclipse IDE for Java EE Developers". We assume you have at least basic knowledge of using Eclipse IDE.
Following the steps to create a dynamic web project in Eclipse:
Select "Dynamic Web Project", click "Next"
Type "JaxWsSample" as Project Name. In the dropdown list of "Dynamic web module version", make sure "3.0" is selected. Click "Next".
Select checkbox "Genereate web.xml deployment descriptor", and click "Finish". Now you have created a web application project named "JaxWsSample" with following directory structure:
Click and open the file "web.xml", you will see the file is almost emtpy except the declaration of name space and schemas. For now will leave this file as it is, since no specific configuration is need to do here for deployment on JEE container.
2. Implement the "JaxWsSample" Web Service
We will create a simple "HelloWorld" web service which has only one operation "sayHello". As mentioned, for JAX-WS style web service, boilerplate code like interfaces are NOT needed any more. In our case, the impementation of the "HelloWorld" service contains only one class, i,e. "HelloWorld.java":
3. Deploy the Web Service in JEE Container JBoss 7
To deploy the "HelloWorld" service in a JBoss 7 container, there is no extra coding or configuration necessary.
What still need to be done is nothing else than packaging the "JaxWsSample" in a "war" archive, and put it in the "deployments" folder of a running JBoss 7 container.
- Start JBoss 7 Application Server in standalone mode
- Export "JaxWsSample" as "JaxWsSample.war"
- The "Destination" should point to the "deployments" directory of the JBoss installation:
We assume the JBoss is up and running, then click "finish" Button in the above window will export the "JaxWsSinmple.war" to JBoss, and the "war" is deployed in JBoss.
Try opening following URL in your Web Browser "http://localhost:8080/JaxWsSample/HelloWorld?wsdl", you will be shown the "wsdl" file of the "HelloWorld" web service.
4. Test "HelloWorld" Web Service using SOAP UI
To test the "HelloWorld" Web Servcie, we need a Web Service Client. We will use SAOP UI for this.
4.1 Download and install SOAP UI
Download SAOP UI from www.soapui.org. After installation, start SOAP UI.
4.2 Create a new SAOP UI project
Create a Web Service (client) project using following WSDL location:
Check the option "Create sample requests for all operations".
After click on the "OK" button, a "HelloWorld" web service client is created in SOAP UI. Open "Request 1".
4.3 Call "HelloWorld" Web Service
Replace the "?" with text "hehe" for the "name" tag of "Request 1". Click the green run button to execute the "sayHello" web service call.
The result of the web service call is show in the "response window":
5. Deploy the Web Service in Tomcat 7
In this section we will try to deploy the "HelloWorld" web service in a servlet container, i.e. Tomcat 7.
Different from JEE Conainer, Tomcat does NOT support JAX-WS out of box. To enable JAX-WS, followings have to be done:
- include "catalina-ws.jar" in Tomcat lib
- include "JAX-WS RI" libs
- configure "jax-ws servlet" in web.xml
- add "sun-jaxws-xml"
5.1 Download Tomcat Extras - "catalina-ws.jar"
Standard Tomcat delivery does NOT has libs supporting JAX-WS. We need to import "catalina-ws.jar" in Tomcat's "lib" directory. "catlina-ws.jar" belongs to Tomcat Extras, which could be downloaded here:
We need to include the JAX-WS runtime libs, i.e. JAX-WS RI (referencial implementation) in Tomcat. The lateste JAX-WS RI (2.2.7) could be downloaded here:
Download and extract the arcive to you favorite location, for example to:
The JAX-WS RI jars could be made available to Tomcat by including them in Tomcat's lib directory. Or you can include the jars in you Web Application's lib directory, in such case, the jars will be only available to the including Web Application.
We will take the second option and copy all jar files under
"JaxWsSample" Eclipse project, and put the jars under
5.3 Configure jax-ws servlet
Change "web.xml" file by adding a "WSServletContextListener" and a "WSServlet":
5.4 Add "sun-jaxws.xml"
Create a "sun-jaxws.xml" file in "WEN-INF" directory with following content:
5.5 Deploy "JaxWsSample.war" in Tomcat 7
We assume the Tomcat 7 is up and running. Export the "JaxWsSample" project as "war" archive in Tomcat's "webapps" direcdory. The deployment will be successful ff you see following info in Tomcat console:
Try opening following URL in your Web Browser "http://localhost:8080/JaxWsSample/hello?wsdl", you will be shown the "wsdl" file of the "HelloWorld" web service.
Please NOTE, the URL to Web Service and WSDL is different as those in JBoss.
5.6 Test "HelloWorld" web service using SAOP UI
Repeat section 4.2-4.3 to test "HelloWorld" web service, when create web service client in SOAP UI, be sure to use "http://localhost:8080/JaxWsSample/hello?wsdl" for WSDL location.
When you have followed all the steps without mistake till now, you would see the correct response of "sayHello".
5.7 Does the "HalloWorld" web service still work when deployed in JBoss 7
Now we have successed "migrated" a JAX-WS web service running on JBoss 7 to Tomcat 7. You might wounder, after all these changes, does the "HelloWorld" service still work in JBoss 7 ? We will find it out now.
Stop Tomcat 7, and hence stop "HelloWorld" in Tomcat.
Start JBoss 7 standardalone server
Copy "JaxWsSample.war" from Tomcat "webapps" directory to "deployments" directory of the JBoss installation.
You would see following info in JBoss 7 console:
The above info indicates that the deployment in JBoss till works!
Further more, you would find that the "HelloWorld" web service works too, and the service is even access able under 2 URLs:
6. To sum it up