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

Claus Ibsen resolved CAMEL-12424.
---------------------------------
    Resolution: Fixed

Thanks for reporting and providing the suggested patch

> HTTPHelper.setCharsetFromContentType can't properly extract the charset if it 
> isn't the last parameter
> ------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-12424
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12424
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-http-common
>    Affects Versions: 2.19.2
>         Environment: Apache Camel 2.19.2
> Karaf 4.1.2
> JDK 1.8.0_161
>            Reporter: Fabricio Guimarães Pellegrini
>            Assignee: Claus Ibsen
>            Priority: Major
>              Labels: easyfix
>             Fix For: 2.20.4, 2.21.1, 2.22.0
>
>
> When our application recieves the Content-Type: 
> application/json;charset=utf-8;profile="http://my.company.profile.errorSchema.4.json#";,
>  the HTTPHelper sets the wrong value for the Exchange.CHARSET_NAME in the 
> Exchange.
> {quote} @SuppressWarnings("deprecation")
>      public static void setCharsetFromContentType(String contentType, 
> Exchange exchange) {
>          if (contentType != null) {
>              // find the charset and set it to the Exchange
>              int index = contentType.indexOf("charset=");
>              if (index > 0) {
>                  String charset = contentType.substring(index + 8); //HERE IS 
> THE PROBLEM                 exchange.setProperty(Exchange.CHARSET_NAME, 
> IOConverter.normalizeCharset(charset));             }
>         }
>      }
> {quote}
> Because of that, when the HTTPProducer tries to load the body we get the 
> following error:
> {quote}Exception: Error during type conversion from type: java.lang.String to 
> the required type: java.lang.String with value [Body is instance of 
> java.io.InputStream] due java.io.UnsupportedEncodingException: 
> utf-8;profile="http://my.company.profile.errorSchema.4.json#
>  org.apache.camel.TypeConversionException: Error during type conversion from 
> type: java.lang.String to the required type: java.lang.String with value 
> [Body is instance of java.io.InputStream] due 
> java.io.UnsupportedEncodingException: 
> utf-8;profile="http://my.company.profile.errorSchema.4.json#
>          at 
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:629)
>  [178:org.apache.camel.camel-core:2.19.2]
>          at 
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:150)
>  [178:org.apache.camel.camel-core:2.19.2]
>          at 
> org.apache.camel.core.osgi.OsgiTypeConverter.convertTo(OsgiTypeConverter.java:120)
>  [176:org.apache.camel.camel-blueprint:2.19.2]
>          at 
> org.apache.camel.component.http4.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:305)
>  [182:org.apache.camel.camel-http4:2.19.2]
>          at 
> org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:207) 
> [182:org.apache.camel.camel-http4:2.19.2]
> Caused by: org.apache.camel.RuntimeCamelException: 
> java.io.UnsupportedEncodingException: 
> utf-8;profile="http://my.company.profile.errorSchema.4.json#
>          at 
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1774)
>  ~[?:?]
>          at 
> org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:1355) ~[?:?]
>          at 
> org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMethodTypeConverter.java:59)
>  ~[?:?]
>          at 
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.doConvertTo(BaseTypeConverterRegistry.java:306)
>  ~[?:?]
>          at 
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:133)
>  ~[?:?]
>          ... 70 more
>  Caused by: java.io.UnsupportedEncodingException: 
> utf-8;profile="http://my.company.profile.errorSchema.4.json#
>          at 
> sun.nio.cs.StreamDecoder.forInputStreamReader(StreamDecoder.java:71) ~[?:?]
>          at java.io.InputStreamReader.<init>(InputStreamReader.java:100) 
> ~[?:?]
>          at 
> org.apache.camel.converter.IOConverter.toReader(IOConverter.java:179) ~[?:?]
>          at 
> org.apache.camel.converter.IOConverter.toString(IOConverter.java:364) ~[?:?]
>          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
>          at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:?]
>          at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:?]
>          at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
>          at 
> org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:1351) ~[?:?]
>          at 
> org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMethodTypeConverter.java:59)
>  ~[?:?]
>          at 
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.doConvertTo(BaseTypeConverterRegistry.java:306)
>  ~[?:?]
>          at 
> org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:133)
>  ~[?:?]
> {quote}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to