Java Reference
In-Depth Information
Example6-23.Using polling to invoke operation asynchronously
package com.soacookbook.ch03;
import java.util.*;
import javax.xml.bind.*;
import javax.xml.soap.*;
import org.apache.log4j.Logger;
import com.soacookbook.ns.*;
import javax.xml.ws.Response;
public class AsynchClient {
private static final Logger LOGGER =
Logger.getLogger(AsynchClient.class);
public String doLongJobPolling(String jobName) throws Exception {
LOGGER.debug("Executing.");
SoaCookbookService svc = new SoaCookbookService();
SoaCookbook port = svc.getSoaCookbookPort();
Response<DoLongJobResponse> response =
port.doLongJobAsync(jobName);
LOGGER.debug("Invoked service.");
while(!response.isDone()){
LOGGER.debug("Waiting...");
Thread.sleep(1000); //do something
}
DoLongJobResponse res = response.get();
String status = res.getJobDone();
LOGGER.debug("Status: " + status);
return status;
}
}
Once the isDone method returns true, the response object is available.
Running this client from a unit test using a fabricated job name of “My Batch” has this output:
Executing.
Invoked service.
Waiting...
Waiting...
Search WWH ::




Custom Search