public void testAsyncSynchronousPolling() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull(service);
ExecutorService executor = Executors.newFixedThreadPool(5);
service.setExecutor(executor);
assertNotNull(service);
final String expectedString = new String("How are you Joe");
class Poller extends Thread {
Response<GreetMeSometimeResponse> response;
int tid;
Poller(Response<GreetMeSometimeResponse> r, int t) {
response = r;
tid = t;
}
public void run() {
if (tid % 2 > 0) {
while (!response.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
// ignore
}
}
}
GreetMeSometimeResponse reply = null;
try {
reply = response.get();
} catch (Exception ex) {
fail("Poller " + tid + " failed with " + ex);
}
assertNotNull("Poller " + tid + ": no response received from service", reply);
String s = reply.getResponseType();
assertEquals(expectedString, s);
}
}
Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
Response<GreetMeSometimeResponse> response = greeter.greetMeSometimeAsync("Joe");
Poller[] pollers = new Poller[4];
for (int i = 0; i < pollers.length; i++) {
pollers[i] = new Poller(response, i);