Java Code Examples for javax.xml.ws.Dispatch#invoke()

The following examples show how to use javax.xml.ws.Dispatch#invoke() . 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: DispatchHandlerInvocationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeWithDataSourcPayloadModeXMLBinding() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);

    XMLService service = new XMLService();
    assertNotNull(service);

    Dispatch<DataSource> disp = service.createDispatch(portNameXML, DataSource.class, Mode.PAYLOAD);
    setAddress(disp, addNumbersAddress);

    TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
    addHandlersProgrammatically(disp, handler);

    URL is = getClass().getResource("/messages/XML_GreetMeDocLiteralReq.xml");
    DataSource ds = new URLDataSource(is);
    DataSource resp = disp.invoke(ds);
    assertNotNull(resp);
}
 
Example 2
Source File: ClientServerRPCLitTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDispatchClient() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    Dispatch<Source> disp = service.createDispatch(portName, Source.class,
                                                   javax.xml.ws.Service.Mode.PAYLOAD);
    updateAddressPort(disp, PORT);

    String req = "<ns1:sendReceiveData xmlns:ns1=\"http://apache.org/hello_world_rpclit\">"
        + "<in xmlns:ns2=\"http://apache.org/hello_world_rpclit/types\">"
        + "<ns2:elem1>elem1</ns2:elem1><ns2:elem2>elem2</ns2:elem2><ns2:elem3>45</ns2:elem3>"
        + "</in></ns1:sendReceiveData>";
    Source source = new StreamSource(new StringReader(req));
    Source resp = disp.invoke(source);
    assertNotNull(resp);

    Node nd = StaxUtils.read(resp);
    if (nd instanceof Document) {
        nd = ((Document)nd).getDocumentElement();
    }
    XPathUtils xpu = new XPathUtils(new W3CNamespaceContext((Element)nd));
    assertTrue(xpu.isExist("/ns1:sendReceiveDataResponse/out", nd, XPathConstants.NODE));
}
 
Example 3
Source File: DispatchXMLClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDOMSourcePAYLOAD() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");
    assertNotNull(wsdl);

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

    InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
    Document doc = StaxUtils.read(is);
    DOMSource reqMsg = new DOMSource(doc);
    assertNotNull(reqMsg);

    Dispatch<DOMSource> disp = service.createDispatch(PORT_NAME, DOMSource.class,
                                                      Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + port
                                 + "/XMLService/XMLDispatchPort");
    DOMSource result = disp.invoke(reqMsg);
    assertNotNull(result);

    Node respDoc = result.getNode();
    assertEquals("greetMeResponse", respDoc.getFirstChild().getLocalName());
    assertEquals("Hello tli", respDoc.getFirstChild().getTextContent());
}
 
Example 4
Source File: DispatchHandlerInvocationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeWithJAXBMessageModeXMLBinding() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);

    XMLService service = new XMLService();
    assertNotNull(service);

    JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_xml_http.wrapped.types");
    Dispatch<Object> disp = service.createDispatch(portNameXML, jc, Mode.MESSAGE);
    setAddress(disp, greeterAddress);

    TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
    addHandlersProgrammatically(disp, handler);

    org.apache.hello_world_xml_http.wrapped.types.GreetMe req =
        new org.apache.hello_world_xml_http.wrapped.types.GreetMe();
    req.setRequestType("tli");

    Object response = disp.invoke(req);
    assertNotNull(response);
    org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse value =
        (org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse)response;
    assertEquals("Hello tli", value.getResponseType());
}
 
Example 5
Source File: ValidationClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHeaderValidation() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/schema_validation.wsdl");
    assertNotNull(wsdl);
    SchemaValidationService service = new SchemaValidationService(wsdl, serviceName);
    assertNotNull(service);


    String smsg = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Header>"
        + "<SomeHeader soap:mustUnderstand='1' xmlns='http://apache.org/schema_validation/types'>"
        + "<id>1111111111</id></SomeHeader>"
        + "</soap:Header><soap:Body><SomeRequestWithHeader xmlns='http://apache.org/schema_validation/types'>"
        + "<id>1111111111</id></SomeRequestWithHeader></soap:Body></soap:Envelope>";
    Dispatch<Source> dsp = service.createDispatch(SchemaValidationService.SoapPort, Source.class, Mode.MESSAGE);
    updateAddressPort(dsp, PORT);
    dsp.invoke(new StreamSource(new StringReader(smsg)));
}
 
