Search in sources :

Example 71 with SOAPMessage

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

the class SOAPHandlerInterceptor method handleMessage.

public void handleMessage(SoapMessage message) {
    if (binding.getHandlerChain().isEmpty()) {
        return;
    }
    if (getInvoker(message).getProtocolHandlers().isEmpty()) {
        return;
    }
    checkUnderstoodHeaders(message);
    if (getInvoker(message).isOutbound()) {
        if (!chainAlreadyContainsSAAJ(message)) {
            SAAJ_OUT.handleMessage(message);
        }
        message.getInterceptorChain().add(ending);
    } else {
        boolean isFault = handleMessageInternal(message);
        SOAPMessage msg = message.getContent(SOAPMessage.class);
        if (msg != null) {
            XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(msg);
            message.setContent(XMLStreamReader.class, xmlReader);
            // replace headers
            try {
                SAAJInInterceptor.replaceHeaders(msg, message);
            } catch (SOAPException e) {
                e.printStackTrace();
            }
        }
        if (isFault) {
            Endpoint ep = message.getExchange().getEndpoint();
            message.getInterceptorChain().abort();
            if (ep.getInFaultObserver() != null) {
                ep.getInFaultObserver().onMessage(message);
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Endpoint(org.apache.cxf.endpoint.Endpoint) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 72 with SOAPMessage

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

the class SOAPHandlerInterceptor method createProtocolMessageContext.

@Override
protected MessageContext createProtocolMessageContext(SoapMessage message) {
    SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);
    Exchange exch = message.getExchange();
    setupBindingOperationInfo(exch, sm);
    SOAPMessage msg = sm.getMessage();
    if (msg != null) {
        try {
            List<SOAPElement> params = new ArrayList<>();
            message.put(MessageContext.REFERENCE_PARAMETERS, params);
            SOAPHeader head = SAAJUtils.getHeader(msg);
            if (head != null) {
                Iterator<Node> it = CastUtils.cast(head.getChildElements());
                while (it != null && it.hasNext()) {
                    Node nd = it.next();
                    if (nd instanceof SOAPElement) {
                        SOAPElement el = (SOAPElement) nd;
                        if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter") && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")) || Boolean.parseBoolean(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")))) {
                            params.add(el);
                        }
                    }
                }
            }
            if (isRequestor(message) && msg.getSOAPPart().getEnvelope().getBody() != null && msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
                return null;
            }
        } catch (SOAPException e) {
            throw new Fault(e);
        }
    }
    return sm;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Node(javax.xml.soap.Node) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) ArrayList(java.util.ArrayList) Fault(org.apache.cxf.interceptor.Fault) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 73 with SOAPMessage

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

the class SOAPHandlerInterceptor method getOpQName.

protected QName getOpQName(Exchange ex, Object data) {
    SOAPMessageContextImpl sm = (SOAPMessageContextImpl) data;
    try {
        SOAPMessage msg = sm.getMessage();
        if (msg == null) {
            return null;
        }
        SOAPBody body = SAAJUtils.getBody(msg);
        if (body == null) {
            return null;
        }
        org.w3c.dom.Node nd = body.getFirstChild();
        while (nd != null && !(nd instanceof org.w3c.dom.Element)) {
            nd = nd.getNextSibling();
        }
        if (nd != null) {
            return new QName(nd.getNamespaceURI(), nd.getLocalName());
        }
    } catch (SOAPException e) {
    // ignore, nothing we can do
    }
    return null;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 74 with SOAPMessage

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

the class GreeterDOMSourceMessageProvider method invoke.

public DOMSource invoke(DOMSource request) {
    DOMSource response = new DOMSource();
    try {
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage soapReq = factory.createMessage();
        soapReq.getSOAPPart().setContent(request);
        System.out.println("Incoming Client Request as a DOMSource data in MESSAGE Mode");
        soapReq.writeTo(System.out);
        System.out.println("\n");
        InputStream is = getClass().getResourceAsStream("/GreetMeDocLiteralResp2.xml");
        SOAPMessage greetMeResponse = factory.createMessage(null, is);
        is.close();
        response.setNode(greetMeResponse.getSOAPPart());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 75 with SOAPMessage

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

the class GreeterSoapMessageProvider method invoke.

public SOAPMessage invoke(SOAPMessage request) {
    SOAPMessage response = null;
    try {
        System.out.println("Incoming Client Request as a SOAPMessage");
        MessageFactory factory = MessageFactory.newInstance();
        InputStream is = getClass().getResourceAsStream("/GreetMeDocLiteralResp1.xml");
        response = factory.createMessage(null, is);
        is.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

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