We have seen that we have successfully created the jax-ws webservice example tutorial and also published and tested the service successfully.

Now we want to deploy the service in Tomcat Server.
Prerequisites

JDK 1.6
Eclipse 3.6
Tomcat Server v7
List of jars
jax-ws webservice example

We have the same endpoint interface and implementation class as we have in the previous tutorial.

Now we need to generate request and response structure. So we will use wsgen command from command prompt. Go to the project root directory. For example, if your project full path is “c:\eclipse_workspace\jax-ws” then go to the project home path(“c:\eclipse_workspace\jax-ws”) and execute the below command in command prompt.

wsgen -s src -d build/classes -cp build/classes in.webtuts.service.HelloImpl

 

You will get two generated classes SayHello.java and SayHelloResponse.java under package in.webtuts.service.jaxws

SayHello.java

package com.roytuts.service.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "sayHello", namespace = "http://service.roytuts.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sayHello", namespace = "http://service.roytuts.com/")
public class SayHello {

    @XmlElement(name = "arg0", namespace = "")
    private String arg0;

    /**
     *
     * @return
     *     returns String
     */
    public String getArg0() {
        return this.arg0;
    }

    /**
     *
     * @param arg0
     *     the value for the arg0 property
     */
    public void setArg0(String arg0) {
        this.arg0 = arg0;
    }

}

 

SayHelloResponse.java

package com.roytuts.service.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "sayHelloResponse", namespace = "http://service.roytuts.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sayHelloResponse", namespace = "http://service.roytuts.com/")
public class SayHelloResponse {

    @XmlElement(name = "return", namespace = "")
    private String _return;

    /**
     *
     * @return
     *     returns String
     */
    public String getReturn() {
        return this._return;
    }

    /**
     *
     * @param _return
     *     the value for the _return property
     */
    public void setReturn(String _return) {
        this._return = _return;
    }

}

 

Now modify the deployment descriptor file so that it looks like below. Add jax-ws webservice listener class.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>jax-ws-ssl</display-name>
  <listener>
    <listener-class>
        com.sun.xml.ws.transport.http.servlet.WSServletContextListener
     </listener-class>
  </listener>
  <servlet>
    <servlet-name>Hello</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/Hello</url-pattern>
  </servlet-mapping>
</web-app>

 

Create another sun-jaxws.xml file and put it under WEB-INF directory. This file is used to recognize the jax-ws endpoint service.

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

 

Now run the web project on Tomcat Server from Eclipse. You can also export the project as war file and put the war file under tomcat’s webapp directory. Run the Tomcat server.

Now access the URL http://localhost:8080/jax-ws-ssl/hello You will get the below output.

Hello Soumitra

 

To access the WSDL directly use URL http://localhost:8080/jax-ws-ssl/hello?wsdl

We will see how to test the service after generating client/stub from the WSDL file in another tutorial.

Thanks for your reading. Please leave a comment if you any query.

Tags:

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Roy Tutorials | TwitterFacebook Google PlusLinkedin | Reddit

Leave a Reply

Your email address will not be published. Required fields are marked *