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

HTTPHelper.setCharsetFromContentType can't properly extract the charset if it isn't the last parameter

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.19.2
    • Fix Version/s: 2.20.4, 2.21.1, 2.22.0
    • Component/s: camel-http-common
    • Labels:
    • Environment:

      Apache Camel 2.19.2

      Karaf 4.1.2

      JDK 1.8.0_161

    • Estimated Complexity:
      Novice

      Description

      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.

       @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)

      Unknown macro: {                 String charset = contentType.substring(index + 8); //HERE IS THE PROBLEM                 exchange.setProperty(Exchange.CHARSET_NAME, IOConverter.normalizeCharset(charset));             }

              }
          }

      Because of that, when the HTTPProducer tries to load the body we get the following error:

      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) ~[?:?]

       

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              fabricio.pellegrini Fabricio Guimarães Pellegrini
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: