Search in sources :

Example 66 with SOAPService

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

the class DispatchClientServerTest method testDOMSourceMESSAGE.

@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());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) SOAPService(org.apache.hello_world_soap_http.SOAPService) Service(javax.xml.ws.Service) WebService(javax.jws.WebService) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.junit.Test)

Example 67 with SOAPService

use of org.apache.hello_world_soap_http.SOAPService 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 68 with SOAPService

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

the class DispatchClientServerTest method testCreateDispatchWithEPR.

@Test
public void testCreateDispatchWithEPR() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder.address("http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
    builder.serviceName(SERVICE_NAME);
    builder.endpointName(PORT_NAME);
    W3CEndpointReference w3cEpr = builder.build();
    Dispatch<SOAPMessage> disp = service.createDispatch(w3cEpr, SOAPMessage.class, Service.Mode.MESSAGE);
    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.getAllContent(SAAJUtils.getBody(soapResMsg)).trim());
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 69 with SOAPService

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

the class DispatchClientServerTest method testStreamSourcePAYLOADWithSchemaValidation.

@Test
public void testStreamSourcePAYLOADWithSchemaValidation() throws Exception {
    URL wsdl = getClass().getResource("/org/apache/cxf/systest/provider/hello_world_with_restriction.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");
    disp.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReqExceedMaxLength.xml");
    StreamSource streamSourceReq = new StreamSource(is);
    assertNotNull(streamSourceReq);
    try {
        disp.invoke(streamSourceReq);
        fail("Should have thrown an exception");
    } catch (Exception ex) {
        // expected
        assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
    }
    is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
    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));
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SocketTimeoutException(java.net.SocketTimeoutException) ExecutionException(java.util.concurrent.ExecutionException) WebServiceException(javax.xml.ws.WebServiceException) Test(org.junit.Test)

Example 70 with SOAPService

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

the class DispatchClientServerTest method testJAXBObjectPAYLOADFromEPR.

@Test
public void testJAXBObjectPAYLOADFromEPR() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder.address("http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
    builder.serviceName(SERVICE_NAME);
    builder.endpointName(PORT_NAME);
    W3CEndpointReference w3cEpr = builder.build();
    JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_soap_http.types");
    Dispatch<Object> disp = service.createDispatch(w3cEpr, jc, Service.Mode.PAYLOAD, new AddressingFeature());
    doJAXBPayload(disp);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) AddressingFeature(javax.xml.ws.soap.AddressingFeature) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) JAXBContext(javax.xml.bind.JAXBContext) 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