Search in sources :

Example 1 with ReaderInputStream

use of org.apache.camel.component.cxf.util.ReaderInputStream in project camel by apache.

the class DefaultCxfBinding method getContentFromCxf.

protected static Object getContentFromCxf(Message message, DataFormat dataFormat, String encoding) {
    Set<Class<?>> contentFormats = message.getContentFormats();
    Object answer = null;
    if (contentFormats != null) {
        if (LOG.isTraceEnabled()) {
            for (Class<?> contentFormat : contentFormats) {
                LOG.trace("Content format={} value={}", contentFormat, message.getContent(contentFormat));
            }
        }
        if (dataFormat == DataFormat.POJO) {
            answer = message.getContent(List.class);
            if (answer == null) {
                answer = message.getContent(Object.class);
                if (answer != null) {
                    answer = new MessageContentsList(answer);
                }
            }
        } else if (dataFormat == DataFormat.PAYLOAD) {
            List<SoapHeader> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
            Map<String, String> nsMap = new HashMap<String, String>();
            answer = new CxfPayload<SoapHeader>(headers, getPayloadBodyElements(message, nsMap), nsMap);
        } else if (dataFormat.dealias() == DataFormat.RAW) {
            answer = message.getContent(InputStream.class);
            if (answer == null) {
                answer = message.getContent(Reader.class);
                if (answer != null) {
                    if (encoding == null) {
                        encoding = "UTF-8";
                    }
                    LOG.trace("file encoding is = {}", encoding);
                    answer = new ReaderInputStream((Reader) answer, Charset.forName(encoding));
                }
            }
        } else if (dataFormat.dealias() == DataFormat.CXF_MESSAGE && message.getContent(List.class) != null) {
            // CAMEL-6404 added check point of message content
            // The message content of list could be null if there is a fault message is received
            answer = message.getContent(List.class).get(0);
        }
        LOG.trace("Extracted body from CXF message = {}", answer);
    }
    return answer;
}
Also used : MessageContentsList(org.apache.cxf.message.MessageContentsList) ReaderInputStream(org.apache.camel.component.cxf.util.ReaderInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) ReaderInputStream(org.apache.camel.component.cxf.util.ReaderInputStream) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) TreeMap(java.util.TreeMap)

Aggregations

InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ReaderInputStream (org.apache.camel.component.cxf.util.ReaderInputStream)1 MessageContentsList (org.apache.cxf.message.MessageContentsList)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1