Example 6
Source File: EmptySOAPBodyTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testProviderSource() throws Exception {
    QName providerServiceName = new QName("http://apache.org/hello_world_xml_http/bare",
                                          "HelloProviderService");

    QName providerPortName = new QName("http://apache.org/hello_world_xml_http/bare", "HelloProviderPort");

    URL wsdl = new URL("http://localhost:" + EmptySoapProviderServer.REG_PORT
                       + "/helloProvider/helloPort?wsdl");
    assertNotNull(wsdl);

    XMLService service = new XMLService(wsdl, providerServiceName, new LoggingFeature());
    assertNotNull(service);
    Dispatch<Source> dispatch = service.createDispatch(providerPortName, Source.class,
                                                       javax.xml.ws.Service.Mode.PAYLOAD);

    String str = new String("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
                          + "<ns2:in xmlns=\"http://apache.org/hello_world_xml_http/bare/types\""
                          + " xmlns:ns2=\"http://apache.org/hello_world_xml_http/bare\">"
                          + "<elem1>empty</elem1><elem2>this is element 2</elem2><elem3>42</elem3></ns2:in>"
                          + "</soap:Body></soap:Envelope>");
    StreamSource req = new StreamSource(new StringReader(str));
    Source resSource = dispatch.invoke(req);
    Assert.assertNull("null result is expected", resSource);
}
 
Example 7
Source File: Test.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 8
Source File: Test.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 9
Source File: Test.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 10
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testStAXSourcePAYLOAD() throws Exception {

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

    Service service = Service.create(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<StAXSource> disp = service.createDispatch(PORT_NAME, StAXSource.class, Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");
    QName opQName = new QName("http://apache.org/hello_world_soap_http", "greetMe");
    disp.getRequestContext().put(MessageContext.WSDL_OPERATION, opQName);

    // Test request-response
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
    StAXSource staxSourceReq = new StAXSource(StaxUtils.createXMLStreamReader(is));
    assertNotNull(staxSourceReq);
    Source resp = disp.invoke(staxSourceReq);
    assertNotNull(resp);
    assertTrue(resp instanceof StAXSource);
    String expected = "Hello TestSOAPInputMessage";
    String actual = StaxUtils.toString(StaxUtils.read(resp));
    assertTrue("Expected: " + expected, actual.contains(expected));
}
 
Example 11
Source File: Test.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 12
Source File: Test.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example 13
Source File: WSAPureWsdlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDispatchActionMissmatch() throws Exception {
    String req = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                + "<S:Body><addNumbers3 xmlns=\"http://apache.org/cxf/systest/ws/addr_feature/\">"
                + "<number1>1</number1><number2>2</number2></addNumbers3>"
                + "</S:Body></S:Envelope>";
    //String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
    String expectedOut = "http://bad.action";

    URL wsdl = getClass().getResource("/wsdl_systest_wsspec/add_numbers.wsdl");
    assertNotNull("WSDL is null", wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);


    Dispatch<Source> disp = service.createDispatch(AddNumbersService.AddNumbersPort,
                                                   Source.class, Mode.MESSAGE);

    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:" + PORT + "/jaxws/add");

    //manually set the action
    disp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,
                                 expectedOut);
    disp.getRequestContext().put(ContextUtils.ACTION,
                                 expectedOut + "/wsaAction");
    try {
        disp.invoke(new StreamSource(new StringReader(req)));
        fail("no exception");
    } catch (SOAPFaultException f) {
        //expected
    }
}
 
Example 14
Source File: SampleWsApplicationClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String address = "http://localhost:8080/Service/Hello";
    String request = "<q0:sayHello xmlns:q0=\"http://service.ws.sample/\"><myname>Elan</myname></q0:sayHello>";

    StreamSource source = new StreamSource(new StringReader(request));
    Service service = Service.create(new URL(address + "?wsdl"), 
                                     new QName("http://service.ws.sample/" , "HelloService"));
    Dispatch<Source> disp = service.createDispatch(new QName("http://service.ws.sample/" , "HelloPort"),
                                                   Source.class, Mode.PAYLOAD);
    
    Source result = disp.invoke(source);
    String resultAsString = StaxUtils.toString(result);
    System.out.println(resultAsString);
   
}
 
