Search in sources :

Example 61 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class DispatchClientServerTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    // CXF-2384
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    // pick one of the other service/ports that would have an address
    // without a service running
    QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    SOAPService service = new SOAPService(wsdl, otherServiceName);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + TestUtil.getPortNumber("fake-port") + "/SOAPDispatchService/SoapDispatchPort");
    DispatchImpl<?> dispImpl = (DispatchImpl<?>) disp;
    HTTPConduit cond = (HTTPConduit) dispImpl.getClient().getConduit();
    cond.getClient().setConnectionTimeout(500);
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
    assertNotNull(soapReqMsg);
    try {
        disp.invoke(soapReqMsg);
        fail("Should have faulted");
    } catch (SOAPFaultException ex) {
        fail("should not be a SOAPFaultException");
    } catch (WebServiceException ex) {
        // expected
        assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.net.ConnectException || ex.getCause() instanceof java.net.SocketTimeoutException);
    }
    dispImpl.close();
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SocketTimeoutException(java.net.SocketTimeoutException) Test(org.junit.Test)

Example 62 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class DispatchClientServerTest method testStreamSourceMESSAGE.

@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));
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) URL(java.net.URL) Test(org.junit.Test)

Example 63 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class DispatchClientServerTest method testSOAPMessage.

@Test
public void testSOAPMessage() throws Exception {
    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");
    // Test request-response
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
    assertNotNull(soapReqMsg);
    SOAPMessage soapResMsg = disp.invoke(soapReqMsg);
    assertNotNull(soapResMsg);
    String expected = "Hello TestSOAPInputMessage";
    assertEquals("Response should be : Hello TestSOAPInputMessage", expected, DOMUtils.getContent(SAAJUtils.getBody(soapResMsg).getFirstChild().getFirstChild()).trim());
    // Test oneway
    InputStream is1 = getClass().getResourceAsStream("resources/GreetMe1WDocLiteralReq2.xml");
    SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
    assertNotNull(soapReqMsg1);
    disp.invokeOneWay(soapReqMsg1);
    // Test async polling
    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq2.xml");
    SOAPMessage soapReqMsg2 = MessageFactory.newInstance().createMessage(null, is2);
    assertNotNull(soapReqMsg2);
    Response<?> response = disp.invokeAsync(soapReqMsg2);
    SOAPMessage soapResMsg2 = (SOAPMessage) response.get();
    assertNotNull(soapResMsg2);
    String expected2 = "Hello TestSOAPInputMessage2";
    assertEquals("Response should be : Hello TestSOAPInputMessage2", expected2, DOMUtils.getContent(SAAJUtils.getBody(soapResMsg2).getFirstChild().getFirstChild()));
    // Test async callback
    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
    SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
    assertNotNull(soapReqMsg3);
    TestSOAPMessageHandler tsmh = new TestSOAPMessageHandler();
    Future<?> f = disp.invokeAsync(soapReqMsg3, tsmh);
    assertNotNull(f);
    waitForFuture(f);
    String expected3 = "Hello TestSOAPInputMessage3";
    assertEquals("Response should be : Hello TestSOAPInputMessage3", expected3, tsmh.getReplyBuffer().trim());
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 64 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class DispatchClientServerTest method testSAXSourceMESSAGE.

@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));
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) InputStream(java.io.InputStream) URL(java.net.URL) Test(org.junit.Test)

Example 65 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.

the class DispatchClientServerTest method test404.

@Test
public void test404() throws Exception {
    // CXF-2384
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    // pick one of the other service/ports that would have an address
    // without a service running
    QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
    QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
    SOAPService service = new SOAPService(wsdl, otherServiceName);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SomePlaceWithNoServiceRunning/SoapDispatchPort");
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
    assertNotNull(soapReqMsg);
    try {
        disp.invoke(soapReqMsg);
        fail("Should have faulted");
    } catch (SOAPFaultException ex) {
        fail("should not be a SOAPFaultException");
    } catch (WebServiceException ex) {
        // expected
        assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.io.IOException);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SOAPService (org.apache.hello_world_soap_http.SOAPService)84 URL (java.net.URL)67 Test (org.junit.Test)56 Greeter (org.apache.hello_world_soap_http.Greeter)49 InputStream (java.io.InputStream)20 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)18 SOAPMessage (javax.xml.soap.SOAPMessage)14 Bus (org.apache.cxf.Bus)14 BindingProvider (javax.xml.ws.BindingProvider)13 Endpoint (javax.xml.ws.Endpoint)13 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)13 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)13 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)12 TimeoutException (java.util.concurrent.TimeoutException)8 WebServiceException (javax.xml.ws.WebServiceException)8 File (java.io.File)7 ExecutionException (java.util.concurrent.ExecutionException)7 QName (javax.xml.namespace.QName)7 BeforeClass (org.junit.BeforeClass)7 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6