Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-M1
    • Fix Version/s: 2.0-M2
    • Component/s: None
    • Labels:
      None

      Description

      When converting data from a binary form the convertBodyTo(String.class) function currently does not support changing the encoding. This should be added. Additionally it would be nice to have automatic encoding settings for xml files that contain a <?xml header with an encoding attribute.

      The issue happened for me when I tried to read from a FileEndpoint. I have debugged into the code and found that where the file is read there seems to be no support for encoding at all. But maybe I am wrong. I will search for the place in the code and post a link here.

      http://www.nabble.com/Convert-File-to-String-with-encoding-to23291163.html

        Activity

        Hide
        Christian Schneider added a comment -

        I have found the code that reads the file. It seems to be IOConverter.toString(File file) . As you can see there is no encoding mentioned. So I think this code will not work with the Exchange.CHARSET_NAME parameter. Btw. I have not yet found this constant.

        Show
        Christian Schneider added a comment - I have found the code that reads the file. It seems to be IOConverter.toString(File file) . As you can see there is no encoding mentioned. So I think this code will not work with the Exchange.CHARSET_NAME parameter. Btw. I have not yet found this constant.
        Hide
        Claus Ibsen added a comment -

        That constant is in Camel 2.0. In Camel 1.x its somewhere else.

        You should really use org.w3c.Document as the type if you want to read an XML file. It will leverage the Java XML API to read and understand the encoding option in the XML files.
        Then afterwards you can get it as a String.

        Or the javax.xml.transform.stream.StreamSource should also be doable.

        Camel cannot really know its a XML file, unless we add some convention that if the file name extension is xml it should use the XML converters.

        Show
        Claus Ibsen added a comment - That constant is in Camel 2.0. In Camel 1.x its somewhere else. You should really use org.w3c.Document as the type if you want to read an XML file. It will leverage the Java XML API to read and understand the encoding option in the XML files. Then afterwards you can get it as a String. Or the javax.xml.transform.stream.StreamSource should also be doable. Camel cannot really know its a XML file, unless we add some convention that if the file name extension is xml it should use the XML converters.
        Hide
        Christian Schneider added a comment -

        Hi Claus,

        I have just tested with org.w3c.dom.Document. This seems to work fine. So we have a solution for my problem.
        But in any case this should be added to documentation. I did not know that I can convert to Document.

        Is there any page already for the convertBodyTo ? I did not find one. It would be quite nice to have some examples for conversions. Perhaps there could be one page per dsl method. Are there any plans to build this?

        Show
        Christian Schneider added a comment - Hi Claus, I have just tested with org.w3c.dom.Document. This seems to work fine. So we have a solution for my problem. But in any case this should be added to documentation. I did not know that I can convert to Document. Is there any page already for the convertBodyTo ? I did not find one. It would be quite nice to have some examples for conversions. Perhaps there could be one page per dsl method. Are there any plans to build this?
        Hide
        Claus Ibsen added a comment -

        Hi Christian

        Camel have 150+ type converters in the distribution. The new Camel web console have a web page that lists them all.
        And I think there is a maven tool that could generate a list of converters as well.

        But the rule of thumb is that you should just try to convert to the type you want and Camel will lookup a suitable type convert if any exsits.
        If not you get an exception.

        The basic converters for String, byte[], streams, XML should be there. There might be some odd combinations missing such as a org.w3c.Document to byte[] or the likes.

        Keeping documentation in the wiki is time consuming and it would be much better if we get a tool to be able to slurp the javadoc in the code, then we would be able to generate a full DSL list with documentation.

        As we love contributions, you can get karma to the wiki pages so you can edit and add it yourself.

        Show
        Claus Ibsen added a comment - Hi Christian Camel have 150+ type converters in the distribution. The new Camel web console have a web page that lists them all. And I think there is a maven tool that could generate a list of converters as well. But the rule of thumb is that you should just try to convert to the type you want and Camel will lookup a suitable type convert if any exsits. If not you get an exception. The basic converters for String, byte[], streams, XML should be there. There might be some odd combinations missing such as a org.w3c.Document to byte[] or the likes. Keeping documentation in the wiki is time consuming and it would be much better if we get a tool to be able to slurp the javadoc in the code, then we would be able to generate a full DSL list with documentation. As we love contributions, you can get karma to the wiki pages so you can edit and add it yourself.
        Hide
        Claus Ibsen added a comment -

        trunk: 771351
        1.x: 771353

        In 1.x I have fixed the bug in ObjectHelper.loadClass not being able to load byte[] class.

        Show
        Claus Ibsen added a comment - trunk: 771351 1.x: 771353 In 1.x I have fixed the bug in ObjectHelper.loadClass not being able to load byte[] class.

          People

          • Assignee:
            Claus Ibsen
            Reporter:
            Christian Schneider
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development