@Test
public void testAsyncCallWithHandlerAndMultipleClients() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull(service);
final MyHandler h = new MyHandler();
MyHandler.invocationCount = 0;
final String expectedString = new String("Hello, finally!");
class Poller extends Thread {
Future<?> future;
int tid;
Poller(Future<?> f, int t) {
future = f;
tid = t;
}
public void run() {
if (tid % 2 > 0) {
while (!future.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
// ignore
ex.printStackTrace();
}
}
}
try {
future.get();
} catch (Exception ex) {
fail("Poller " + tid + " failed with " + ex);
}
assertEquals("callback was not executed or did not return the expected result",
expectedString, h.getReplyBuffer());
}
}
Greeter greeter = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
long before = System.currentTimeMillis();
long delay = 3000;
Future<?> f = greeter.greetMeLaterAsync(delay, h);