Search in sources :

Example 16 with Response

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();
}
Also used : AsyncHandler(javax.xml.ws.AsyncHandler) QName(javax.xml.namespace.QName) HelloWorldService(org.apache.cxf.hello_world_jms.HelloWorldService) Closeable(java.io.Closeable) HelloWorldPortType(org.apache.cxf.hello_world_jms.HelloWorldPortType) URL(java.net.URL) Response(javax.xml.ws.Response) ExecutionException(java.util.concurrent.ExecutionException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with Response

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());
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) ArrayList(java.util.ArrayList) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) URL(java.net.URL) Endpoint(javax.xml.ws.Endpoint) BareDocumentResponse(org.apache.hello_world_soap_http.types.BareDocumentResponse) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) Response(javax.xml.ws.Response) Executor(java.util.concurrent.Executor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Greeter(org.apache.hello_world_soap_http.Greeter) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 18 with Response

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());
}
Also used : AsyncHandler(javax.xml.ws.AsyncHandler) AddNumbersResponse(org.apache.cxf.systest.ws.addr_feature.AddNumbersResponse) MAPCodec(org.apache.cxf.ws.addressing.soap.MAPCodec) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) AddNumbersPortType(org.apache.cxf.systest.ws.addr_feature.AddNumbersPortType) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AddNumbersResponse(org.apache.cxf.systest.ws.addr_feature.AddNumbersResponse) Response(javax.xml.ws.Response) Test(org.junit.Test)

Example 19 with Response

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);
}
Also used : Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 20 with Response

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);
}
Also used : Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Aggregations

Response (javax.xml.ws.Response)20 Test (org.junit.Test)17 AsyncHandler (javax.xml.ws.AsyncHandler)16 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)11 GreetMeResponse (org.apache.hello_world_soap_http.types.GreetMeResponse)11 ExecutionException (java.util.concurrent.ExecutionException)10 Endpoint (javax.xml.ws.Endpoint)6 IOException (java.io.IOException)4 URL (java.net.URL)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 SOAPService (org.apache.hello_world_soap_http.SOAPService)4 QName (javax.xml.namespace.QName)3 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)3 Greeter (org.apache.hello_world_soap_http.Greeter)3 StringReader (java.io.StringReader)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 MalformedURLException (java.net.MalformedURLException)2 JAXBElement (javax.xml.bind.JAXBElement)2 Source (javax.xml.transform.Source)2 StreamSource (javax.xml.transform.stream.StreamSource)2