Search in sources :

Example 36 with SOAPPart

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

the class JBossWSClientAuthConfig method getAuthContextID.

@SuppressWarnings("rawtypes")
public String getAuthContextID(MessageInfo messageInfo) {
    SOAPMessage request = (SOAPMessage) messageInfo.getRequestMessage();
    if (request == null) {
        return null;
    }
    String authContext = null;
    MimeHeaders headers = request.getMimeHeaders();
    if (headers != null) {
        String[] soapActions = headers.getHeader("SOAPAction");
        if (soapActions != null && soapActions.length > 0) {
            authContext = soapActions[0];
            if (!StringUtils.isEmpty(authContext)) {
                return authContext;
            }
        }
    }
    SOAPPart soapMessage = request.getSOAPPart();
    if (soapMessage != null) {
        try {
            SOAPEnvelope envelope = soapMessage.getEnvelope();
            if (envelope != null) {
                SOAPBody body = envelope.getBody();
                if (body != null) {
                    Iterator it = body.getChildElements();
                    while (it.hasNext()) {
                        Object o = it.next();
                        if (o instanceof SOAPElement) {
                            QName name = ((SOAPElement) o).getElementQName();
                            return name.getLocalPart();
                        }
                    }
                }
            }
        } catch (SOAPException se) {
            // ignore;
            Logger.getLogger(JBossWSClientAuthConfig.class).trace(se);
        }
    }
    return null;
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 37 with SOAPPart

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

the class JBossWSServerAuthConfig method getAuthContextID.

@SuppressWarnings("rawtypes")
public String getAuthContextID(MessageInfo messageInfo) {
    SOAPMessage request = (SOAPMessage) messageInfo.getRequestMessage();
    if (request == null) {
        return null;
    }
    String authContext = null;
    MimeHeaders headers = request.getMimeHeaders();
    if (headers != null) {
        String[] soapActions = headers.getHeader("SOAPAction");
        if (soapActions != null && soapActions.length > 0) {
            authContext = soapActions[0];
            if (!StringUtils.isEmpty(authContext)) {
                return authContext;
            }
        }
    }
    SOAPPart soapMessage = request.getSOAPPart();
    if (soapMessage != null) {
        try {
            SOAPEnvelope envelope = soapMessage.getEnvelope();
            if (envelope != null) {
                SOAPBody body = envelope.getBody();
                if (body != null) {
                    Iterator it = body.getChildElements();
                    while (it.hasNext()) {
                        Object o = it.next();
                        if (o instanceof SOAPElement) {
                            QName name = ((SOAPElement) o).getElementQName();
                            return name.getLocalPart();
                        }
                    }
                }
            }
        } catch (SOAPException se) {
            // ignore;
            Logger.getLogger(JBossWSServerAuthConfig.class).trace(se);
        }
    }
    return null;
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 38 with SOAPPart

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

the class TestHandler method checkEnvelope.

private void checkEnvelope(SOAPMessage soapMessage) throws SOAPException {
    SOAPPart part = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    String namespace = envelope.getNamespaceURI();
    if (envelopeNamespace.equals(namespace) == false) {
        throw new RuntimeException("Expected '" + envelopeNamespace + "' namespace, actual '" + namespace + "'");
    }
}
Also used : SOAPPart(javax.xml.soap.SOAPPart) SOAPEnvelope(javax.xml.soap.SOAPEnvelope)

Example 39 with SOAPPart

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

the class ProviderMessageTestCase method testProviderMessageNullResponse.

@Test
@RunAsClient
public void testProviderMessageNullResponse() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgStringForNullResponse.getBytes()));
    URL epURL = baseURL;
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    if (resMsg != null) {
        SOAPPart soapPart = resMsg.getSOAPPart();
        // verify there's either nothing in the reply or at least the response body is empty
        if (soapPart != null && soapPart.getEnvelope() != null && soapPart.getEnvelope().getBody() != null) {
            SOAPBody soapBody = soapPart.getEnvelope().getBody();
            assertFalse(soapBody.getChildElements().hasNext());
        }
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPPart(javax.xml.soap.SOAPPart) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 40 with SOAPPart

use of javax.xml.soap.SOAPPart in project iaf by ibissource.

the class SOAPProviderBase method invoke.

@Override
public SOAPMessage invoke(SOAPMessage request) {
    String result;
    try (PipeLineSession pipelineSession = new PipeLineSession()) {
        String correlationId = Misc.createSimpleUUID();
        log.debug(getLogPrefix(correlationId) + "received message");
        String soapProtocol = SOAPConstants.SOAP_1_1_PROTOCOL;
        if (request == null) {
            String faultcode = "soap:Server";
            String faultstring = "SOAPMessage is null";
            String httpRequestMethod = (String) webServiceContext.getMessageContext().get(MessageContext.HTTP_REQUEST_METHOD);
            if (!"POST".equals(httpRequestMethod)) {
                faultcode = "soap:Client";
                faultstring = "Request was send using '" + httpRequestMethod + "' instead of 'POST'";
            }
            result = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body><soap:Fault>" + "<faultcode>" + faultcode + "</faultcode>" + "<faultstring>" + faultstring + "</faultstring>" + "</soap:Fault></soap:Body></soap:Envelope>";
        } else {
            // Make mime headers in request available as session key
            @SuppressWarnings("unchecked") Iterator<MimeHeader> mimeHeaders = request.getMimeHeaders().getAllHeaders();
            String mimeHeadersXml = getMimeHeadersXml(mimeHeaders).toXML();
            pipelineSession.put("mimeHeaders", mimeHeadersXml);
            // Make attachments in request (when present) available as session keys
            int i = 1;
            XmlBuilder attachments = new XmlBuilder("attachments");
            @SuppressWarnings("unchecked") Iterator<AttachmentPart> attachmentParts = request.getAttachments();
            while (attachmentParts.hasNext()) {
                try {
                    AttachmentPart attachmentPart = attachmentParts.next();
                    XmlBuilder attachment = new XmlBuilder("attachment");
                    attachments.addSubElement(attachment);
                    XmlBuilder sessionKey = new XmlBuilder("sessionKey");
                    sessionKey.setValue("attachment" + i);
                    attachment.addSubElement(sessionKey);
                    Message rawContent = new Message(attachmentPart.getRawContentBytes());
                    pipelineSession.put("attachment" + i, rawContent);
                    log.debug(getLogPrefix(correlationId) + "adding attachment [attachment" + i + "] to session");
                    @SuppressWarnings("unchecked") Iterator<MimeHeader> attachmentMimeHeaders = attachmentPart.getAllMimeHeaders();
                    attachment.addSubElement(getMimeHeadersXml(attachmentMimeHeaders));
                } catch (SOAPException e) {
                    log.warn("Could not store attachment in session key", e);
                }
                i++;
            }
            pipelineSession.put("attachments", attachments.toXML());
            // Transform SOAP message to string
            String message;
            try {
                SOAPPart part = request.getSOAPPart();
                try {
                    if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(part.getEnvelope().getNamespaceURI()))
                        soapProtocol = SOAPConstants.SOAP_1_2_PROTOCOL;
                } catch (SOAPException e) {
                    log.error("unable to determine SOAP URI NS type, falling back to SOAP 1.1", e);
                }
                message = XmlUtils.nodeToString(part);
                log.debug(getLogPrefix(correlationId) + "transforming from SOAP message");
            } catch (TransformerException e) {
                String m = "Could not transform SOAP message to string";
                log.error(m, e);
                throw new WebServiceException(m, e);
            }
            pipelineSession.put("soapProtocol", soapProtocol);
            if (soapProtocol.equals(SOAPConstants.SOAP_1_1_PROTOCOL)) {
                String soapAction = (String) webServiceContext.getMessageContext().get(SoapBindingConstants.SOAP_ACTION);
                pipelineSession.put(SoapBindingConstants.SOAP_ACTION, soapAction);
            } else if (soapProtocol.equals(SOAPConstants.SOAP_1_2_PROTOCOL)) {
                String contentType = (String) webServiceContext.getMessageContext().get("Content-Type");
                if (StringUtils.isNotEmpty(contentType) && contentType.contains("action=")) {
                    String action = findAction(contentType);
                    if (StringUtils.isNotEmpty(action)) {
                        pipelineSession.put(SoapBindingConstants.SOAP_ACTION, action);
                    } else {
                        log.warn(getLogPrefix(correlationId) + "no SOAPAction found!");
                    }
                }
            }
            // Process message via WebServiceListener
            ISecurityHandler securityHandler = new WebServiceContextSecurityHandler(webServiceContext);
            pipelineSession.setSecurityHandler(securityHandler);
            pipelineSession.put(PipeLineSession.HTTP_REQUEST_KEY, webServiceContext.getMessageContext().get(MessageContext.SERVLET_REQUEST));
            pipelineSession.put(PipeLineSession.HTTP_RESPONSE_KEY, webServiceContext.getMessageContext().get(MessageContext.SERVLET_RESPONSE));
            try {
                log.debug(getLogPrefix(correlationId) + "processing message");
                result = processRequest(correlationId, new Message(message), pipelineSession).asString();
            } catch (ListenerException | IOException e) {
                String m = "Could not process SOAP message: " + e.getMessage();
                log.error(m);
                throw new WebServiceException(m, e);
            }
        }
        // Transform result string to SOAP message
        SOAPMessage soapMessage = null;
        try {
            log.debug(getLogPrefix(correlationId) + "transforming to SOAP message");
            soapMessage = getMessageFactory(soapProtocol).createMessage();
            StreamSource streamSource = new StreamSource(new StringReader(result));
            soapMessage.getSOAPPart().setContent(streamSource);
        } catch (SOAPException e) {
            String m = "Could not transform string to SOAP message";
            log.error(m);
            throw new WebServiceException(m, e);
        }
        try {
            String multipartXml = pipelineSession.getMessage(attachmentXmlSessionKey).asString();
            log.debug(getLogPrefix(correlationId) + "building multipart message with MultipartXmlSessionKey [" + multipartXml + "]");
            if (StringUtils.isNotEmpty(multipartXml)) {
                Element partsElement;
                try {
                    partsElement = XmlUtils.buildElement(multipartXml);
                } catch (DomBuilderException e) {
                    String m = "error building multipart xml";
                    log.error(m, e);
                    throw new WebServiceException(m, e);
                }
                Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part");
                if (parts == null || parts.size() == 0) {
                    log.warn(getLogPrefix(correlationId) + "no part(s) in multipart xml [" + multipartXml + "]");
                } else {
                    Iterator<Node> iter = parts.iterator();
                    while (iter.hasNext()) {
                        Element partElement = (Element) iter.next();
                        // String partType = partElement.getAttribute("type");
                        String partName = partElement.getAttribute("name");
                        String partSessionKey = partElement.getAttribute("sessionKey");
                        String partMimeType = partElement.getAttribute("mimeType");
                        Message partObject = pipelineSession.getMessage(partSessionKey);
                        DataHandler dataHander;
                        try {
                            if (partObject.isBinary()) {
                                dataHander = new DataHandler(new ByteArrayDataSource(partObject.asByteArray(), partMimeType));
                            } else {
                                dataHander = new DataHandler(new ByteArrayDataSource(partObject.asString(), partMimeType));
                            }
                        } catch (IOException e) {
                            String m = "Unable to add session key '" + partSessionKey + "' as attachment";
                            log.error(m, e);
                            throw new WebServiceException(m, e);
                        }
                        AttachmentPart attachmentPart = soapMessage.createAttachmentPart(dataHander);
                        attachmentPart.setContentId(partName);
                        soapMessage.addAttachmentPart(attachmentPart);
                        log.debug(getLogPrefix(correlationId) + "appended filepart [" + partSessionKey + "] name [" + partName + "]");
                    }
                }
            }
        } catch (IOException e) {
            String m = "Could not transform attachment";
            log.error(m);
            throw new WebServiceException(m, e);
        }
        return soapMessage;
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) SOAPMessage(javax.xml.soap.SOAPMessage) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) DataHandler(javax.activation.DataHandler) SOAPMessage(javax.xml.soap.SOAPMessage) ListenerException(nl.nn.adapterframework.core.ListenerException) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) StringReader(java.io.StringReader) ByteArrayDataSource(org.apache.soap.util.mime.ByteArrayDataSource) TransformerException(javax.xml.transform.TransformerException) ISecurityHandler(nl.nn.adapterframework.core.ISecurityHandler) WebServiceException(javax.xml.ws.WebServiceException) StreamSource(javax.xml.transform.stream.StreamSource) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) AttachmentPart(javax.xml.soap.AttachmentPart) IOException(java.io.IOException) MimeHeader(javax.xml.soap.MimeHeader) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException)

Aggregations

SOAPPart (javax.xml.soap.SOAPPart)45 SOAPMessage (javax.xml.soap.SOAPMessage)30 SOAPBody (javax.xml.soap.SOAPBody)28 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)26 SOAPException (javax.xml.soap.SOAPException)26 MessageFactory (javax.xml.soap.MessageFactory)17 SOAPElement (javax.xml.soap.SOAPElement)14 Iterator (java.util.Iterator)13 Element (org.w3c.dom.Element)13 StreamSource (javax.xml.transform.stream.StreamSource)12 QName (javax.xml.namespace.QName)11 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 Name (javax.xml.soap.Name)10 NodeList (org.w3c.dom.NodeList)9 BufferedWriter (java.io.BufferedWriter)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 OutputStreamWriter (java.io.OutputStreamWriter)7 HttpURLConnection (java.net.HttpURLConnection)7 SOAPHeader (javax.xml.soap.SOAPHeader)6