Search in sources :

Example 86 with SOAPMessage

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

the class HWDOMSourceMessageProvider method invoke.

public DOMSource invoke(DOMSource request) {
    QName qn = (QName) ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
    if (qn == null) {
        throw new RuntimeException("No Operation Name");
    }
    // XMLUtils.writeTo(request, System.out);
    DOMSource response = new DOMSource();
    try {
        SOAPMessage msg = factory.createMessage();
        msg.getSOAPPart().setContent(request);
        SOAPBody body = msg.getSOAPBody();
        Node n = body.getFirstChild();
        while (n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getNextSibling();
        }
        if (n.getLocalName().equals(sayHi.getLocalPart())) {
            response.setNode(sayHiResponse.getSOAPPart());
        } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
            response.setNode(greetMeResponse.getSOAPPart());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 87 with SOAPMessage

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

the class NBProviderClientServerTest method encodeRequest.

private SOAPMessage encodeRequest(MessageFactory factory, String value) throws SOAPException {
    SOAPMessage request = factory.createMessage();
    SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
    request.setProperty("soapaction", "");
    if (value != null) {
        request.getSOAPBody().addBodyElement(envelope.createName(value, "ns1", sayHi.getNamespaceURI()));
    }
    return request;
}
Also used : SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 88 with SOAPMessage

use of javax.xml.soap.SOAPMessage 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)

Example 89 with SOAPMessage

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

the class ClientServerSwaTest method testSwaTypesWithDispatchAPI.

@Test
public void testSwaTypesWithDispatchAPI() throws Exception {
    URL url1 = this.getClass().getResource("resources/attach.text");
    URL url2 = this.getClass().getResource("resources/attach.html");
    URL url3 = this.getClass().getResource("resources/attach.xml");
    URL url4 = this.getClass().getResource("resources/attach.jpeg1");
    URL url5 = this.getClass().getResource("resources/attach.jpeg2");
    byte[] bytes = IOUtils.readBytesFromStream(url1.openStream());
    byte[] bigBytes = new byte[bytes.length * 50];
    for (int x = 0; x < 50; x++) {
        System.arraycopy(bytes, 0, bigBytes, x * bytes.length, bytes.length);
    }
    DataHandler dh1 = new DataHandler(new ByteArrayDataSource(bigBytes, "text/plain"));
    DataHandler dh2 = new DataHandler(url2);
    DataHandler dh3 = new DataHandler(url3);
    DataHandler dh4 = new DataHandler(url4);
    DataHandler dh5 = new DataHandler(url5);
    SwAService service = new SwAService();
    Dispatch<SOAPMessage> disp = service.createDispatch(SwAService.SwAServiceHttpPort, SOAPMessage.class, Service.Mode.MESSAGE);
    setAddress(disp, "http://localhost:" + serverPort + "/swa");
    SOAPMessage msg = MessageFactory.newInstance().createMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
    body.addBodyElement(new QName("http://cxf.apache.org/swa/types", "VoidRequest"));
    AttachmentPart att = msg.createAttachmentPart(dh1);
    att.setContentId("<attach1=c187f5da-fa5d-4ab9-81db-33c2bb855201@apache.org>");
    msg.addAttachmentPart(att);
    att = msg.createAttachmentPart(dh2);
    att.setContentId("<attach2=c187f5da-fa5d-4ab9-81db-33c2bb855202@apache.org>");
    msg.addAttachmentPart(att);
    att = msg.createAttachmentPart(dh3);
    att.setContentId("<attach3=c187f5da-fa5d-4ab9-81db-33c2bb855203@apache.org>");
    msg.addAttachmentPart(att);
    att = msg.createAttachmentPart(dh4);
    att.setContentId("<attach4=c187f5da-fa5d-4ab9-81db-33c2bb855204@apache.org>");
    msg.addAttachmentPart(att);
    att = msg.createAttachmentPart(dh5);
    att.setContentId("<attach5=c187f5da-fa5d-4ab9-81db-33c2bb855205@apache.org>");
    msg.addAttachmentPart(att);
    // Test for CXF-
    msg = disp.invoke(msg);
    assertEquals(5, msg.countAttachments());
}
Also used : SwAService(org.apache.cxf.swa.SwAService) SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) AttachmentPart(javax.xml.soap.AttachmentPart) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 90 with SOAPMessage

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

the class HWSoapMessageDocProvider method resumeMessage.

public SOAPMessage resumeMessage(SOAPMessage request) {
    if (IncomingMessageCounterInterceptor.getMessageCount() != 1) {
        throw new RuntimeException("IncomingMessageCounterInterceptor get invoked twice");
    }
    QName qn = (QName) ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
    if (qn == null) {
        throw new RuntimeException("No Operation Name");
    }
    SOAPMessage response = null;
    try {
        SOAPBody body = request.getSOAPBody();
        Node n = body.getFirstChild();
        while (n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getNextSibling();
        }
        if (n.getLocalName().equals(sayHi.getLocalPart())) {
            response = sayHiResponse;
        } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
            Element el = DOMUtils.getFirstElement(n);
            String v = DOMUtils.getContent(el);
            if (v.contains("Return sayHi")) {
                response = sayHiResponse;
            } else {
                response = greetMeResponse;
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Aggregations

SOAPMessage (javax.xml.soap.SOAPMessage)219 SOAPException (javax.xml.soap.SOAPException)87 SOAPBody (javax.xml.soap.SOAPBody)47 Test (org.junit.Test)46 InputStream (java.io.InputStream)45 QName (javax.xml.namespace.QName)45 Element (org.w3c.dom.Element)44 IOException (java.io.IOException)40 MessageFactory (javax.xml.soap.MessageFactory)40 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)30 SOAPElement (javax.xml.soap.SOAPElement)28 ByteArrayInputStream (java.io.ByteArrayInputStream)26 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)25 XMLStreamReader (javax.xml.stream.XMLStreamReader)25 Node (org.w3c.dom.Node)24 Document (org.w3c.dom.Document)22 URL (java.net.URL)21 SOAPPart (javax.xml.soap.SOAPPart)21 Exchange (org.apache.cxf.message.Exchange)19 MessageImpl (org.apache.cxf.message.MessageImpl)19