Search in sources :

Example 1 with Response

use of javax.xml.ws.Response in project uavstack by uavorg.

the class CXFClientE2ETest method doGet.

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest request,
 *      javax.servlet.http.HttpServletResponse response)
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String test = request.getParameter("test");
    if (test == null || "good".equals(test)) {
        TestService_Service service = new TestService_Service();
        TestService ts = service.getPort(TestService.class);
        ts.echo();
    } else if ("fault".equals(test)) {
        TestService_Service service = new TestService_Service();
        TestService ts = service.getPort(TestService.class);
        ts.echoFault();
    } else if ("async1".equals(test)) {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(TestService_Service.WSDL_LOCATION);
        try {
            client.invokeWrapped(new ClientCallback() {

                @Override
                public void handleResponse(Map<String, Object> ctx, Object[] res) {
                    super.handleResponse(ctx, res);
                }

                @Override
                public void handleException(Map<String, Object> ctx, Throwable ex) {
                    super.handleException(ctx, ex);
                }
            }, "echo");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if ("async0".equals(test)) {
        Service sr = Service.create(TestService_Service.WSDL_LOCATION, TestService_Service.SERVICE);
        JAXBContext jc = null;
        try {
            jc = JAXBContext.newInstance("com.creditease.monitorframework.fat.client");
        } catch (JAXBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Dispatch d = sr.createDispatch(TestService_Service.TestServicePort, jc, Mode.PAYLOAD);
        d.invokeAsync(null, new AsyncHandler() {

            @Override
            public void handleResponse(Response res) {
                if (res.isDone()) {
                    try {
                        System.out.println(res.get());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
Also used : JaxWsDynamicClientFactory(org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory) ClientCallback(org.apache.cxf.endpoint.ClientCallback) AsyncHandler(javax.xml.ws.AsyncHandler) TestService_Service(com.creditease.monitorframework.fat.client.TestService_Service) TestService(com.creditease.monitorframework.fat.client.TestService) JAXBException(javax.xml.bind.JAXBException) Service(javax.xml.ws.Service) TestService_Service(com.creditease.monitorframework.fat.client.TestService_Service) TestService(com.creditease.monitorframework.fat.client.TestService) Dispatch(javax.xml.ws.Dispatch) JAXBContext(javax.xml.bind.JAXBContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) ExecutionException(java.util.concurrent.ExecutionException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.xml.ws.Response) Client(org.apache.cxf.endpoint.Client) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with Response

use of javax.xml.ws.Response 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();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) URL(java.net.URL) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException) WebServiceException(javax.xml.ws.WebServiceException) 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) 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 3 with Response

use of javax.xml.ws.Response 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 | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }).get();
    assertEquals("Hello " + request, resp.getResponseType());
    g.greetMeLaterAsync(1000, new AsyncHandler<GreetMeLaterResponse>() {

        public void handleResponse(Response<GreetMeLaterResponse> res) {
        }
    }).get();
}
Also used : GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Test(org.junit.Test)

Example 4 with Response

use of javax.xml.ws.Response in project cxf by apache.

the class AsyncHTTPConduitTest method testCallAsyncCallbackInvokedOnlyOnce.

@Test
public void testCallAsyncCallbackInvokedOnlyOnce() throws Exception {
    // This test is especially targeted for RHEL 6.8
    updateAddressPort(g, PORT_INV);
    int repeat = 100;
    final AtomicInteger count = new AtomicInteger(0);
    for (int i = 0; i < repeat; i++) {
        try {
            g.greetMeAsync(request, new AsyncHandler<GreetMeResponse>() {

                public void handleResponse(Response<GreetMeResponse> res) {
                    count.incrementAndGet();
                }
            }).get();
        } catch (Exception e) {
        }
    }
    Thread.sleep(1000);
    assertEquals("Callback should be invoked only once per request", repeat, count.intValue());
}
Also used : GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Endpoint(javax.xml.ws.Endpoint) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with Response

use of javax.xml.ws.Response in project cxf by apache.

the class AsyncHTTPConduitTest method testRetransmitAsync.

@Test
public void testRetransmitAsync() throws Exception {
    updateAddressPort(g, PORT);
    HTTPConduit c = (HTTPConduit) ClientProxy.getClient(g).getConduit();
    HTTPClientPolicy cp = new HTTPClientPolicy();
    cp.setMaxRetransmits(2);
    cp.setChunkLength(20);
    c.setClient(cp);
    GreetMeResponse resp = (GreetMeResponse) g.greetMeAsync(request, new AsyncHandler<GreetMeResponse>() {

        public void handleResponse(Response<GreetMeResponse> res) {
            try {
                res.get().getResponseType();
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }).get();
    assertEquals("Hello " + request, resp.getResponseType());
    g.greetMeLaterAsync(1000, new AsyncHandler<GreetMeLaterResponse>() {

        public void handleResponse(Response<GreetMeLaterResponse> res) {
        }
    }).get();
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Test(org.junit.Test)

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