Java Code Examples for javax.xml.ws.Response#get()

The following examples show how to use javax.xml.ws.Response#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientServerWebSocketTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleResponse(Response<GreetMeLaterResponse> response) {
    invocationCount++;
    try {
        GreetMeLaterResponse reply = response.get();
        replyBuffer = reply.getResponseType();
    } catch (InterruptedException | ExecutionException ex) {
        ex.printStackTrace();
    }
}
 
Example 2
Source File: SSLNettyClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void handleResponse(Response<GreetMeLaterResponse> res) {
    try {
        response = res.get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: TestAsyncHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleResponse(Response<GreetMeSometimeResponse> response) {
    try {
        System.err.println("handleResponse called");
        reply = response.get();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example 4
Source File: NettyHttpConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoTimeoutAsync() throws Exception {
    updateAddressPort(g, PORT);
    HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit();
    c.getClient().setReceiveTimeout(2000);
    c.getClient().setAsyncExecuteTimeout(2000);

    Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-100L);
    future.get();
    
    Response<GreetMeLaterResponse> future2 = g.greetMeLaterAsync(-100L);
    future2.get();
    
    Thread.sleep(3000);
}
 
Example 5
Source File: DispatchClientServerWithHugeResponseTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testStackOverflowErrorForSOAPMessageWithHugeResponse() throws Exception {
    HugeResponseInterceptor hugeResponseInterceptor =
        new HugeResponseInterceptor(ResponseInterceptorType.overflow);
    getBus().getInInterceptors().add(hugeResponseInterceptor);
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<SOAPMessage> disp = service
        .createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");


    InputStream is3 = getClass().getResourceAsStream("GreetMeDocLiteralReq3.xml");
    SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
    assertNotNull(soapReqMsg3);
    Response<SOAPMessage> response = disp.invokeAsync(soapReqMsg3);
    try {
        response.get(300, TimeUnit.SECONDS);
        fail("should catch exception");
    } catch (TimeoutException te) {
        fail("We should not have encountered a timeout, "
            + "should get some exception tell me stackoverflow");
    } catch (Throwable e) {
        assertTrue(e.getCause() instanceof StackOverflowError);
    } finally {
        getBus().getInInterceptors().remove(hugeResponseInterceptor);
    }

}
 
Example 6
Source File: AsyncHTTPConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeoutAsyncWithPropertySetting() throws Exception {
    updateAddressPort(g, PORT);
    ((javax.xml.ws.BindingProvider)g).getRequestContext().put("javax.xml.ws.client.receiveTimeout",
        "3000");
    try {
        Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-5000L);
        future.get();
        fail();
    } catch (Exception ex) {
        //expected!!!
    }
}
 
Example 7
Source File: DispatchClientServerWithMalformedResponseTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleResponse(Response<SOAPMessage> response) {
    try {
        asyncHandlerInvokedCount++;
        SOAPMessage reply = response.get();
        replyBuffer = reply.getSOAPBody().getTextContent();
    } catch (Exception e) {
        //
    }
}
 
Example 8
Source File: NettyClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void handleResponse(Response<GreetMeLaterResponse> res) {
    try {
        response = res.get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: NettyHttpConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeoutAsyncWithPropertySetting() throws Exception {
    updateAddressPort(g, PORT);
    ((javax.xml.ws.BindingProvider)g).getRequestContext().put("javax.xml.ws.client.receiveTimeout",
        "3000");
    try {
        Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-5000L);
        future.get();
        fail();
    } catch (Exception ex) {
        //expected!!!
    }
}
 
Example 10
Source File: NettyHttpConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeoutAsync() throws Exception {
    updateAddressPort(g, PORT);
    HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit();
    c.getClient().setReceiveTimeout(3000);
    c.getClient().setAsyncExecuteTimeout(3000);
    try {
        Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-5000L);
        future.get();
        fail();
    } catch (Exception ex) {
        //expected!!!
    }
}
 
Example 11
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleResponse(Response<SOAPMessage> response) {
    try {
        SOAPMessage reply = response.get();
        replyBuffer = DOMUtils.getContent(SAAJUtils.getBody(reply).getFirstChild().getFirstChild());
    } catch (Exception e) {
        //e.printStackTrace();
    }
}
 
Example 12
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleResponse(Response<DOMSource> response) {
    try {
        DOMSource reply = response.get();
        replyBuffer = DOMUtils.getChild(reply.getNode(), Node.ELEMENT_NODE).getTextContent();
    } catch (Exception e) {
        //e.printStackTrace();
    }
}
 
Example 13
Source File: DispatchClientServerWithHugeResponseTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testThresholdfForSOAPMessageWithHugeResponse() throws Exception {
    HugeResponseInterceptor hugeResponseInterceptor =
        new HugeResponseInterceptor(ResponseInterceptorType.ElementLevelThreshold);
    getBus().getInInterceptors().add(hugeResponseInterceptor);
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<SOAPMessage> disp = service
        .createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");


    InputStream is3 = getClass().getResourceAsStream("GreetMeDocLiteralReq3.xml");
    SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
    assertNotNull(soapReqMsg3);
    Response<SOAPMessage> response = disp.invokeAsync(soapReqMsg3);
    try {
        response.get(300, TimeUnit.SECONDS);
        fail("should catch exception");
    } catch (TimeoutException te) {
        fail("We should not have encountered a timeout, "
            + "should get some exception tell me stackoverflow");
    } catch (Throwable e) {
        if (e.getCause() == null) {
            throw e;
        }
        Throwable t = e.getCause();
        if (t instanceof SOAPFaultException) {
            SoapFault sf = (SoapFault)t.getCause();
            if (sf.getCause() == null) {
                throw e;
            }
            t = sf.getCause();
        }
        if (t.getMessage() == null) {
            throw e;
        }

        String msg = t.getMessage();
        assertTrue(msg, msg.startsWith("reach the innerElementLevelThreshold")
                   || msg.contains("Maximum Element Depth limit"));
    } finally {
        getBus().getInInterceptors().remove(hugeResponseInterceptor);
    }

}
 
Example 14
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStreamSourcePAYLOAD() throws Exception {

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);
    Dispatch<StreamSource> disp = service.createDispatch(PORT_NAME, StreamSource.class,
                                                         Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");

    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
    StreamSource streamSourceReq = new StreamSource(is);
    assertNotNull(streamSourceReq);
    StreamSource streamSourceResp = disp.invoke(streamSourceReq);
    assertNotNull(streamSourceResp);
    String expected = "Hello TestSOAPInputMessage";
    assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp).contains(expected));

    InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq1.xml");
    StreamSource streamSourceReq1 = new StreamSource(is1);
    assertNotNull(streamSourceReq1);
    disp.invokeOneWay(streamSourceReq1);

    // Test async polling
    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq2.xml");
    StreamSource streamSourceReq2 = new StreamSource(is2);
    assertNotNull(streamSourceReq2);
    Response<StreamSource> response = disp.invokeAsync(streamSourceReq2);
    StreamSource streamSourceResp2 = response.get();
    assertNotNull(streamSourceResp2);
    String expected2 = "Hello TestSOAPInputMessage2";
    assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp2).contains(expected2));

    // Test async callback
    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq3.xml");
    StreamSource streamSourceReq3 = new StreamSource(is3);
    assertNotNull(streamSourceReq3);

    TestStreamSourceHandler tssh = new TestStreamSourceHandler();
    Future<?> fd = disp.invokeAsync(streamSourceReq3, tssh);
    assertNotNull(fd);
    waitForFuture(fd);

    String expected3 = "Hello TestSOAPInputMessage3";
    StreamSource streamSourceResp3 = tssh.getStreamSource();
    assertNotNull(streamSourceResp3);
    assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp3).contains(expected3));
}
 
