Friday, June 22, 2012

Publishing Web Service Quickly with Java Technology

javax.xml.ws.EndPoint can be used to publish a webservice without any Application Server or Servlet Container. It uses HTTP Server that comes with Java.
The static method publish takes the String endpoint address and web service implementor class object as parameter.


public class EndpointPublish {
 public static void main(String[] args) {
  Endpoint.publish("http://localhost:8088/ws/SiddMyTestWS", new SimpleHellowServiceImpl  ());
 }
}

For example just running the above stand alone java program, we are able to publish a webservice with the address http://localhost:8088/ws/SiddMyTestWS.


Where MyWSTest is the implemented Endpoint class. Implemented EndPoint class in JAX-WS should have the following properties




  • The implemented class should be annotated  javax.jws.WebService or javax.jws.WebServiceProvider.
  • The implemented class should not be final or abstract.
  • Exposed web service method should be annotated with javax.jws.WebMethod.
  • Web service method cannot be final or static.
  • Web Service method cannot declare finalize method.

Our web service class looks like the following,

@WebService
public class SimpleHellowServiceImpl  {
 //@Override
 public String sayHi(String toName) {
  // TODO Auto-generated method stub
  return "Hello Ji " + toName;
 }
 
}

No comments :

Post a Comment