Search in sources :

Example 6 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class StaxDataBindingInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("StaxDataBindingInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    DataReader<XMLStreamReader> dr = getDataReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    // operation anymore, just return
    if (!StaxUtils.toNextElement(xmlReader) && bop != null) {
        // body may be empty for partial response to decoupled request
        return;
    }
    if (bop == null) {
        Endpoint ep = exchange.getEndpoint();
        bop = ep.getBinding().getBindingInfo().getOperations().iterator().next();
    }
    message.getExchange().put(BindingOperationInfo.class, bop);
    if (isRequestor(message)) {
        parameters.put(bop.getOutput().getMessageParts().get(0), dr.read(xmlReader));
    } else {
        parameters.put(bop.getInput().getMessageParts().get(0), dr.read(xmlReader));
    }
    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) Endpoint(org.apache.cxf.endpoint.Endpoint) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader)

Example 7 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class ClientImpl method setParameters.

protected void setParameters(Object[] params, Message message) {
    MessageContentsList contents = new MessageContentsList(params);
    message.setContent(List.class, contents);
}
Also used : MessageContentsList(org.apache.cxf.message.MessageContentsList)

Example 8 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class AbstractInvoker method invoke.

public Object invoke(Exchange exchange, Object o) {
    final Object serviceObject = getServiceObject(exchange);
    try {
        BindingOperationInfo bop = exchange.getBindingOperationInfo();
        MethodDispatcher md = (MethodDispatcher) exchange.getService().get(MethodDispatcher.class.getName());
        Method m = bop == null ? null : md.getMethod(bop);
        if (m == null && bop == null) {
            LOG.severe(new Message("MISSING_BINDING_OPERATION", LOG).toString());
            throw new Fault(new Message("EXCEPTION_INVOKING_OBJECT", LOG, "No binding operation info", "unknown method", "unknown"));
        }
        List<Object> params = null;
        if (o instanceof List) {
            params = CastUtils.cast((List<?>) o);
        } else if (o != null) {
            params = new MessageContentsList(o);
        }
        m = adjustMethodAndParams(m, exchange, params, serviceObject.getClass());
        // Method m = (Method)bop.getOperationInfo().getProperty(Method.class.getName());
        m = matchMethod(m, serviceObject);
        return invoke(exchange, serviceObject, m, params);
    } finally {
        releaseServiceObject(exchange, serviceObject);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) Fault(org.apache.cxf.interceptor.Fault) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) Method(java.lang.reflect.Method)

Example 9 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList 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);
    BindingOperationInfo operation = null;
    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);
    }
    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();
    }
    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 10 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project cxf by apache.

the class RPCOutInterceptor method handleMessage.

public void handleMessage(Message message) {
    XMLStreamWriter origXmlWriter = null;
    try {
        NSStack nsStack = new NSStack();
        nsStack.push();
        BindingOperationInfo operation = message.getExchange().getBindingOperationInfo();
        assert operation.getName() != null;
        XMLStreamWriter xmlWriter = getXMLStreamWriter(message);
        CachingXmlEventWriter cache = null;
        // need to cache the events in case validation fails or buffering is enabled
        if (shouldBuffer(message)) {
            origXmlWriter = xmlWriter;
            cache = new CachingXmlEventWriter();
            try {
                cache.setNamespaceContext(xmlWriter.getNamespaceContext());
            } catch (XMLStreamException e) {
            // ignorable, will just get extra namespace decls
            }
            message.setContent(XMLStreamWriter.class, cache);
            xmlWriter = cache;
        }
        List<MessagePartInfo> parts = null;
        boolean output = false;
        if (!isRequestor(message)) {
            if (operation.getOutput() == null) {
                return;
            }
            parts = operation.getOutput().getMessageParts();
            output = true;
        } else {
            parts = operation.getInput().getMessageParts();
            output = false;
        }
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        if (objs == null) {
            addOperationNode(nsStack, message, xmlWriter, output, operation);
            xmlWriter.writeEndElement();
            return;
        }
        for (MessagePartInfo part : parts) {
            if (objs.hasValue(part)) {
                Object o = objs.get(part);
                if (o == null) {
                    // WSI-BP R2211 - RPC/Lit parts are not allowed to be xsi:nil
                    throw new Fault(new org.apache.cxf.common.i18n.Message("BP_2211_RPCLIT_CANNOT_BE_NULL", LOG, part.getConcreteName()));
                }
            // WSI-BP R2737  -RPC/LIG part name space is empty
            // part.setConcreteName(new QName("", part.getConcreteName().getLocalPart()));
            }
        }
        addOperationNode(nsStack, message, xmlWriter, output, operation);
        writeParts(message, message.getExchange(), operation, objs, parts);
        // Finishing the writing.
        xmlWriter.writeEndElement();
        if (cache != null) {
            try {
                for (XMLEvent event : cache.getEvents()) {
                    StaxUtils.writeEvent(event, origXmlWriter);
                }
            } catch (XMLStreamException e) {
                throw new Fault(e);
            }
        }
    } catch (XMLStreamException e) {
        throw new Fault(e);
    } finally {
        if (origXmlWriter != null) {
            message.setContent(XMLStreamWriter.class, origXmlWriter);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) CachingXmlEventWriter(org.apache.cxf.staxutils.CachingXmlEventWriter) NSStack(org.apache.cxf.helpers.NSStack) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XMLEvent(javax.xml.stream.events.XMLEvent)

Aggregations

MessageContentsList (org.apache.cxf.message.MessageContentsList)63 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)24 Exchange (org.apache.cxf.message.Exchange)22 Fault (org.apache.cxf.interceptor.Fault)19 Message (org.apache.cxf.message.Message)19 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)18 ArrayList (java.util.ArrayList)13 List (java.util.List)13 MessageImpl (org.apache.cxf.message.MessageImpl)11 Endpoint (org.apache.cxf.endpoint.Endpoint)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)10 Method (java.lang.reflect.Method)9 OperationInfo (org.apache.cxf.service.model.OperationInfo)9 Response (javax.ws.rs.core.Response)8 XMLStreamException (javax.xml.stream.XMLStreamException)8 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)8 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)8 MessageInfo (org.apache.cxf.service.model.MessageInfo)8 Test (org.junit.Test)8 Service (org.apache.cxf.service.Service)7