Skip to main content

JAX-RPC 2.0 Standard Implementation Early Access

Posted by kohlert on April 7, 2005 at 6:05 PM PDT

The JAX-RPC 2.0 Standard Implementation Early Access has just been released to the JAX-RPC project and you can download it here.

I would like to highlight some of the new features available in this release here.

JAXB data binding

JAXB 2.0 Early Access is also available. JAX-RPC 2.0 uses JAXB for all of its data binding. This means that much more of XML Schema can be handled compared to JAX-RPC 1.1. Although JAXB 2.0 has not completed bindings for all of XML Schema in this release, it will do so by FCS.

You can access the standalone early access of JAXB 2.0 at the JAXB Project on


Annotations from JSR 181 are used to allow customizations in the mapping from Java to WSDL. Many JAX-RPC 1.X users complained that the SI generated meaningless part names like: String_1. Now developers can customize these names using the WebParam annotation. Of course there are many more customizations available that allow the developer to control most of the mapping to WSDL. Here is an example of an annotated endpoint implementation class.

@WebService(targetNamespace="",  name="AddNumbers")
@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
public class AddNumbers {
   @WebMethod(operationName="add", action="urn:addNumbers")
   public int addNumbers(
            @WebParam(name="num0")int number1,
            @WebParam(name="num1")int number2) throws RemoteException, AddNumbersException {
        if (number1 < 0 || number2 < 0) {
            throw new AddNumbersException("Negative number cant be added!",
                "Numbers: " + number1 + ", " + number2);
        return number1 + number2;

JAXB 2.0 also defines a number of annotations that can be used to customize the mapping of Java types to XML Schema.


Customizations allow the developer to customize the mapping from WSDL to Java. For those of you that are familiar with JAXB 1.0 customizations, JAX-RPC customizations will look familiar as they are model after JAXB customizations. In fact, you can embedded JAXB customizations within a JAX-RPC customization giving you the ability to customize both WSDL and XML Schema.

Improved Handler Framework

JAX-RPC 2.0 allows for the use of both logical and protocol handlers. Protocol handlers have access to the entire message, while logical handlers only have access to the payload of the message. So in the case of a SOAP message a protocol handler can access the entire SOAP envelope, while a logical handler will only have access to the contents of the SOAP body.

Handler chains can now be configured on a per-port, per-protocol, or per-service basis.

Dynamic Client

JAX-RPC 2.0 has added a new Dispatch interface. This interface is the follow on to the 1.1 Call interface. This inteface gives the developer much more control over what is sent over the wire in a web service invocation. It allows the client developers to with either java.lang.transform.Source, javax.xml.soap.SOAPMessage or a JAXB data bound object. The developer can also choose to work with the entire message or just the payload of the message.

Dynamic Server

The Provider interface is provided as a counter part to the Dispatch interface. It allows server developers the same choices as the Dispatch developers do when writing a client.

Asynchronous Clients

Asynchronous clients are now supported on both stubs and the new Dispatch interface. Clients can choose between polling or callback techniques. For example, a standard invocation of a addNumbers operation on a stub would look like:

private void invokeSynchronous() throws RemoteException{
   int number1 = 10;
   int number2 = 20;
   System.out.println("\nInvoking synchronous addNumber():");
   int result = port.addNumbers(number1, number2);
   System.out.printf("The result of adding %d and %d is %d\n", number1, number2, result);       

Here is the same operation invoke asynchronously using polling.

private void invokeAsyncPoll() throws InterruptedException, ExecutionException{
   int number1 = 10;
   int number2 = 20;

   System.out.println("\nInvoking Asynchronous Polling addNumbersAsync():");
   javax.xml.rpc.Response resp = port.addNumbersAsync(number1, number2);
   AddNumbersResponse output = resp.get();
   System.out.printf("The result of adding %d and %d is %d\n", number1, number2, output.getReturn());       

And here it is using the the callback mechanism.

private void invokeAsyncCallback() throws InterruptedException{
   int number1 = 10;
   int number2 = 20;

   System.out.println("\nInvoking Asynchronous Callback addNumbersAsync():");
   AddNumbersCallbackHandler callbackHandler = new AddNumbersCallbackHandler();
   Future response = port.addNumbersAsync(number1, number2, callbackHandler);
   AddNumbersResponse output = callbackHandler.getResponse();              
   System.out.printf("The result of adding %d and %d is %d\n", number1, number2, output.getReturn());               

Please send feedback to the JAXB 2.0 and JAX-RPC 2.0 forum

Related Topics >>