use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.
the class ClientServerTest method testAsyncSynchronousPolling.
@Test
public void testAsyncSynchronousPolling() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull(service);
final String expectedString = new String("Hello, finally!");
class Poller extends Thread {
Response<GreetMeLaterResponse> response;
int tid;
Poller(Response<GreetMeLaterResponse> 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
}
}
}
GreetMeLaterResponse 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 = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
long before = System.currentTimeMillis();
long delay = 3000;
Response<GreetMeLaterResponse> response = greeter.greetMeLaterAsync(delay);
long after = System.currentTimeMillis();
assertTrue("Duration of calls exceeded " + delay + " ms", after - before < delay);
// first time round, responses should not be available yet
assertFalse("Response already available.", response.isDone());
Poller[] pollers = new Poller[4];
for (int i = 0; i < pollers.length; i++) {
pollers[i] = new Poller(response, i);
}
for (Poller p : pollers) {
p.start();
}
for (Poller p : pollers) {
p.join();
}
}
use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.
the class ClientServerTest method testAsyncDiscardProxy.
@Test
public void testAsyncDiscardProxy() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull(service);
Greeter greeter = service.getPort(portName, Greeter.class);
assertNotNull(service);
updateAddressPort(greeter, PORT);
Response<GreetMeLaterResponse> r1 = greeter.greetMeLaterAsync(3000);
greeter = null;
service = null;
System.gc();
System.gc();
System.gc();
assertEquals("Hello, finally!", r1.get().getResponseType());
}
use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.
the class AsyncHTTPConduitTest method testCallAsync.
@Test
public void testCallAsync() throws Exception {
updateAddressPort(g, PORT);
GreetMeResponse resp = (GreetMeResponse) g.greetMeAsync(request, new AsyncHandler<GreetMeResponse>() {
public void handleResponse(Response<GreetMeResponse> res) {
try {
res.get().getResponseType();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}).get();
assertEquals("Hello " + request, resp.getResponseType());
g.greetMeLaterAsync(1000, new AsyncHandler<GreetMeLaterResponse>() {
public void handleResponse(Response<GreetMeLaterResponse> res) {
}
}).get();
}
Aggregations