O'Reilly logo

Java SOA Cookbook by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making Asynchronous Calls with a JAX-WS Client

Problem

You want to invoke an operation on your service endpoint interface asynchronously.

Solution

Add the <enableAsyncMapping> custom binding on the server side in the WSDL, then use one of the invokeAsync methods available on your SEI.

Asynchronous web service clients can be constructed in one of two ways: with a callback, or with polling. Both methods become available when using a single <enableAsyncMapping> customization.

Note

Before you attempt to call invokeAsync, you need to enable asynchronous mappings on the WSDL using the jaxws:bindings element. Otherwise, your invocations may appear to succeed, but they won’t actually be asynchronous. That is, they’ll block, just like a normal call to invoke.

With the polling method, the client blocks, checking repeatedly for the response. This is not suitable for a GUI application where the main thread must be free to keep the application responsive to user interaction. With the callback method, clients must pass a Handler<T> to the web service operation at invocation, and the handler object will be populated when the response is ready. This allows the application thread to continue with other business in the meantime.

In order to allow a client to invoke an operation asynchronously, you must first specify the binding customization in a file that you point to during client generation with wsimport.

Note

It does not matter what name you give the binding customization file or what extension you use, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required