Search in sources :

Example 51 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class XMLStreamDataReader method read.

public DOMSource read(XMLStreamReader reader) {
    // performance reasons
    try {
        XMLStreamReader reader2 = reader;
        if (reader2 instanceof DepthXMLStreamReader) {
            reader2 = ((DepthXMLStreamReader) reader2).getReader();
        }
        if (reader2 instanceof W3CDOMStreamReader) {
            W3CDOMStreamReader domreader = (W3CDOMStreamReader) reader2;
            DOMSource o = new DOMSource(domreader.getCurrentElement());
            domreader.consumeFrame();
            return o;
        }
        Document document = StaxUtils.read(reader);
        if (reader.hasNext()) {
            // need to actually consume the END_ELEMENT
            reader.next();
        }
        return new DOMSource(document);
    } catch (XMLStreamException e) {
        throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e, e.getMessage());
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) W3CDOMStreamReader(org.apache.cxf.staxutils.W3CDOMStreamReader) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) Document(org.w3c.dom.Document)

Example 52 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class XSLTUtils method transform.

public static Document transform(Templates xsltTemplate, Document in) {
    try {
        DOMSource beforeSource = new DOMSource(in);
        Document out = DOMUtils.createDocument();
        Transformer trans = xsltTemplate.newTransformer();
        trans.transform(beforeSource, new DOMResult(out));
        return out;
    } catch (TransformerException e) {
        throw new Fault("XML_TRANSFORM", LOG, e, e.getMessage());
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) Fault(org.apache.cxf.interceptor.Fault) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException)

Example 53 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class SoapBindingFactory method setupUDP.

