Description
The CXF consumer copies the content-type http header to the camel exchange. This header may indicate the character set used in the request (for instance "text/xml;charset=UTF-8"), and if so this should be made available in the normal place for Camel (i.e. a property in the exchange called 'CamelCharsetName').
This may (of course) be done in each route by a separate processor, but it simplifies life if this is done by default. (org.apache.camel.component.cxf.DefaultCxfBinding.populateExchangeFromCxfRequest() seems the logical place)
Sample processor that performs this job.
import java.nio.charset.Charset; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.util.ExchangeHelper; import org.apache.http.entity.ContentType; /** * Processor to ensure the exchange's charset name property is in sync with * its content type. */ public class CharsetProcessor implements Processor { @Override public void process(Exchange exchange) throws Exception { String contentTypeHeader = ExchangeHelper.getContentType(exchange); if (contentTypeHeader != null) { ContentType contentType = ContentType.parse(contentTypeHeader); if (contentType != null) { Charset charset = contentType.getCharset(); exchange.setProperty(Exchange.CHARSET_NAME, charset.name()); } } } }