Example 15
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStreamSourceMESSAGE() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);
    Dispatch<StreamSource> disp = service.createDispatch(PORT_NAME, StreamSource.class,
                                                         Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");

    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    StreamSource streamSourceReq = new StreamSource(is);
    assertNotNull(streamSourceReq);
    StreamSource streamSourceResp = disp.invoke(streamSourceReq);
    assertNotNull(streamSourceResp);
    String expected = "Hello TestSOAPInputMessage";
    assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp).contains(expected));

    InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq1.xml");
    StreamSource streamSourceReq1 = new StreamSource(is1);
    assertNotNull(streamSourceReq1);
    disp.invokeOneWay(streamSourceReq1);

    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq2.xml");
    StreamSource streamSourceReq2 = new StreamSource(is2);
    assertNotNull(streamSourceReq2);
    Response<StreamSource> response = disp.invokeAsync(streamSourceReq2);
    StreamSource streamSourceResp2 = response.get();
    assertNotNull(streamSourceResp2);
    String expected2 = "Hello TestSOAPInputMessage2";
    assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp2).contains(expected2));

    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
    StreamSource streamSourceReq3 = new StreamSource(is3);
    assertNotNull(streamSourceReq3);
    TestStreamSourceHandler tssh = new TestStreamSourceHandler();
    Future<?> fd = disp.invokeAsync(streamSourceReq3, tssh);
    assertNotNull(fd);
    waitForFuture(fd);

    String expected3 = "Hello TestSOAPInputMessage3";
    StreamSource streamSourceResp3 = tssh.getStreamSource();
    assertNotNull(streamSourceResp3);
    assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp3).contains(expected3));
}
 
