Showing posts with label Web Service. Show all posts
Showing posts with label Web Service. Show all posts

Sunday, January 27, 2013

When web service methods in implicit SEI are exposed

If you carefully watch/read @WebMethod annotation of JAX-WS API.

You can find that there is an attribute called "exclude" in @WebMethod annotation. Yes! as name suggests it controls whether the method of implicit SEI(Service Endpoint Interface) are exposed or not. 

One important thing is that - you can not use "exclude" attribute of @WebMethod annotation in explicit SEI(Service Endpoint Interface).

Also, there is some restriction of using "exclude" attribute of @WebMethod depending upon the JAX-WS version.

Prior to JAX-WS 2.1.6:
  • The method has an @WebMethod or @WebMethod(exclude=false) annotation and the containing class has an @WebService annotation.
  • The method has no @WebMethod annotation, but the containing class has a @WebWervice annotation and no other methods have @WebMethod or @WebMethod(exclude=false) annotation on it.
On JAX-WS 2.1.6 or Later:
  • The method has an @WebMethod or @WebMethod(exclude=false) annotation.
  • The method has no @WebMethod or @WebMethod(exclude=false) annotation but the containing class has an @WebService annotation.
Example:

public class Message {

    @WebMethod(exclude=false)
    public void send(String s) {...}

    public String accept() {...}
}

@WebService(targetNamespace="foo")
public class MessageImpl extends Message {

    @WebMethod(exclude=false)
    public void sendWrapper(String s) {...}

    public String acceptWrapper() {...}
}

Prior you JAX-WS 2.1.6
public void sendWrapper(String s) {...}

On or After JAX-WS 2.1.6

public void send(String s) {...}
public void sendWrapper(String s) {...}
public String acceptWrapper() {...}


Create a service endpoint implementation for JAX-WS applications with annotations

Before going to steps/procedure creating a service endpoint using JAX-WS annotation, you should read the basic of Endpoint implementation using JAX_WS.


  1. First determine if the service implementation is a JavaBeans endpoint or a Provider endpoint. If you choose to use a JavaBeans endpoint, then determine if you want to use an explicit SEI or if the bean itself will have an implicit SEI.
  2. Annotate the service endpoints. A Java class that implements a Web service must specify either the javax.jws.WebService orjavax.xml.ws.WebServiceProvider annotation. Both annotations must not be present on a Java class. Thejavax.xml.ws.WebServiceProvider annotation is only supported on classes that implement the javax.xml.ws.Provider interface.
    • If you have an explicit service endpoint interface with the Java class, then use the endpointInterface parameter to specify the service endpoint interface class name to the javax.jws.WebService annotation. You can add the @WebMethod annotation to methods of a service endpoint interface to customize the Java-to-WSDL mappings. All public methods are considered as exposed methods regardless of whether the @WebMethod annotation is specified or not. It is incorrect to have an @WebMethod annotation on an service endpoint interface that contains the exclude attribute.
    • If you have an implicit service endpoint interface with the Java class, then the javax.jws.WebService annotation will use the default values for the serviceNameportName, and targetNamespace parameters. To override these default values, specify values for these parameters in the @WebService annotation. If the @WebMethod annotation is not specified, all public methods are exposed including the inherited methods with the exception of methods inherited from java.lang.Object. The exclude parameter of the @WebMethod annotation can be used to control which methods are exposed.
    • If you are using the Provider interface, use the javax.xml.ws.WebServiceProvider annotation on the Provider endpoint.

JAX-WS Web Service Endpoint implementation

In web service development cycle, Endpoint implementation plays a vital role. Actual purpose of the web service is written in Web service endpoint class or technically we can say that web service endpoint contains the business logic.

In this blog post i'll be going to discuss about types of JAX-WS web service endpoint implementation.

In JAX-WS, we have two choice and discuss individually:

1. JavaBeans service endpoint interface.
2. A Provider interface.

JavaBeans service endpoint implementation is same a JAX-RPC. In JAX-WS SEI (Service Endpoint Interface) is optional. The JAX-WS service that do not have an associated SEI are regarded as having implicit SEI. whereas the service have an associated SEI are regarded as having explicit SEI. Unlike JAX-RPC, JAX-WS service not required to implement java.rmi.Remote. It is mandatory in JAX-RPC.

JAX-WS specification leverages support for annotating Java class with other metadata to expose the class as a web service.

If you are decided to use JavaBeans service endpoint interface, then annotate the class with javax.jws.WebService annotation.


If JAX-WS service implementation bean also uses an explicit SEI then endpoint interface name should be used in attribute "endpointInterface" of javax.jws.WebService annotation.

