1) Create new dynamic web project
2) Copy all jars from glassfish metro JAX-WS (http://jax-ws.java.net/) to WEB-
INF/lib and copy 3 jaxb jars to tomcat's common/endorsed folder
3) Define the Web service class with proper annotations,
@WebService
public class TimeService {
@WebMethod
public String showTime(){
return new Date().toString();
}
}
4) Create sun-jaxws.xml under WEB-INF with endpoint entry for each webservice,
<?xml version="1.0" encoding="ASCII"?>
<runtime:endpoints xmlns:runtime="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<runtime:endpoint implementation="com.jax.sample.TimeService" name="MyTimeService"
url-pattern="/ws/SampleTimeService"/>
</runtime:endpoints>
5) Added servlet mapping and URL mapping entries in web.xml
<servlet>
<servlet-name>WebServiceServlet</servlet-name>
<servlet-
class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WebServiceServlet</servlet-name>
<url-pattern>/ws/SampleTimeService</url-pattern>
</servlet-mapping>
6) Add context listener entry in web.xml
<listener>
<listener-
class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-
class>
</listener>
7) Deploy the webapplication and access the WSDL using the url,
appContext/ws/SampleTimeService?wsdl
Creating java client for webservice
-----------------------------------
1) Create a Java Project
2) new -->> Web Service Client
3) Generate stub classes
4) Use proxy class for invoking the webservice
1) Create a web application
ReplyDelete2) Add the Jersey REST implementation jars to WEB-INF/lib folder
3) Create the web service class as below,
package com.sample.rest;
import javax.ws.rs.*;
@Path("helloworld")
public class HelloWorldResource {
@GET
@Produces("text/plain")
public String getMessage() {
return "Rest Never Sleeps";
}
}
4) Add the Jersey implementation servlet entry in web.xml
servlet-name : RestfulContainer
servlet-class : com.sun.jersey.spi.container.servlet.ServletContainer
init-param
param-name : com.sun.jersey.config.property.packages
param-value :com.sample.rest
servlet-mapping
servlet-name : RestfulContainer
url-pattern : /resources/*
5) Check the WADL file with the below url,
http://localhost:8080/restful/resources/application.wadl
WADL --> Web Application Description Language
6) Invoke the webservice with the below url,
http://localhost:8080/restful/resources/helloworld