Example 16
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testSAXSourcePAYLOAD() throws Exception {

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<SAXSource> disp = service.createDispatch(PORT_NAME, SAXSource.class, Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");

    // Test request-response
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
    InputSource inputSource = new InputSource(is);
    inputSource.setPublicId(getClass()
                                .getResource("resources/GreetMeDocLiteralSOAPBodyReq.xml").toString());
    inputSource.setSystemId(inputSource.getPublicId());
    SAXSource saxSourceReq = new SAXSource(inputSource);
    assertNotNull(saxSourceReq);
    SAXSource saxSourceResp = disp.invoke(saxSourceReq);
    assertNotNull(saxSourceResp);
    String expected = "Hello TestSOAPInputMessage";
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp).contains(expected));

    // Test oneway
    InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq1.xml");
    InputSource inputSource1 = new InputSource(is1);
    inputSource1.setPublicId(getClass()
                             .getResource("resources/GreetMeDocLiteralSOAPBodyReq1.xml").toString());
    inputSource1.setSystemId(inputSource1.getPublicId());
    SAXSource saxSourceReq1 = new SAXSource(inputSource1);
    assertNotNull(saxSourceReq1);
    disp.invokeOneWay(saxSourceReq1);

    // Test async polling
    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq2.xml");
    InputSource inputSource2 = new InputSource(is2);
    inputSource2.setPublicId(getClass()
                             .getResource("resources/GreetMeDocLiteralSOAPBodyReq2.xml").toString());
    inputSource2.setSystemId(inputSource2.getPublicId());
    SAXSource saxSourceReq2 = new SAXSource(inputSource2);
    assertNotNull(saxSourceReq2);
    Response<SAXSource> response = disp.invokeAsync(saxSourceReq2);
    SAXSource saxSourceResp2 = response.get();
    assertNotNull(saxSourceResp2);
    String expected2 = "Hello TestSOAPInputMessage2";
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp2).contains(expected2));

    // Test async callback
    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq3.xml");
    InputSource inputSource3 = new InputSource(is3);
    inputSource3.setPublicId(getClass()
                             .getResource("resources/GreetMeDocLiteralSOAPBodyReq3.xml").toString());
    inputSource3.setSystemId(inputSource3.getPublicId());
    SAXSource saxSourceReq3 = new SAXSource(inputSource3);
    assertNotNull(saxSourceReq3);

    TestSAXSourceHandler tssh = new TestSAXSourceHandler();
    Future<?> fd = disp.invokeAsync(saxSourceReq3, tssh);
    assertNotNull(fd);
    waitForFuture(fd);

    String expected3 = "Hello TestSOAPInputMessage3";
    SAXSource saxSourceResp3 = tssh.getSAXSource();
    assertNotNull(saxSourceResp3);
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp3).contains(expected3));
}
 