If JAX-WS service implementation bean does not use explicit SEI then service is described by implicit SEI declared in the bean itself.

If you have explicit SEI then you have to annotate the interface with the javax.jws.WebService with the following attributes.

@WebService(name="", targetNamespace="", wsdlLocation="")

and SIB (Service Implementation Bean) should be annotate with the followings:

@WebService(serviceName="", targetNamespace="", endpointInterface="", portName="")


If you are decided to use a new Provider interface, then annotate the class woth javax.jws.WebServiceProvider annotation.

a new Provider API, is more message oriented and this interface has one method named "invoke" and uses generic "Source" to control input and output.










Transitivity rules of WSDL1.1

Transitivity rules of WSDL 1.1
  • A claim on a wsdl:port element is inherited by the referenced wsdl:binding element
  • A claim on a wsdl:binding element is inherited by the referenced wsdl:portType element
  • A claim on a wsdl:portType element is inherited by the referenced wsdl:operation elements
  • A claim on a wsdl:operation element is inherited by the referenced wsdl:message elements of its child wsdl:output and/or wsdl:input elements

Monday, December 31, 2012

WS-I Basic Profile versions

WS-I stands for Web Services Interoperability industry consortium (WS-I). WS-I provides interoperability guidance for core Web Services specifications such as SOAP, WSDL, and UDDI. 

The profile uses Web Services Description Language (WSDL) to enable the description of services as sets of endpoints operating on messages.

WS-I versions are given below:

  1. Version 1.0 of this profile was released in early 2004.
  2.  Version 1.1 published in 2006 does not have the same scope as version 1.0. The part of version 1.0 dealing with serialization of envelopes and their representation in messages has been moved to a new profile called Simple Soap Binding Profile (SSBP)
  3.  Version 1.2 was finalized in November 2010. The main new features are the support for MTOM binary attachments and WS-Addressing
  4.  Version 2.0 was also published in November 2010. It uses SOAP 1.2, UDDI 3 and WS-Addressing
To read more on WS-I please click on this link


 

Friday, September 7, 2012

SSL is not enough for Web Services

SSL is not enough for Web Services, below mentioned are the reasions:

  • Intermediaries - SSL provide point-to-point whole message encription. Intermediaries need encription of parts of messages so that part can be read.
  • Two-way-authentication - Client side SSL required for two way credential management however is very deficult to manage, hence SSL is not suitable for authenticating all kind of web services clients.
  • Authorization - SSL does not handle authorization issues at all.
  • Federation - SSL has no mechanism of federation of web services security credentials which is very necessary in distributed web services environments.

Wednesday, July 20, 2011

Register dynamic Web Service Client Handler


package javawiki.webservice.consumer;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javawiki.webservice.common.LogHandler;
import javawiki.webservice.provider.GetBookDetails;
import javawiki.webservice.provider.LibraryService;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import javax.xml.ws.handler.Handler;
public class ConsumeLibraryService {
 public static void main(String arg[])
 {
  try
  {
   URL url = new URL("http://localhost:8080/libraryservice/LibraryService");
   QName qName = new QName("http://javawikiforbeginners.blogspot.com/JavaLibraryService/","JavaLibraryService");
   Service service = Service.create(url, qName);
   LibraryService libraryService = service.getPort(LibraryService.class);
   BindingProvider bindingProvider = (BindingProvider) libraryService;
   
   List<Handler> handlerChain = new ArrayList<Handler>();
   
   handlerChain.add(new LogHandler());
   
   bindingProvider.getBinding().setHandlerChain(handlerChain);
   
   GetBookDetails aBookDtls = libraryService.getBook("123456");
   System.out.println(aBookDtls.getBook());
  }
  catch(Exception ex)
  {
   ex.printStackTrace();
  }
 }
}



package javawiki.webservice.common;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class LogHandler implements SOAPHandler<SOAPMessageContext>{
 @Override
 public Set<QName> getHeaders() {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void close(MessageContext context) {
  System.out.println("Closing message");
 }
 @Override
 public boolean handleFault(SOAPMessageContext context) {
  // TODO Auto-generated method stub
  return false;
 }
 @Override
 public boolean handleMessage(SOAPMessageContext context) {
  Boolean outbound = (Boolean) context
  .get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY);
  
  System.out.println(context.keySet());
  
  if(outbound)
  {
   System.out.println("=====================this is outbound log handler===============");
   return true;
  }
  else
  {
   System.out.println("=====================this is inbound log handler===============");
   return false;
  }
 }
}