JOBS4TIMES jobs4timesLogo

JAX-WS 2.0

Agenda :
  1. JAX-WS 2.0
  2. Diff between JAX-RPC1.x vs JAX-WS2.0
  3. Dynamic Proxy
  4. Wsimport
  5. JAX-WS Annotations
  6. WS-Metadata
  7. Guide to JAX-WS

Introduction :

  • JAX-WS stands for Java Api for XML-based Web Services.
  • The JAX-RPC 2.0 Specification will extend JAX-RPC1.1 in a number of different ways.
The JAX-RPC2.0 renamed as JAX-WS2.0 , this way done for number of reasons:
  1. The industry was not merely doing RPC Web Services, they were also doing message-oriented web services, So RPC was removed from the name and replaced with WS.
  2. The JAX-RPC name is misleading , developers assume that all JAX-RPC is about just RPC, not web services. By renaming JAX-RPC to JAX-WS we can eliminate this confusion.
  3. JAX-RPC2.0 uses JAXB for all databinding. Migrating from JAX-RPC1.x to JAX-RPC2.0 is very difficult. Hence these are two separate technologies.
  4. Using JAX-RPC1.0/1.1 APIs are not developer friendly i.e., using javax.xml.rpc.Service, javax.xml.rpc.Call interfaces are not convenient for developer. JAX-WS introduces new set of APIs (including annotations) which are easier to understand and use.

The successor to JAX-RPC1.1 is JAX-WS2.0 - The Java Api for XML-based Web Services.

ScenarioJAX-RPC1.0/1.1JAX-RPC2.0/JAX-WS2.0
Serialization / DeSerialization (Or) Marshalling / Unmarshalling (Or) Data Mapping model Defines its own type mapping for serialization and deserialization of XML types to and from Java types, Which covers 90% of the all XML types.
Those that it does not cover are mapped to javax.xml.soap. SOAPElement. This version does not require the use of JAXB.
JAX-RPC2.0 strongly aligned with JAXB2.0 , effectively delegating to the JAXB2.0 for all data binding related tasks.
Message Format SOAP over HTTP (soap binding) SOAP over HTTP (soap binding) & XML over HTTP (http binding).
J2EE & JDK version J2EE 1.4 & JDK 1.4 Java EE 5 & JDK 1.5
SOAP version SOAP 1.1 SOAP 1.1 & SOAP 1.2
WSDL version WSDL 1.1 WSDL 1.1 & WSDL 2.0
Basic profile 1.0 1.1
Annotation Support No Yes
Message Style RPC - style both RPC & Document style
Encoding Style Literal and soap encoding Only literal encoding.
Note : soap encoding causes interoperability issues according to WS-I basic profile.
MTOM (Message Transmission Optimization Mechanism ) No No
Handler Rely on SAAJ 1.2 Rely on SAAJ 1.3
  1. The JAX-RPC defined its own Java/XML binding, but the JAX-WS 2.0 (The successor to JAX-RPC) no longer defines a Java/XML binding, rather the JAX-WS delegates type mapping to JAXB.
  2. The delegation of Java/XML binding to JAXB 2.0 greatly improves the usability of JAX-WS as compared with JAX-RPC.
  3. The JAX-WS supports two most popular WS-I complaint WSDL styles: rpc/literal, document/literal.
  4. The JAX-WS supports both SOAP over HTTP (soap binding) and XML over HTTP (http binding).
  5. SOAP over HTTp(SOAP binding) means send and receive SOAP Messages over HTTP transport.
  6. XML over HTTp(http binding) means send and receive XML Messages over HTTP transport without using SOAP.
  7. The support of XML over HTTP(http binding) enables the deployment and consumption of Web services defined using RESTful services.

Dynamic Proxy :

The JAX-WS automatically creates proxy object at runtime which is an instance of SEI. Hence we do not need to generate stub classes.

The following diagram show the process of creating SEI interface and its proxy instance

The following steps detailing the process of creating and using SEI and its Proxy object :
  1. The wsimport tool is used to generate SEI for corresponding element.
  2. The proxy object(subclass of SEI) is automatically created at runtime when getPort() method on service interface (javax.xml.ws.Service) is invoked.
  3. The JAXB generated classes becomes parameters and return values of SEI methods.
  4. The proxy object marshalls method parameters as SOAP request.
  5. The proxy object receives SOAP response and unmarshal it into return values.

wsimport :

The wsimport tool does following :
  1. Generates Endpoint interface (SEI) which maps with element.
  2. Generates JAXB classes which maps with element.
Syntax :
C:\> wsimport -s. -d.RequestOrder.wsdl
  • The source files are generated to the directory to the specified by -s option.
  • The compiled classes are generated to the directory specified by -d option.
  • The JAXB annotations are added to generated JAXB java classes. Similarly, the JAX-WS annotations are added to generated SEI.
Conclusion : The JAX-WS provides standard mapping between wsdl and java types.

Annotations :

  • JAXB binding framework uses JAXB annotations to determine how to marshal/unmarshal a JAXB java object to/form XML message.
  • JAX-WS runtime uses JAX-WS annotations on SEI to determine how to marshal a method invocation to a SOAP request message and unmarshal a SOAP response into a method's return value.
The annotated Service Endpoint Interface (SEI) is given below :

The below table describes JAX-WS annotations :
Annotation Description Example
@WebService Indicates SEI mapped with
@WebMethod Indicates method mapped with
@WebResult Indicates method return type mapped with
@RequestWrapper Indicates the request wrapper bean -a JAXB generated class that maps to the request messages's top level element name. This annotation is not applicable for rpc/literal.
@ResponseWrapper Indicates the response wrapper bean -a JAXB generated class that maps to the response messages's top level element name. This annotation is not applicable for rpc/literal.
@WebParam Indicates SEI method's parameter maps with element.

JAX-WS 2.0 Server Side Development :

JAX-WS provides server side capabilities to write web services including start from WSDL, Integrate with existing classes, and XML processing without any Java/XML binding.

Start from WSDL using SEI :
  • This section explains how to create, deploy, and invoke JAX-WS endpoint using an existing WSDL and SEI.
  • When starting from an existing WSDL document in JAX-WS, the most straight forward way to implement a web service that confirms to the WSDL contract is to use a service Endpoint interface (SEI).
The @WebService annotation defines a Web Service :

Installation :

Step 1 :
Download Java EE 5 or above from http://java.sun.com/javaee such as java_ee_sdk-5_08-windows-jdk.exe
By default, above installation comes with GlassFish application server.

Step 1 :

BACK