Example 17
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testSAXSourceMESSAGE() throws Exception {

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);

    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    InputSource inputSource = new InputSource(is);
    SAXSource saxSourceReq = new SAXSource(inputSource);
    assertNotNull(saxSourceReq);

    Dispatch<SAXSource> disp = service.createDispatch(PORT_NAME, SAXSource.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");
    SAXSource saxSourceResp = disp.invoke(saxSourceReq);
    assertNotNull(saxSourceResp);
    String expected = "Hello TestSOAPInputMessage";
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp).contains(expected));

    // Test oneway
    InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq1.xml");
    InputSource inputSource1 = new InputSource(is1);
    SAXSource saxSourceReq1 = new SAXSource(inputSource1);
    assertNotNull(saxSourceReq1);
    disp.invokeOneWay(saxSourceReq1);

    // Test async polling
    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq2.xml");
    InputSource inputSource2 = new InputSource(is2);
    SAXSource saxSourceReq2 = new SAXSource(inputSource2);
    assertNotNull(saxSourceReq2);

    Response<SAXSource> response = disp.invokeAsync(saxSourceReq2);
    SAXSource saxSourceResp2 = response.get();
    assertNotNull(saxSourceResp2);
    String expected2 = "Hello TestSOAPInputMessage2";
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp2).contains(expected2));

    // Test async callback
    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
    InputSource inputSource3 = new InputSource(is3);
    SAXSource saxSourceReq3 = new SAXSource(inputSource3);
    assertNotNull(saxSourceReq3);
    TestSAXSourceHandler tssh = new TestSAXSourceHandler();
    Future<?> fd = disp.invokeAsync(saxSourceReq3, tssh);
    assertNotNull(fd);
    waitForFuture(fd);

    String expected3 = "Hello TestSOAPInputMessage3";
    SAXSource saxSourceResp3 = tssh.getSAXSource();
    assertNotNull(saxSourceResp3);
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp3).contains(expected3));
}
 
Example 18
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testDOMSourcePAYLOAD() throws Exception {

    /*URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);*/
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://schemas.xmlsoap.org/soap/",
                    "http://localhost:"
                    + greeterPort + "/SOAPDispatchService/SoapDispatchPort");

    Dispatch<DOMSource> disp = service.createDispatch(PORT_NAME, DOMSource.class, Service.Mode.PAYLOAD);

    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
    DOMSource domReqMsg = new DOMSource(soapReqMsg.getSOAPBody().extractContentAsDocument());
    assertNotNull(domReqMsg);

    // invoke
    DOMSource domResMsg = disp.invoke(domReqMsg);

    assertNotNull(domResMsg);
    String expected = "Hello TestSOAPInputMessage";

    Node node = domResMsg.getNode();
    assertNotNull(node);
    if (node instanceof Document) {
        node = ((Document)node).getDocumentElement();
    }
    String content = node.getTextContent();
    assertNotNull(content);
    assertEquals("Response should be : Hello TestSOAPInputMessage", expected, content.trim());

    InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq1.xml");
    SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
    DOMSource domReqMsg1 = new DOMSource(soapReqMsg1.getSOAPBody().extractContentAsDocument());
    assertNotNull(domReqMsg1);
    // invokeOneWay
    disp.invokeOneWay(domReqMsg1);

    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq2.xml");
    SOAPMessage soapReqMsg2 = MessageFactory.newInstance().createMessage(null, is2);
    DOMSource domReqMsg2 = new DOMSource(soapReqMsg2.getSOAPBody().extractContentAsDocument());
    assertNotNull(domReqMsg2);
    // invokeAsync
    Response<DOMSource> response = disp.invokeAsync(domReqMsg2);
    DOMSource domRespMsg2 = response.get();
    assertNotNull(domRespMsg2);
    String expected2 = "Hello TestSOAPInputMessage2";

    node = domRespMsg2.getNode();
    assertNotNull(node);
    if (node instanceof Document) {
        node = ((Document)node).getDocumentElement();
    }
    content = node.getTextContent();
    assertNotNull(content);

    assertEquals("Response should be : Hello TestSOAPInputMessage2", expected2, content.trim());

    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
    SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
    DOMSource domReqMsg3 = new DOMSource(soapReqMsg3.getSOAPBody().extractContentAsDocument());
    assertNotNull(domReqMsg3);
    // invokeAsync with AsyncHandler
    TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
    Future<?> fd = disp.invokeAsync(domReqMsg3, tdsh);
    assertNotNull(fd);
    waitForFuture(fd);
    String expected3 = "Hello TestSOAPInputMessage3";
    assertEquals("Response should be : Hello TestSOAPInputMessage3",
                 expected3, tdsh.getReplyBuffer().trim());
}
 
