public void populateExchangeFromCxfRsRequest( org.apache.cxf.message.Exchange cxfExchange, Exchange camelExchange, Method method, Object[] paramArray) { Message camelMessage = camelExchange.getIn(); // Copy the CXF message header into the Camel inMessage org.apache.cxf.message.Message cxfMessage = cxfExchange.getInMessage(); // TODO use header filter strategy and cxfToCamelHeaderMap CxfUtils.copyHttpHeadersFromCxfToCamel(cxfMessage, camelMessage); // copy the protocol header copyProtocolHeader(cxfMessage, camelMessage, camelMessage.getExchange()); camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, method.getReturnType()); camelMessage.setHeader( CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, method.getGenericReturnType()); copyOperationResourceInfoStack(cxfMessage, camelMessage); camelMessage.setHeader(CxfConstants.OPERATION_NAME, method.getName()); camelMessage.setHeader(CxfConstants.CAMEL_CXF_MESSAGE, cxfMessage); camelMessage.setBody(new MessageContentsList(paramArray)); }
/** * @param cxfMessage * @param camelMessage * @param exchange provides context for filtering */ protected void propagateHeadersFromCxfToCamel( Message cxfMessage, org.apache.camel.Message camelMessage, Exchange exchange) { Map<String, List<String>> cxfHeaders = CastUtils.cast((Map<?, ?>) cxfMessage.get(Message.PROTOCOL_HEADERS)); Map<String, Object> camelHeaders = camelMessage.getHeaders(); camelHeaders.put(CxfConstants.CAMEL_CXF_MESSAGE, cxfMessage); // Copy the http header to CAMEL as we do in camel-cxfrs CxfUtils.copyHttpHeadersFromCxfToCamel(cxfMessage, camelMessage); if (cxfHeaders != null) { for (Map.Entry<String, List<String>> entry : cxfHeaders.entrySet()) { if (!headerFilterStrategy.applyFilterToExternalHeaders( entry.getKey(), entry.getValue(), exchange)) { // We need to filter the content type with multi-part, // as the multi-part stream is already consumed by AttachmentInInterceptor, // it will cause some trouble when route this message to another CXF endpoint. if ("Content-Type".compareToIgnoreCase(entry.getKey()) == 0 && entry.getValue().get(0) != null && entry.getValue().get(0).startsWith("multipart/related")) { // We need to keep the Content-Type if the data format is RAW message DataFormat dataFormat = exchange.getProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.class); if (dataFormat.equals(DataFormat.RAW)) { camelHeaders.put(entry.getKey(), getContentTypeString(entry.getValue())); } else { String contentType = replaceMultiPartContentType(entry.getValue().get(0)); LOG.trace("Find the multi-part Conent-Type, and replace it with {}", contentType); camelHeaders.put(entry.getKey(), contentType); } } else { LOG.trace( "Populate header from CXF header={} value={}", entry.getKey(), entry.getValue()); List<String> values = entry.getValue(); Object evalue; if (values.size() > 1) { if (exchange.getProperty( CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.FALSE, Boolean.class)) { StringBuilder sb = new StringBuilder(); for (Iterator<String> it = values.iterator(); it.hasNext(); ) { sb.append(it.next()); if (it.hasNext()) { sb.append(',').append(' '); } } evalue = sb.toString(); } else { evalue = values; } } else { evalue = values.get(0); } camelHeaders.put(entry.getKey(), evalue); } } } } // propagate SOAP/protocol header list String key = Header.HEADER_LIST; Object value = cxfMessage.get(key); if (value != null) { if (!headerFilterStrategy.applyFilterToExternalHeaders(key, value, exchange)) { camelHeaders.put(key, value); LOG.trace("Populate header from CXF header={} value={}", key, value); } else { ((List<?>) value).clear(); } } // propagate the SOAPAction header String soapAction = (String) camelHeaders.get(SoapBindingConstants.SOAP_ACTION); // Remove SOAPAction from the protocol header, as it will not be overrided if (ObjectHelper.isEmpty(soapAction) || "\"\"".equals(soapAction)) { camelHeaders.remove(SoapBindingConstants.SOAP_ACTION); } soapAction = (String) cxfMessage.get(SoapBindingConstants.SOAP_ACTION); if (soapAction != null) { if (!headerFilterStrategy.applyFilterToExternalHeaders( SoapBindingConstants.SOAP_ACTION, soapAction, exchange)) { camelHeaders.put(SoapBindingConstants.SOAP_ACTION, soapAction); LOG.trace( "Populate header from CXF header={} value={}", SoapBindingConstants.SOAP_ACTION, soapAction); } } }