JAX-WS based Webservice and Client Design Options.JAX-WS stands for Java Api for XML Web services. JAX-WS supports both SOAP 1.1 and SOAP 1.2.
The following section tries to snapshot the different ways we can use JAX-WS to write both Web Services and Clients.
What is Web service Endpoint?A web service endpoint is an server side resource that can be referenced by client and to which web services messages can be addressed.Generally, web services will have endpoint and a WSDL file to share its descriptions with clients.Clients use the web service endpoint description to generate/write code that can send SOAP messages to and receive SOAP messages from the web service endpoint.
In JAX-WS the endpoints are annotated with the javax.jws.WebService annotation or javax.jws.WebServiceProvider annotation, but not both at a time.
Services designe options .
JAX-WS broadly supports two Webservice models,
- Annotated with the javax.jws.WebService, where the implemented class works on abstraction, where it deals with objects (SEI) and not underlying XML messages directly.
Here the methods to be exposed as web service are annotated with @WebMethod annotation. And JAXB objects are used to handle request and response processing. JAXB is responsible for marshaling and
unmarshalling the objects to XML
- Annotated with javax.jws.WebServiceProvider, and implements Provider interface. Where the service will work at XML message level.Compared to SEI, Provider is a low level Api. Here understanding the payload structure, or SOAP message structure is important.
The @ServiceMode annotation is used to configure the messaging mode of a Provider instance.
Provider<Source> or Provider<SOAPMessage> or Provider<DataSource>
Like wheather the web service endpoint will be working on the whole payload or just the message part.
@ServiceMode(value=MESSAGE) indicates that the provider instance wishes to receive and send entire
protocol messages absence of the annotation or use of
@ServiceMode(value=PAYLOAD) indicates that the provider instance wishes to receive and send
message payloads only
Client Programming Model's in JAX-WS
JAX-WS broadly supports two Client models,
Dispatch Client API
Dispatch client api works directly with XML message level and we dont need to use generated Java artifacts from the wsdl.
The Dispatch client API requires clients to construct messages or payloads as XML.
This requires a detailed knowledge of the message or message payload structure. It could be useful when we need to customize the request message.
Sometimes, generated artifcats after marshalling generates the XML which always does not work always.
This model also usefull when we need to do a lot of xml level processing like digital signing the message and modifying some of the attibutes of the xml.
Dispatch client works with following type of Objects,
- JAXB objects
Use SOAPMessage objects so that clients can work with SOAP messages.SOAPMessage objects works with only SOAP bindings.
Use JAXB objects so that clients can use JAXB objects that are generated from an XML schema.
Dynamic Proxy Client API
Dynamic Proxy client's works with generated artifacts from wsdl, i,e. SEI(Service endpoint Interfaces).
For Dynamic proxy we can use wsimport tool to generate the SEI classes, and use them to build the client.
Main steps for using Dynamic Proxy are as follows,
- Create instance for SEI class ( Annotated with @WebServiceClient)
- Get the webservice endpoint object or the Object representing port ( Annotated with @WebEndpoint)
- Invoke port object's operation/method (Annotated with @WebMethod)