Example 19
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testDOMSourceMESSAGE() throws Exception {
    /*URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);*/
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://schemas.xmlsoap.org/soap/",
                    "http://localhost:"
                    + greeterPort
                    + "/SOAPDispatchService/SoapDispatchPort");

    Dispatch<DOMSource> disp = service.createDispatch(PORT_NAME, DOMSource.class, Service.Mode.MESSAGE);

    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
    DOMSource domReqMsg = new DOMSource(soapReqMsg.getSOAPPart());
    assertNotNull(domReqMsg);


    DOMSource domResMsg = disp.invoke(domReqMsg);
    assertNotNull(domResMsg);
    String expected = "Hello TestSOAPInputMessage";

    assertEquals("Response should be : Hello TestSOAPInputMessage", expected,
                 DOMUtils.getAllContent(domResMsg.getNode().getFirstChild()).trim());

    Element el = (Element)domResMsg.getNode().getFirstChild();
    assertEquals("gmns", el.lookupPrefix("http://apache.org/hello_world_soap_http/types"));
    assertEquals("http://apache.org/hello_world_soap_http/types",
                 el.lookupNamespaceURI("gmns"));

    // Test invoke oneway
    InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq1.xml");
    SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
    DOMSource domReqMsg1 = new DOMSource(soapReqMsg1.getSOAPPart());
    assertNotNull(domReqMsg1);
    disp.invokeOneWay(domReqMsg1);

    // Test async polling
    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq2.xml");
    SOAPMessage soapReqMsg2 = MessageFactory.newInstance().createMessage(null, is2);
    DOMSource domReqMsg2 = new DOMSource(soapReqMsg2.getSOAPPart());
    assertNotNull(domReqMsg2);

    Response<DOMSource> response = disp.invokeAsync(domReqMsg2);
    DOMSource domRespMsg2 = response.get();
    assertNotNull(domReqMsg2);
    String expected2 = "Hello TestSOAPInputMessage2";
    assertEquals("Response should be : Hello TestSOAPInputMessage2", expected2, domRespMsg2.getNode()
        .getFirstChild().getTextContent().trim());

    // Test async callback
    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
    SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
    DOMSource domReqMsg3 = new DOMSource(soapReqMsg3.getSOAPPart());
    assertNotNull(domReqMsg3);

    TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
    Future<?> fd = disp.invokeAsync(domReqMsg3, tdsh);
    assertNotNull(fd);
    waitForFuture(fd);
    String expected3 = "Hello TestSOAPInputMessage3";
    assertEquals("Response should be : Hello TestSOAPInputMessage3", expected3,
                 tdsh.getReplyBuffer().trim());
}
 
Example 20
Source File: DispatchClientServerWithHugeResponseTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testElementCountThresholdfForSOAPMessageWithHugeResponse() throws Throwable {
    HugeResponseInterceptor hugeResponseInterceptor =
        new HugeResponseInterceptor(ResponseInterceptorType.ElementCountThreshold);
    getBus().getInInterceptors().add(hugeResponseInterceptor);
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<SOAPMessage> disp = service
        .createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");

    InputStream is3 = getClass().getResourceAsStream("GreetMeDocLiteralReq3.xml");
    SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
    assertNotNull(soapReqMsg3);
    Response<SOAPMessage> response = disp.invokeAsync(soapReqMsg3);
    try {
        response.get(300, TimeUnit.SECONDS);
        fail("should catch exception");
    } catch (TimeoutException te) {
        fail("We should not have encountered a timeout, "
            + "should get some exception tell me stackoverflow");
    } catch (ExecutionException e) {
        if (e.getCause() == null) {
            throw e;
        }
        Throwable t = e.getCause();
        if (t instanceof SOAPFaultException) {
            SoapFault sf = (SoapFault)t.getCause();
            if (sf.getCause() == null) {
                throw e;
            }
            t = sf.getCause();
        }
        if (t.getMessage() == null) {
            throw e;
        }

        String msg = t.getMessage();
        assertTrue(msg, msg.startsWith("reach the innerElementCountThreshold")
                   || msg.contains("Maximum Number of Child Elements"));
    } finally {
        getBus().getInInterceptors().remove(hugeResponseInterceptor);
    }

}