Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-6188

CXF cosumer should set Exchange's charset name, if content type provides one

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.10.4
    • 2.11.0
    • camel-cxf
    • None
    • Novice

    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());
                  }
              }
          }
      }
      

      Attachments

        Activity

          People

            njiang Willem Jiang
            fhoeben Fried Hoeben
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: