My observation on how a JAX-WS Webservice is deployed to Tomcat when creating a Webservice End-Point in Netbeans

 I was playing with Netbeans today and wanted to see how I would be able to deploy a Webservice. I started by importing all the required Jar file. I used a wizard(Library Manager) so all the required Jars were already placed on my behalf. If you want to add them manually, here is the list of jars that were included in my project(I'm sure you don't need all of these).

 

 

 

 Now, the question in my mind was what if I weren't using netbeans? What if I'm doing all these manually through Ant? Or even without a build tool? I wanted to be able to deploy my webservice so I could access it to a web browser and see if it works. Let's try to create a webservice class first.

 

package com.test.ws.endpoint;

import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService()
public class HelloWorldWS {
  private String message = "Hello, ";
 
  @WebMethod
  public String sayHello(String name){
    return message + name;
  }
 
}

In netbeans, when you create a Webservice using the "New" command then an entry in the web.xml is already made for you. I didn't know this before so I was really puzzled. Here are the entries

 
    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>HelloWorldWS</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorldWS</servlet-name>
        <url-pattern>/HelloWorldWS</url-pattern>
    </servlet-mapping>
 

There's also a file called sun-jaxws.xml create by the Netbeans IDE

<?xml version="1.0" encoding="UTF-8"?>
<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
  <endpoint implementation="com.test.ws.endpoint.HelloWorldWS" name="HelloWorldWS" url-pattern="/HelloWorldWS"/>
</endpoints>


I do not claim that all these assumptions are correct. But studing all these entries gives me the idea that all requests goes to the com.sun.xml.ws.transport.http.servlet.WSServlet and delegated through your Webservice class. The WSServlet does a lookup in your sun-jaxws.xml file(and I do hope so that I'm correct).

 

Invoking the Servlet(http://localhost:8084/WSTest/HelloWorldWS in my machine) would yield this result

 

 And clicking on the link would give you the WSDL

 

What I don't like here is unlike .Net's implementation, there is a page wherein you could click on a method and put some parameters in it. I'd like to see something similar in Java.


Published 09-27-2007 10:05 PM by lamia

Comments

Saturday, October 06, 2007 2:50 AM by Jan Venema

# re: My observation on how a JAX-WS Webservice is deployed to Tomcat when creating a Webservice End-Point in Netbeans

Thank you. I was wondering how I could easily expose my class as a webservice in Tomcat. This is the answer :)

Sunday, October 07, 2007 10:29 PM by lamia

# re: My observation on how a JAX-WS Webservice is deployed to Tomcat when creating a Webservice End-Point in Netbeans

Wow. I didn't think it would help. Thanks to you as well. :)