Search in sources :

Example 51 with MessageFactory

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

the class HWSoapMessageProvider method invoke.

public SOAPMessage invoke(SOAPMessage request) {
    SOAPMessage response = null;
    try {
        SOAPBody body = SAAJUtils.getBody(request);
        Node n = body.getFirstChild();
        while (n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getNextSibling();
        }
        if (n.getLocalName().equals(sayHi.getLocalPart())) {
            response = sayHiResponse;
            if (request.countAttachments() > 0) {
                MessageFactory factory = MessageFactory.newInstance();
                InputStream is = getClass().getResourceAsStream("resources/sayHiRpcLiteralResp.xml");
                response = factory.createMessage(null, is);
                is.close();
                Iterator<AttachmentPart> it = CastUtils.cast(request.getAttachments(), AttachmentPart.class);
                while (it.hasNext()) {
                    response.addAttachmentPart(it.next());
                }
            }
        } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
            response = greetMeResponse;
        } else {
            response = request;
        // response.writeTo(System.out);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) AttachmentPart(javax.xml.soap.AttachmentPart) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 52 with MessageFactory

use of javax.xml.soap.MessageFactory in project quickstarts by jboss-switchyard.

the class SoapAttachmentClient method sendMessage.

public static SOAPMessage sendMessage(String switchyard_web_service) throws Exception {
    SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = conFactory.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage msg = msgFactory.createMessage();
    SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
    bodyElement.addTextNode("cid:switchyard.png");
    AttachmentPart ap = msg.createAttachmentPart();
    URL imageUrl = Classes.getResource("switchyard.png");
    ap.setDataHandler(new DataHandler(new URLDataSource(imageUrl)));
    ap.setContentId("switchyard.png");
    msg.addAttachmentPart(ap);
    return connection.call(msg, new URL(switchyard_web_service));
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) URLDataSource(javax.activation.URLDataSource) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPConnection(javax.xml.soap.SOAPConnection) AttachmentPart(javax.xml.soap.AttachmentPart) DataHandler(javax.activation.DataHandler) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 53 with MessageFactory

use of javax.xml.soap.MessageFactory in project jbossws-cxf by jbossws.

the class JaspiClientOutInterceptor method handleMessage.

@Override
public void handleMessage(SoapMessage message) throws Fault {
    if (message.getContent(SOAPMessage.class) == null) {
        SAAJInInterceptor saajIn = new SAAJInInterceptor();
        saajIn.handleMessage(message);
    }
    SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
    if (soapMessage == null) {
        return;
    }
    SOAPMessage copyMessage = null;
    try {
        MessageFactory messageFactory = SAAJPreInInterceptor.INSTANCE.getFactory(message);
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        soapMessage.writeTo(bout);
        copyMessage = messageFactory.createMessage(soapMessage.getMimeHeaders(), new ByteArrayInputStream(bout.toByteArray()));
    } catch (SOAPException e) {
        throw new Fault(e);
    } catch (IOException e) {
        throw new Fault(e);
    }
    if (copyMessage != null) {
        message.put(SOAPMessage.class, copyMessage);
    }
    try {
        authManager.secureRequest(message);
    } finally {
        message.put(SOAPMessage.class, soapMessage);
    }
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPException(javax.xml.soap.SOAPException) Fault(org.apache.cxf.interceptor.Fault) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 54 with MessageFactory

use of javax.xml.soap.MessageFactory in project jbossws-cxf by jbossws.

the class SOAPConnectionImpl method readSoapMessage.

@SuppressWarnings("unchecked")
private SOAPMessage readSoapMessage(Exchange exch) throws SOAPException {
    // read SOAPMessage
    try {
        InputStream ins = exch.get(InputStream.class);
        Map<String, List<String>> inHeaders = (Map<String, List<String>>) exch.get(Message.PROTOCOL_HEADERS);
        MimeHeaders mimeHeaders = new MimeHeaders();
        if (inHeaders != null) {
            for (Map.Entry<String, List<String>> entry : inHeaders.entrySet()) {
                if (entry.getValue() != null) {
                    for (String value : entry.getValue()) {
                        mimeHeaders.addHeader(entry.getKey(), value);
                    }
                }
            }
        }
        if (ins == null)
            return null;
        // if inputstream is empty, no need to build
        if (ins.markSupported()) {
            ins.mark(1);
            final int bytesRead = ins.read(new byte[1]);
            ins.reset();
            if (bytesRead == -1) {
                return null;
            }
        } else if (ins.available() == 0) {
            return null;
        }
        MessageFactory msgFac = MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
        return msgFac.createMessage(mimeHeaders, ins);
    } catch (Exception ex) {
        throw MESSAGES.soapMessageCouldNotBeRead(ex);
    }
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException)

Example 55 with MessageFactory

use of javax.xml.soap.MessageFactory in project jbossws-cxf by jbossws.

the class JaspiSeverInInterceptor method handleMessage.

@Override
public void handleMessage(SoapMessage message) throws Fault {
    if (message.getContent(SOAPMessage.class) == null) {
        SAAJInInterceptor saajIn = new SAAJInInterceptor();
        saajIn.handleMessage(message);
    }
    SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
    if (soapMessage == null) {
        return;
    }
    SOAPMessage copyMessage = null;
    try {
        MessageFactory messageFactory = SAAJPreInInterceptor.INSTANCE.getFactory(message);
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        soapMessage.writeTo(bout);
        copyMessage = messageFactory.createMessage(soapMessage.getMimeHeaders(), new ByteArrayInputStream(bout.toByteArray()));
    } catch (SOAPException e) {
        throw new Fault(e);
    } catch (IOException e) {
        throw new Fault(e);
    }
    if (copyMessage != null) {
        message.put(SOAPMessage.class, copyMessage);
    }
    try {
        authManager.validateRequest(message);
    } finally {
        message.put(SOAPMessage.class, soapMessage);
    }
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPException(javax.xml.soap.SOAPException) Fault(org.apache.cxf.interceptor.Fault) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPMessage(javax.xml.soap.SOAPMessage)

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