Search in sources :

Example 46 with MessageContentsList

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

the class DefaultCxfBinding method getResponsePayloadList.

// Non public methods
// -------------------------------------------------------------------------
protected MessageContentsList getResponsePayloadList(org.apache.cxf.message.Exchange exchange, List<Source> elements) {
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
        exchange.put(BindingOperationInfo.class, boi);
    }
    MessageContentsList answer = new MessageContentsList();
    int i = 0;
    if (boi.getOutput() != null) {
        for (MessagePartInfo partInfo : boi.getOutput().getMessageParts()) {
            if (elements != null && elements.size() > i) {
                answer.put(partInfo, elements.get(i++));
            }
        }
    }
    return answer;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 47 with MessageContentsList

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

the class PersonProcessor method process.

@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
    LOG.info("processing exchange in camel");
    BindingOperationInfo boi = (BindingOperationInfo) exchange.getProperty(BindingOperationInfo.class.getName());
    if (boi != null) {
        LOG.info("boi.isUnwrapped" + boi.isUnwrapped());
    }
    // Get the parameters list which element is the holder.
    MessageContentsList msgList = (MessageContentsList) exchange.getIn().getBody();
    Holder<String> personId = (Holder<String>) msgList.get(0);
    Holder<String> ssn = (Holder<String>) msgList.get(1);
    Holder<String> name = (Holder<String>) msgList.get(2);
    if (personId.value == null || personId.value.length() == 0) {
        LOG.info("person id 123, so throwing exception");
        // Try to throw out the soap fault message
        org.apache.camel.wsdl_first.types.UnknownPersonFault personFault = new org.apache.camel.wsdl_first.types.UnknownPersonFault();
        personFault.setPersonId("");
        org.apache.camel.wsdl_first.UnknownPersonFault fault = new org.apache.camel.wsdl_first.UnknownPersonFault("Get the null value of person name", personFault);
        // Since camel has its own exception handler framework, we can't throw the exception to trigger it
        // We just set the fault message in the exchange for camel-cxf component handling and return
        exchange.getOut().setFault(true);
        exchange.getOut().setBody(fault);
        return;
    }
    name.value = "Bonjour";
    ssn.value = "123";
    LOG.info("setting Bonjour as the response");
    // Set the response message, first element is the return value of the operation,
    // the others are the holders of method parameters
    exchange.getOut().setBody(new Object[] { null, personId, ssn, name });
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) Holder(javax.xml.ws.Holder)

Example 48 with MessageContentsList

use of org.apache.cxf.message.MessageContentsList in project steve by RWTH-i5-IDSG.

the class FromAddressInterceptor method getChargeBoxId.

private String getChargeBoxId(Message message) {
    MessageContentsList lst = MessageContentsList.getContentsList(message);
    if (lst == null) {
        return null;
    }
    MessageInfo mi = (MessageInfo) message.get("org.apache.cxf.service.model.MessageInfo");
    for (MessagePartInfo mpi : mi.getMessageParts()) {
        if (CHARGEBOX_ID_HEADER.equals(mpi.getName().getLocalPart())) {
            return (String) lst.get(mpi);
        }
    }
    return null;
}
Also used : MessageContentsList(org.apache.cxf.message.MessageContentsList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 49 with MessageContentsList

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

the class BodyWriter method handleMessage.

@Override
public void handleMessage(Message outMessage) throws Fault {
    MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
    if (objs == null || objs.size() == 0) {
        return;
    }
    OutputStream os = outMessage.getContent(OutputStream.class);
    if (os == null) {
        XMLStreamWriter writer = outMessage.getContent(XMLStreamWriter.class);
        if (writer == null) {
            return;
        }
    }
    Object body = objs.get(0);
    Type t = outMessage.get(Type.class);
    doWriteBody(outMessage, body, t);
}
Also used : MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) MessageContentsList(org.apache.cxf.message.MessageContentsList) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStream(java.io.OutputStream)

Example 50 with MessageContentsList

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

the class CustomHandler method handleMessage.

@Override
public void handleMessage(final Message message) throws Fault {
    if (isResponseAlreadyHandled(message)) {
        return;
    }
    final MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }
    final Object responseObj = objs.get(0);
    if (Response.class.isInstance(responseObj)) {
        final Response response = Response.class.cast(responseObj);
        if (is404(message, response)) {
            switchResponse(message);
        }
    } else {
        final Object exchangeStatus = message.getExchange().get(Message.RESPONSE_CODE);
        final int status = exchangeStatus != null ? Integer.class.cast(exchangeStatus) : HttpsURLConnection.HTTP_OK;
        if (status == HttpsURLConnection.HTTP_NOT_FOUND) {
            switchResponse(message);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) MessageContentsList(org.apache.cxf.message.MessageContentsList)

Aggregations

MessageContentsList (org.apache.cxf.message.MessageContentsList)69 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)24 Exchange (org.apache.cxf.message.Exchange)23 Message (org.apache.cxf.message.Message)22 Fault (org.apache.cxf.interceptor.Fault)19 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)18 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Endpoint (org.apache.cxf.endpoint.Endpoint)11 MessageImpl (org.apache.cxf.message.MessageImpl)11 Response (javax.ws.rs.core.Response)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)10 Method (java.lang.reflect.Method)9 OperationInfo (org.apache.cxf.service.model.OperationInfo)9 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