Java Reference
In-Depth Information
Waiting...
Waiting...
Status: Job is done running: My Batch
Using Asynchronous Callbacks
This section assumes that you have performed the steps earlier in this recipe to generate the
asynchronous SEI.
The second generated method uses a callback defined by the client that will receive the re-
sponse from the service operation when it is complete. The method signature is as follows:
@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 Future<?> doLongJobAsync(
@WebParam(name="jobName",
targetNamespace="http://ns.soacookbook.com")
String jobName,
@WebParam(name = "asyncHandler", targetNamespace = "")
AsyncHandler<DoLongJobResponse> asyncHandler);
Notice that there are two changes to the regular method signature. The method does not
return a
DoLongJobResponse
, which the WSDL defines, nor does it return a
Respon-
se<DoLongJobResponse>
as with the asynchronous polling method. Rather, it returns a
Fu-
ture<?>
. The second change is that, unlike the polling method, which does not modify the
argument list from the original method, this adds a parameter, which is an
AsyncHandler
,
parameterized on
DoLongJobResponse
. But where does this
AsyncHandler
implementation
come from? You have to write it, and pass an instance of it to the service invocation. The in-
terface contains only one method, called
handleResponse
, which accepts a
Response<T>
.