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