protected void setupUDP(InterceptorProvider p, EndpointInfo ei) {
    // soap UDP requires ws-addressing turned on
    WSAddressingFeature add = new WSAddressingFeature();
    add.setAddressingRequired(true);
    add.initialize(p, bus);
    // UDP has a strict size limit on messages (<64K) so we'll try to shrink the
    // message a little by putting the WSA namespace into the
    // the soap:env which allows it to not be written on every header
    // element as well as disable the output stream optimizations (doesn't really
    // matter on such small messages anyway) to make sure we pickup those
    // namespaces that are declared there.
    p.getOutInterceptors().add(new AbstractSoapInterceptor(Phase.POST_LOGICAL) {

        public void handleMessage(SoapMessage message) throws Fault {
            AddressingProperties p = ContextUtils.retrieveMAPs(message, false, true);
            if (p == null) {
                return;
            }
            String ns = p.getNamespaceURI();
            Map<String, String> nsMap = message.getEnvelopeNs();
            if (nsMap == null) {
                nsMap = new HashMap<>();
            } else {
                nsMap = new HashMap<>(nsMap);
            }
            message.put("soap.env.ns.map", nsMap);
            if (!nsMap.containsValue(ns) && !nsMap.containsKey("wsa")) {
                nsMap.put("wsa", ns);
            }
            message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION, Boolean.TRUE);
        }
    });
    // don't send the optional ReplyTo headers if we don't need to either
    ei.setProperty("ws-addressing.write.optional.replyto", Boolean.FALSE);
}
Also used : AbstractSoapInterceptor(org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) HashMap(java.util.HashMap) Fault(org.apache.cxf.interceptor.Fault) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class RPCInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message)) {
        LOG.fine("RPCInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    if (!StaxUtils.toNextElement(xmlReader)) {
        message.setContent(Exception.class, new RuntimeException("There must be a method name element."));
    }
    String opName = xmlReader.getLocalName();
    if (isRequestor(message) && opName.endsWith("Response")) {
        opName = opName.substring(0, opName.length() - 8);
    }
    final BindingOperationInfo operation;
    if (message.getExchange().getBindingOperationInfo() == null) {
        operation = getOperation(message, new QName(xmlReader.getNamespaceURI(), opName));
        if (operation == null) {
            // it's doc-lit-bare
            new BareInInterceptor().handleMessage(message);
            return;
        }
        setMessage(message, operation);
    } else {
        operation = message.getExchange().getBindingOperationInfo();
        if (!operation.getName().getLocalPart().equals(opName)) {
            String sa = (String) message.get(SoapBindingConstants.SOAP_ACTION);
            throw new Fault("SOAP_ACTION_MISMATCH_OP", LOG, null, sa, opName);
        }
    }
    MessageInfo msg;
    DataReader<XMLStreamReader> dr = getDataReader(message, XMLStreamReader.class);
    if (!isRequestor(message)) {
        msg = operation.getOperationInfo().getInput();
    } else {
        msg = operation.getOperationInfo().getOutput();
    }
    message.put(MessageInfo.class, msg);
    MessageContentsList parameters = new MessageContentsList();
    StaxUtils.nextEvent(xmlReader);
    boolean hasNext = true;
    Iterator<MessagePartInfo> itr = msg.getMessageParts().iterator();
    while (itr.hasNext()) {
        MessagePartInfo part = itr.next();
        if (hasNext) {
            hasNext = StaxUtils.toNextElement(xmlReader);
        }
        if (hasNext) {
            QName qn = xmlReader.getName();
            if (qn.equals(SOAP12_RESULT)) {
                // just ignore this.   The parts should work correctly.
                try {
                    while (xmlReader.getEventType() != XMLStreamConstants.END_ELEMENT) {
                        xmlReader.next();
                    }
                    xmlReader.next();
                } catch (XMLStreamException e) {
                // ignore
                }
                StaxUtils.toNextElement(xmlReader);
                qn = xmlReader.getName();
            }
            // WSI-BP states that RPC/Lit part accessors should be completely unqualified
            // However, older toolkits (Axis 1.x) are qualifying them.   We'll go
            // ahead and just match on the localpart.   The RPCOutInterceptor
            // will always generate WSI-BP compliant messages so it's unknown if
            // the non-WSI-BP toolkits will be able to understand the CXF
            // generated messages if they are expecting it to be qualified.
            Iterator<MessagePartInfo> partItr = msg.getMessageParts().iterator();
            while (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart()) && partItr.hasNext()) {
                part = partItr.next();
            }
            // only check the localpart as explained above
            if (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart())) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_RPC_LIT_PART", LOG, qn));
            }
            try {
                parameters.put(part, dr.read(part, xmlReader));
            } catch (Fault f) {
                if (!isRequestor(message)) {
                    f.setFaultCode(Fault.FAULT_CODE_CLIENT);
                }
                throw f;
            }
        }
    }
    message.setContent(List.class, parameters);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor)

Example 55 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class Soap11FaultOutInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    Fault f = (Fault) message.getContent(Exception.class);
    message.put(org.apache.cxf.message.Message.RESPONSE_CODE, f.getStatusCode());
    if (message.getVersion() == Soap11.getInstance()) {
        message.getInterceptorChain().add(Soap11FaultOutInterceptorInternal.INSTANCE);
    } else {
        message.getInterceptorChain().add(Soap12FaultOutInterceptorInternal.INSTANCE);
    }
}
Also used : Fault(org.apache.cxf.interceptor.Fault) SoapFault(org.apache.cxf.binding.soap.SoapFault)

Aggregations

Fault (org.apache.cxf.interceptor.Fault)283 IOException (java.io.IOException)74 QName (javax.xml.namespace.QName)56 Message (org.apache.cxf.message.Message)52 XMLStreamException (javax.xml.stream.XMLStreamException)50 Element (org.w3c.dom.Element)42 Message (org.apache.cxf.common.i18n.Message)34 Exchange (org.apache.cxf.message.Exchange)30 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)30 SOAPException (javax.xml.soap.SOAPException)28 InputStream (java.io.InputStream)27 ArrayList (java.util.ArrayList)27 XMLStreamReader (javax.xml.stream.XMLStreamReader)26 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)26 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)25 Test (org.junit.Test)24 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)23 List (java.util.List)21 SOAPMessage (javax.xml.soap.SOAPMessage)21 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)21