Example 15
Source File: ActionTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testSignatureDispatchPayload() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ActionTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfigPort");

    Dispatch<StreamSource> dispatch =
        service.createDispatch(portQName, StreamSource.class, Service.Mode.PAYLOAD);
    updateAddressPort(dispatch, PORT);

    // Programmatic interceptor
    Map<String, Object> props = new HashMap<>();
    props.put(ConfigurationConstants.ACTION, "Signature");
    props.put(ConfigurationConstants.SIGNATURE_USER, "alice");
    props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
    props.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
    props.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
    WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props);
    Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();
    client.getOutInterceptors().add(outInterceptor);

    String payload = "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">"
        + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>";
    StreamSource request = new StreamSource(new StringReader(payload));
    StreamSource response = dispatch.invoke(request);
    assertNotNull(response);

    Document doc = StaxUtils.read(response.getInputStream());
    assertEquals("50", doc.getElementsByTagNameNS(null, "doubledNumber").item(0).getTextContent());

    ((java.io.Closeable)dispatch).close();
    bus.shutdown(true);
}
 
Example 16
Source File: X509TokenTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAsymmetricIssuerSerialDispatchMessage() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = X509TokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = X509TokenTest.class.getResource("DoubleItX509.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricIssuerSerialOperationPort");

    Dispatch<SOAPMessage> disp = service.createDispatch(portQName, SOAPMessage.class, Mode.MESSAGE);
    updateAddressPort(disp, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(disp);
    }

    Document xmlDocument = DOMUtils.newDocument();

    Element requestElement = xmlDocument.createElementNS("http://www.example.org/schema/DoubleIt", "tns:DoubleIt");
    requestElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:tns",
                                  "http://www.example.org/schema/DoubleIt");
    Element dataElement = xmlDocument.createElement("numberToDouble");
    dataElement.appendChild(xmlDocument.createTextNode("25"));
    requestElement.appendChild(dataElement);
    xmlDocument.appendChild(requestElement);

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage request = factory.createMessage();
    request.getSOAPBody().appendChild(request.getSOAPPart().adoptNode(requestElement));

    // We need to set the wsdl operation name here, or otherwise the policy layer won't pick
    // up the security policy attached at the operation level
    // this can be done in one of three ways:
    // 1) set the WSDL_OPERATION context property
    //    QName wsdlOperationQName = new QName(NAMESPACE, "DoubleIt");
    //    disp.getRequestContext().put(MessageContext.WSDL_OPERATION, wsdlOperationQName);
    // 2) Set the "find.dispatch.operation" to TRUE to have  CXF explicitly try and determine it from the payload
    disp.getRequestContext().put("find.dispatch.operation", Boolean.TRUE);
    // 3) Turn on WS-Addressing as that will force #2
    //    TODO - add code for this, really is adding WS-Addressing feature to the createDispatch call above

    SOAPMessage resp = disp.invoke(request);
    Node nd = resp.getSOAPBody().getFirstChild();

    Map<String, String> ns = new HashMap<>();
    ns.put("ns2", "http://www.example.org/schema/DoubleIt");
    XPathUtils xp = new XPathUtils(ns);
    Object o = xp.getValue("//ns2:DoubleItResponse/doubledNumber", 
                           DOMUtils.getDomElement(nd), XPathConstants.STRING);
    assertEquals(StaxUtils.toString(nd), "50", o);

    bus.shutdown(true);
}
 
Example 17
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 18
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 19
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testJAXBObjectPAYLOADWithFeature() throws Exception {
    createBus("org/apache/cxf/systest/dispatch/client-config.xml");
    BusFactory.setThreadDefaultBus(bus);

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

    String bindingId = "http://schemas.xmlsoap.org/wsdl/soap/";
    String endpointUrl = "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort";

    Service service = Service.create(wsdl, SERVICE_NAME);
    service.addPort(PORT_NAME, bindingId, endpointUrl);
    assertNotNull(service);

    JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_soap_http.types");
    Dispatch<Object> disp = service.createDispatch(PORT_NAME, jc, Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");

    String expected = "Hello Jeeves";
    GreetMe greetMe = new GreetMe();
    greetMe.setRequestType("Jeeves");

    Object response = disp.invoke(greetMe);
    assertNotNull(response);
    String responseValue = ((GreetMeResponse)response).getResponseType();
    assertEquals("Expected string, " + expected, expected, responseValue);

    assertEquals("Feature should be applied", 1, TestDispatchFeature.getCount());
    assertEquals("Feature based interceptors should be added",
                 1, TestDispatchFeature.getCount());

    assertEquals("Feature based In interceptors has be added to in chain.",
                 1, TestDispatchFeature.getInInterceptorCount());

    assertEquals("Feature based interceptors has to be added to out chain.",
                 1, TestDispatchFeature.getOutInterceptorCount());
    bus.shutdown(true);
}
 
Example 20
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));
}