[ 
https://issues.apache.org/jira/browse/CAMEL-6187?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-6187:
-------------------------------

         Priority: Minor  (was: Major)
    Fix Version/s: 2.12.0
                   2.11.2
         Assignee: Claus Ibsen
    
> http4 component should default to charset based on content type
> ---------------------------------------------------------------
>
>                 Key: CAMEL-6187
>                 URL: https://issues.apache.org/jira/browse/CAMEL-6187
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-http
>    Affects Versions: 2.10.4
>            Reporter: Fried Hoeben
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 2.11.2, 2.12.0
>
>
> HttpProducer determines the charset of an outgoing StringEntity based on an 
> Exchange property (Exchange.CHARSET_NAME), using null if that property is not 
> set. It also sets the content-type based on the content-type of the camel 
> message (this may also contain a character encoding). 
> If these two don't match the receiver of the http request will probably not 
> be able to parse the message. 
> It would be better if the charset of the StringEntity would by default match 
> the charset specified in the content-type. Matching these two is done when 
> receiving response messages (in HttpProducer.extractResponseBody())...
> Suggested fix (in HttpProducer.createRequestEntity()), you could of course 
> also do something like 
> org.apache.camel.component.http4.helper.HttpHelper.setCharsetFromContentType()
>  but my approach uses org.apache.http.entity.ContentType and 
> java.nio.charset.Charset instead of trying to determine the correct charset 
> itself):
> {code}
> // be a bit careful with String as any type can most likely be converted to 
> String
> // so we only do an instanceof check and accept String if the body is really 
> a String
> // do not fallback to use the default charset as it can influence the request
> // (for example application/x-www-form-urlencoded forms being sent)
> String charset = IOHelper.getCharsetName(exchange, false);
> if (charset == null && contentType != null)
> {
>     ContentType ct = ContentType.parse(contentType);
>     if (ct != null) {
>         Charset cs = ct.getCharset();
>         if (cs != null)
>         {
>             charset = cs.name();
>         }
>     }
> }
> StringEntity entity = new StringEntity((String) data, charset);
> entity.setContentType(contentType);
> answer = entity;
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to