Search in sources :

Example 26 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithDOMSourcMessageModeXMLBinding.

@Test
public void testInvokeWithDOMSourcMessageModeXMLBinding() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    XMLService service = new XMLService();
    assertNotNull(service);
    Dispatch<DOMSource> disp = service.createDispatch(portNameXML, DOMSource.class, Mode.MESSAGE);
    setAddress(disp, addNumbersAddress);
    TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
    addHandlersProgrammatically(disp, handler);
    InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is);
    DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
    DOMSource response = disp.invoke(domReqMessage);
    assertNotNull(response);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) XMLService(org.apache.hello_world_xml_http.wrapped.XMLService) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 27 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithSOAPMessagePayloadMode.

@Test
public void testInvokeWithSOAPMessagePayloadMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Mode.PAYLOAD);
    setAddress(disp, addNumbersAddress);
    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);
    InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is2);
    try {
        disp.invoke(soapReq);
        fail("Did not get expected exception");
    } catch (SOAPFaultException e) {
        assertTrue("Did not get expected exception message: " + e.getMessage(), e.getMessage().indexOf("is not valid in PAYLOAD mode with SOAP/HTTP binding") > -1);
    }
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 28 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithDOMSourcPayloadMode.

@Test
public void testInvokeWithDOMSourcPayloadMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);
    Dispatch<DOMSource> disp = service.createDispatch(portName, DOMSource.class, Mode.PAYLOAD);
    setAddress(disp, addNumbersAddress);
    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);
    InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReqPayload.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is2);
    DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
    DOMSource response = disp.invoke(domReqMessage);
    assertNotNull(response);
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) DOMSource(javax.xml.transform.dom.DOMSource) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 29 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class CXF4130Provider method invoke.

public SOAPMessage invoke(SOAPMessage request) {
    try {
        Node node = DOMUtils.getFirstElement(SAAJUtils.getBody(request));
        String requestMsgName = node.getLocalName();
        String responseText = null;
        if ("FooRequest".equals(requestMsgName)) {
            responseText = "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<SOAP-ENV:Header>" + "<FooResponseHeader xmlns:ns2=\"http://cxf.apache.org/soapheader/inband\">" + "FooResponseHeader</FooResponseHeader>" + "</SOAP-ENV:Header>" + "<SOAP-ENV:Body>" + "<ns2:FooResponse xmlns:ns2=\"http://cxf.apache.org/soapheader/inband\">" + "<ns2:Return>Foo Response Body</ns2:Return>" + "</ns2:FooResponse>" + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>\n";
        } else {
            throw new WebServiceException("Error in InBand Provider JAX-WS service -- Unknown Request: " + requestMsgName);
        }
        // Create a SOAP request message
        MessageFactory soapmsgfactory = MessageFactory.newInstance();
        SOAPMessage responseMessage = soapmsgfactory.createMessage();
        StreamSource responseMessageSrc = null;
        responseMessageSrc = new StreamSource(new StringReader(responseText));
        responseMessage.getSOAPPart().setContent(responseMessageSrc);
        responseMessage.saveChanges();
        return responseMessage;
    } catch (Exception e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) MessageFactory(javax.xml.soap.MessageFactory) Node(org.w3c.dom.Node) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) SOAPMessage(javax.xml.soap.SOAPMessage) WebServiceException(javax.xml.ws.WebServiceException)

Example 30 with MessageFactory

use of javax.xml.soap.MessageFactory in project cxf by apache.

the class ProviderRPCClientServerTest method testSWA.

@Test
public void testSWA() throws Exception {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();
    QName sayHi = new QName("http://apache.org/hello_world_rpclit", "sayHiWAttach");
    msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
    AttachmentPart ap1 = msg.createAttachmentPart();
    ap1.setContent("Attachment content", "text/plain");
    msg.addAttachmentPart(ap1);
    AttachmentPart ap2 = msg.createAttachmentPart();
    ap2.setContent("Attachment content - Part 2", "text/plain");
    msg.addAttachmentPart(ap2);
    msg.saveChanges();
    SOAPConnection con = conFac.createConnection();
    URL endpoint = new URL("http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1");
    SOAPMessage response = con.call(msg, endpoint);
    QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse");
    assertNotNull(response.getSOAPBody().getChildElements(sayHiResp));
    assertEquals(2, response.countAttachments());
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPConnection(javax.xml.soap.SOAPConnection) AttachmentPart(javax.xml.soap.AttachmentPart) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPFactory(javax.xml.soap.SOAPFactory) URL(java.net.URL) Test(org.junit.Test)

Aggregations

MessageFactory (javax.xml.soap.MessageFactory)70 SOAPMessage (javax.xml.soap.SOAPMessage)65 URL (java.net.URL)24 InputStream (java.io.InputStream)22 QName (javax.xml.namespace.QName)22 SOAPException (javax.xml.soap.SOAPException)22 Test (org.junit.Test)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 SOAPBody (javax.xml.soap.SOAPBody)18 SOAPPart (javax.xml.soap.SOAPPart)17 StreamSource (javax.xml.transform.stream.StreamSource)14 SOAPConnection (javax.xml.soap.SOAPConnection)13 IOException (java.io.IOException)11 SOAPElement (javax.xml.soap.SOAPElement)11 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)10 JBossWSTest (org.jboss.wsf.test.JBossWSTest)10 NodeList (org.w3c.dom.NodeList)9 AttachmentPart (javax.xml.soap.AttachmentPart)8 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)8 Element (org.w3c.dom.Element)8