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

ManagedCamelContext.dumpRestsAsXml can fail if default charset is not utf-8

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.18.4
    • Fix Version/s: 2.18.5, 2.19.3, 2.20.0
    • Component/s: camel-core, jmx
    • Labels:
    • Environment:

      Windows, default charset is not UTF-8

    • Estimated Complexity:
      Novice

      Description

      I am trying to access the rest definitions using the swagger servlet.
      My operation description is in Danish and includes the character "æ".

      Thus, the xml string generated in line 371 of org.apache.camel.management.mbean.ManagedCamelContext.dumpRestsAsXml
      contains the character "æ".

      In line 376-377, wh have

             InputStream is = new ByteArrayInputStream(xml.getBytes());
              Document dom = XmlLineNumberParser.parseXml(is, new ...)
      

      The call to xml.getBytes() uses the default encoding (CP-1252 in my case), which will encode æ as a single byte. The xml parser expects UTF-8 (since the xml starts with an xml declaration specifying encoding="UTF-8").
      Therefore, it fails with "Invalid byte 2 of 3-byte UTF-8 sequence".

      The fix is simple - change xml.getBytes() to xml.getBytes("UTF-8");

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              niels@harremoes.dk Niels Ull Harremoes

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Issue deployment