Java Reference
In-Depth Information
NOTE
If you are executing from the command line, use the -b option to specify the location of the binding
file. You don't have to put all of your customizations in a single file; if you want to separate them for
greater flexibility, just use a new -b option for each file. Likewise, you can specify multiple binding
elements in the Ant task.
Running your build script now modifies your generated code. It generates two separate meth-
ods within the SEI (here, SoaCookbook.java ) in addition to the regular synchronous method
that was generated. Each asynchronous method has a different manner of handling the asyn-
chronous behavior: polling and callbacks. We'll examine these in the following sections.
Using Asynchronous Polling
This section assumes that you have performed the steps earlier in this recipe to generate the
asynchronous SEI. This looks like the code in Example 6-22 .
Example6-22.Generated polling method
@WebMethod(operationName = "doLongJob")
@RequestWrapper(localName = "doLongJob",
targetNamespace = "http://ns.soacookbook.com",
className = "com.soacookbook.ns.DoLongJob")
@ResponseWrapper(localName = "doLongJobResponse",
targetNamespace = "http://ns.soacookbook.com",
className = "com.soacookbook.ns.DoLongJobResponse")
public Response<DoLongJobResponse> doLongJobAsync(
@WebParam(name = "jobName", targetNamespace =
"http://ns.soacookbook.com")
String jobName);
The polling operation signature does not return a DoLongJobResponse , as the regular block-
ing method does. Instead it returns a Response<DoLongJobResponse> . The
javax.xml.ws.Response<T> is a standard JAX-WS class that wraps the regular return type.
It extends Future<T> , and gives you access to the context map for operation responses. For
asynchronous operations it offers an isDone method to check if the operation has finished,
and a cancel operation to allow clients to interrupt the call.
A client using polling will need to manually perform this check. Let's add a method to
your client class that will handle all of the interaction with the SEI. This class, shown in
Example 6-23 , will act as a business delegate within a larger application in order to encapsu-
late the fact that the work is being performed by a web service.
Search WWH ::




Custom Search