9 Replies Latest reply on May 27, 2010 12:26 AM by davsclaus

    custom TypeConverter

    fsalceda

      Hi, Im implementing a RecipientList that returns targets that are called depending on some data I would get from message body in following way:

       

           public List getTargets(

                     @PielValidationXPath("//xsd:pielInputInfo") PielInputInfo pielInputInfo,

                     @Body String body,

                     Exchange exchange) {

                              ....

                              }

       

      The parameter conversion to "PielInputInfo" throws a exception because it can't found an appropiate TypeConverter from "?" to PielInputInfo.

       

      Now I'm trying to implement a custom type converter to append it to default converters and solve it. Could you give me some advice how to do that? An example related with my scenario would be helpful.

       

      Thanks.

        • 1. Re: custom TypeConverter
          davsclaus

          See here

          http://camel.apache.org/type-converter.html

           

          Or chapter 3 in the Camel in Action book which discusses and shows how to write custom type converters. The source code for the book also shows how to do it.

          http://www.manning.com/ibsen

          • 2. Re: custom TypeConverter
            fsalceda

            I wrote my TypeConverter following the example "PurchaseOrder" in camel in action source and also added the TypeConverter file with the package name of my TypeConverter. Now I would like to packege it as an osgi bundle and install it in Fuse 4.2 to be available for my other bundles when conversion is needed. Should I install it as a features in Fuse? How can I do that?

            • 3. Re: custom TypeConverter
              davsclaus

              How to use OSGi with FUSE ESB is documented here:

              http://fusesource.com/docs/esb/4.2/deploy_osgi/index.html

               

              No a feature is not needed. A feature is a xml file which is like a super bundle which just tells Fuse ESB which other bundles belongs in this group. And then it can install all those bundles together.

               

              You most likely one have one .jar file then you just have to include the OSGi metadata in the MANIFEST.MF file. Then you should be able to deploy the .jar in the FUSE ESB container.

              • 4. Re: custom TypeConverter
                fsalceda

                I added my TypeConverter jar as an embeded-dependency to my osgi-bundle project to test the converter but I get...

                ...

                Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList to the required type: com.andago.piel.types.PielInputInfo with value com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList@1ffaab5

                 

                I append my TypeConverter and my RecicpientList method that causes the exception

                 

                Thx.

                • 5. Re: custom TypeConverter
                  fsalceda

                  Ok, then I can install my custom TypeConverter as a normal osgi-bundle and it will be available when a type conversion happens in other bundles, dont it?

                   

                  Thx.

                  • 6. Re: custom TypeConverter
                    njiang

                    Can you add a converter which can turn a NodeList into the PielInputInfo?

                     

                    I just found a bytes to PielInputInfo method in your custom TypeConverter.

                     

                    Willem

                    • 7. Re: custom TypeConverter
                      fsalceda

                      Yes I can, which type of NodeList is it? Could you help me with a method example with the exact type of NodeList? Is it a org.w3c.dom.NodeList? Cannot find com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList type.

                       

                      Edited by: fsalceda on May 19, 2010 10:18 AM

                      • 8. Re: custom TypeConverter
                        fsalceda

                        I would appreciate any help with type conversion from NodeList?? to extract elements to a java bean.

                         

                        Thx.

                        • 9. Re: custom TypeConverter
                          davsclaus

                          The XML API in JDK is terrible to work with.

                           

                          You may just have to google a bit to find some code snippets for how to work with NodeList.

                           

                          If you only need a couple of data from it you may be able to use XPath to extract the data.