Search in sources :

Example 6 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 7 with Response

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

the class WSDiscoveryClient method resolve.

public ResolveMatchType resolve(W3CEndpointReference ref, int timeout) {
    Dispatch<Object> disp = this.getDispatchInternal(false, version.getResolveAction());
    ResolveType rt = new ResolveType();
    rt.setEndpointReference(ref);
    if (adHoc) {
        disp.getRequestContext().put("udp.multi.response.timeout", timeout);
        final Holder<ResolveMatchesType> response = new Holder<ResolveMatchesType>();
        AsyncHandler<Object> handler = new AsyncHandler<Object>() {

            public void handleResponse(Response<Object> res) {
                try {
                    Object o = res.get();
                    while (o instanceof JAXBElement) {
                        o = ((JAXBElement) o).getValue();
                    }
                    if (o instanceof ResolveMatchesType) {
                        response.value = (ResolveMatchesType) o;
                    } else if (o instanceof HelloType) {
                        HelloType h = (HelloType) o;
                        QName sn = version.getServiceName();
                        if (h.getTypes().contains(sn) || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
                            // A DiscoveryProxy wants us to flip to managed mode
                            uncache();
                            resetDispatch(h.getXAddrs().get(0));
                        }
                    }
                } catch (InterruptedException e) {
                // ?
                } catch (ExecutionException e) {
                // ?
                }
            }
        };
        disp.invokeAsync(new ObjectFactory().createResolve(rt), handler);
        return response.value == null ? null : response.value.getResolveMatch();
    }
    Object o = disp.invoke(new ObjectFactory().createResolve(rt));
    while (o instanceof JAXBElement) {
        o = ((JAXBElement) o).getValue();
    }
    return o == null ? null : ((ResolveMatchesType) o).getResolveMatch();
}
Also used : AsyncHandler(javax.xml.ws.AsyncHandler) ResolveMatchesType(org.apache.cxf.ws.discovery.wsdl.ResolveMatchesType) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ResolveType(org.apache.cxf.ws.discovery.wsdl.ResolveType) HelloType(org.apache.cxf.ws.discovery.wsdl.HelloType) JAXBElement(javax.xml.bind.JAXBElement) Response(javax.xml.ws.Response) ObjectFactory(org.apache.cxf.ws.discovery.wsdl.ObjectFactory) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 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<Response<GreetMeResponse>>();
    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 9 with Response

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

the class DispatchClientServerTest method testSOAPMessageInvokeToOneWay.

@Test
public void testSOAPMessageInvokeToOneWay() throws Exception {
    SOAPService service = new SOAPService(null, SERVICE_NAME);
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
    // message is "one way", but there really isn't a way for us to know that
    // as we don't have a wsdl or other source of operation information to
    // compare the payload to.
    InputStream is1 = getClass().getResourceAsStream("resources/GreetMe1WDocLiteralReq2.xml");
    SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
    assertNotNull(soapReqMsg1);
    // Version 1:
    // we'll just call invoke
    disp.invoke(soapReqMsg1);
    // Version 2:
    // We want to handle things asynchronously
    AsyncHandler<SOAPMessage> callback = new AsyncHandler<SOAPMessage>() {

        public void handleResponse(Response<SOAPMessage> res) {
            synchronized (this) {
                notifyAll();
            }
        }
    };
    synchronized (callback) {
        disp.invokeAsync(soapReqMsg1, callback);
        callback.wait();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.junit.Test)

Example 10 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 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();
}
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) ExecutionException(java.util.concurrent.ExecutionException) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Test(org.junit.Test)

Aggregations

Response (javax.xml.ws.Response)12 Test (org.junit.Test)10 ExecutionException (java.util.concurrent.ExecutionException)9 AsyncHandler (javax.xml.ws.AsyncHandler)8 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6 GreetMeResponse (org.apache.hello_world_soap_http.types.GreetMeResponse)6 URL (java.net.URL)4 Endpoint (javax.xml.ws.Endpoint)4 SOAPService (org.apache.hello_world_soap_http.SOAPService)4 QName (javax.xml.namespace.QName)3 Greeter (org.apache.hello_world_soap_http.Greeter)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 JAXBElement (javax.xml.bind.JAXBElement)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2 HelloType (org.apache.cxf.ws.discovery.wsdl.HelloType)2 ObjectFactory (org.apache.cxf.ws.discovery.wsdl.ObjectFactory)2 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)2 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)2 BareDocumentResponse (org.apache.hello_world_soap_http.types.BareDocumentResponse)2