use of javax.xml.ws.Response in project cxf by apache.
the class JMSClientServerTest method testAsyncCall.
@Ignore
@Test
public void testAsyncCall() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
HelloWorldService service = new HelloWorldService(wsdl, serviceName);
HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
final Thread thread = Thread.currentThread();
class TestAsyncHandler implements AsyncHandler<String> {
String expected;
TestAsyncHandler(String x) {
expected = x;
}
public String getExpected() {
return expected;
}
public void handleResponse(Response<String> response) {
try {
Thread thread2 = Thread.currentThread();
assertNotSame(thread, thread2);
assertEquals("Hello " + expected, response.get());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
TestAsyncHandler h1 = new TestAsyncHandler("Homer");
TestAsyncHandler h2 = new TestAsyncHandler("Maggie");
TestAsyncHandler h3 = new TestAsyncHandler("Bart");
TestAsyncHandler h4 = new TestAsyncHandler("Lisa");
TestAsyncHandler h5 = new TestAsyncHandler("Marge");
Future<?> f1 = greeter.greetMeAsync("Santa's Little Helper", new TestAsyncHandler("Santa's Little Helper"));
f1.get();
f1 = greeter.greetMeAsync("PauseForTwoSecs Santa's Little Helper", new TestAsyncHandler("Santa's Little Helper"));
long start = System.currentTimeMillis();
f1 = greeter.greetMeAsync("PauseForTwoSecs " + h1.getExpected(), h1);
Future<?> f2 = greeter.greetMeAsync("PauseForTwoSecs " + h2.getExpected(), h2);
Future<?> f3 = greeter.greetMeAsync("PauseForTwoSecs " + h3.getExpected(), h3);
Future<?> f4 = greeter.greetMeAsync("PauseForTwoSecs " + h4.getExpected(), h4);
Future<?> f5 = greeter.greetMeAsync("PauseForTwoSecs " + h5.getExpected(), h5);
long mid = System.currentTimeMillis();
assertEquals("Hello " + h1.getExpected(), f1.get());
assertEquals("Hello " + h2.getExpected(), f2.get());
assertEquals("Hello " + h3.getExpected(), f3.get());
assertEquals("Hello " + h4.getExpected(), f4.get());
assertEquals("Hello " + h5.getExpected(), f5.get());
long end = System.currentTimeMillis();
assertTrue("Time too long: " + (mid - start), (mid - start) < 1000);
assertTrue((end - mid) > 1000);
f1 = null;
f2 = null;
f3 = null;
f4 = null;
f5 = null;
((java.io.Closeable) greeter).close();
greeter = null;
service = null;
System.gc();
}
use of javax.xml.ws.Response in project cxf by apache.
the class ClientServerTest method testAsyncCallUseProperAssignedExecutor.
@Test
public void testAsyncCallUseProperAssignedExecutor() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
class TestExecutor implements Executor {
private AtomicInteger count = new AtomicInteger();
public void execute(Runnable command) {
int c = count.incrementAndGet();
LOG.info("asyn call time " + c);
command.run();
}
public int getCount() {
return count.get();
}
}
Executor executor = new TestExecutor();
service.setExecutor(executor);
assertNotNull(service);
assertSame(executor, service.getExecutor());
assertEquals(((TestExecutor) executor).getCount(), 0);
Greeter greeter = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
List<Response<GreetMeResponse>> responses = new ArrayList<>();
for (int i = 0; i < 5; i++) {
responses.add(greeter.greetMeAsync("asyn call" + i));
}
// wait for all the responses
for (Response<GreetMeResponse> resp : responses) {
resp.get();
}
assertEquals(5, ((TestExecutor) executor).getCount());
}
use of javax.xml.ws.Response in project cxf by apache.
the class WSAPureWsdlTest method testBasicInvocationTimeouts.
@Test
public void testBasicInvocationTimeouts() throws Exception {
AddNumbersPortType port = getPort();
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/jaxws/add");
HTTPConduit conduit = (HTTPConduit) ((Client) port).getConduit();
conduit.getClient().setConnectionTimeout(25);
conduit.getClient().setReceiveTimeout(10);
try {
// read timeout
port.addNumbersAsync(5092, 25).get();
fail("should have failed");
} catch (Exception t) {
// expected
assertTrue(t.getCause().toString(), t.getCause() instanceof java.net.SocketTimeoutException);
}
AsyncHandler<AddNumbersResponse> handler = new AsyncHandler<AddNumbersResponse>() {
public void handleResponse(Response<AddNumbersResponse> res) {
// System.out.println("in handle response");
synchronized (this) {
notifyAll();
}
}
};
synchronized (handler) {
port.addNumbersAsync(5092, 25, handler);
handler.wait(1000);
}
try {
// connection timeout
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT2 + "/jaxws/add");
port.addNumbersAsync(25, 25).get();
fail("should have failed");
} catch (Exception t) {
// expected
assertTrue(t.getCause().getCause().toString(), t.getCause().getCause() instanceof java.net.ConnectException || t.getCause().getCause() instanceof java.net.SocketTimeoutException);
}
synchronized (handler) {
port.addNumbersAsync(25, 25, handler);
handler.wait(1000);
}
MAPCodec mp = getMAPCodec((Client) port);
assertEquals(0, mp.getUncorrelatedExchanges().size());
}
use of javax.xml.ws.Response in project jbossws-cxf by jbossws.
the class JBWS3293DispatchTestCase method testInvokeAsynchHandler.
@Test
@RunAsClient
public void testInvokeAsynchHandler() throws Exception {
AsyncHandler<Source> handler = new AsyncHandler<Source>() {
@Override
public void handleResponse(Response<Source> response) {
try {
verifyResponse(response.get());
asyncHandlerCalled = true;
} catch (Exception ex) {
handlerException = ex;
}
}
};
StreamSource reqObj = new StreamSource(new StringReader(reqPayload));
Dispatch<Source> dispatch = createDispatch();
Future<?> future = dispatch.invokeAsync(reqObj, handler);
future.get(3000, TimeUnit.MILLISECONDS);
if (handlerException != null)
throw handlerException;
assertTrue("Async handler called", asyncHandlerCalled);
}
use of javax.xml.ws.Response in project jbossws-cxf by jbossws.
the class AsynchronousTestCase method testInvokeAsyncDispatchHandler.
@Test
@RunAsClient
public void testInvokeAsyncDispatchHandler() throws Exception {
AsyncHandler<Source> handler = new AsyncHandler<Source>() {
@Override
public void handleResponse(Response<Source> response) {
try {
verifyResponse(response.get());
asyncHandlerDispatchCalled = true;
} catch (Exception ex) {
handlerDispatchException = ex;
}
}
};
StreamSource reqObj = new StreamSource(new StringReader(reqPayload));
Future<?> future = createDispatch().invokeAsync(reqObj, handler);
future.get(1000, TimeUnit.MILLISECONDS);
if (handlerDispatchException != null)
throw handlerDispatchException;
assertTrue("Async handler called", asyncHandlerDispatchCalled);
}
Aggregations