11 Replies Latest reply on May 14, 2010 2:40 PM by annasw

    Camel File Component - NoTypeConversionAvailableException

    annasw

      Hello,

      I am using Camel File Component. My code works fine from Eclipse but does not work from jar file. I am getting NoTypeConversionAvailableException when running my code from executable jar file.

       

      ERROR - Caused by: [org.apache.camel.InvalidPayloadException - No body available of type: java.lang.String but has value: GenericFile[myFileName] of type: org.apache.camel.component.file.GenericFile on: GenericFileMessage with file: GenericFile[myFileName]. Caused by: No type converter available to convert from type: org.apache.camel.component.file.GenericFile to the required type: java.lang.String with value GenericFile[myFileName]. Exchange[GenericFileMessage with file: GenericFile[myFileName]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.file.GenericFile to the required type: java.lang.String with value GenericFile[myFileName]]]

       

      Here is my route:

                 

       

      I am not sure whether any additional things I need to get File component working from a jar? Has anyone seeing this error before? Thank you very much.

       

      Thank you very much in advance,

      Anna

        • 1. Re: Camel File Component - NoTypeConversionAvailableException
          njiang

          Can I have a look at your class path ?

          Please make sure you are using camel-spring and not using camel-spring-osgi when you run your code from executable jar file.

          • 2. Re: Camel File Component - NoTypeConversionAvailableException
            annasw

            My classpath does not have camel-osgi.jar/camel-spring-osgi.jar

             

            Here are the jars on my classpath: lib/java/junit-3.8.1.jar, lib/java/log4j-1.2.9.jar, programs/eclipse/mysql-connector-java-5.1.6-bin.jar, programs/log4j/log4j.properties, programs/log4j/log4jproperties.jar, programs/spring-framework-2.5.5/dist/spring.jar, programs/spring-framework-2.5.5/lib/jakarta-commons/commons-logging.jar, programs/spring-framework-2.5.5/lib/log4j-1.2.15.jar, programs/eclipse/mysql-connector-java-5.1.6-bin.jar.

             

            Pom dependencies:

                  

             

            Thanks!

             

            Edited by: asilchenko on May 12, 2010 1:56 PM

            • 3. Re: Camel File Component - NoTypeConversionAvailableException
              davsclaus

              How do you exactly start your app as a jar file?

              • 4. Re: Camel File Component - NoTypeConversionAvailableException
                annasw

                java -jar target/myJar-1.0-SNAPSHOT.one-jar.jar

                I am using onejar-maven-plugin to generate jar. I have used this many times before to generate jar with dependencies. It always works fine but not when I am using Camel File Component.

                This morning I tried changing route to

                           

                 

                And got similar but little different error:

                ERROR - Caused by: [org.apache.camel.InvalidPayloadException - No body available of type: java.io.InputStream but has value: GenericFile[myFileName] of type: org.apache.camel.component.file.GenericFile on: GenericFileMessage with file: GenericFile[myFileName]. Caused by: No type converter available to convert from type: org.apache.camel.component.file.GenericFile to the required type: java.io.InputStream with value GenericFile[myFileName]. Exchange[GenericFileMessage with file: GenericFile[myFileName]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.file.GenericFile to the required type: java.io.InputStream with value GenericFile[myFileName]]]

                 

                Thank you very much for your time!

                 

                Edited by: asilchenko on May 12, 2010 3:57 PM

                 

                Edited by: asilchenko on May 12, 2010 3:58 PM

                 

                Edited by: asilchenko on May 12, 2010 4:00 PM

                • 5. Re: Camel File Component - NoTypeConversionAvailableException
                  davsclaus

                  Maybe that onejar maven tool do only put .class files in the one big JAR. You have to include files from META-INF as well.

                   

                  And I suspect it can't merge the META-INF .../TypeConverter file which tells Camel which converters it should find in this JAR.

                   

                  So start it in normal situations using a -cp and provide the classpath.

                   

                  Or if using maven, you can just use mvn camel:run

                  • 6. Re: Camel File Component - NoTypeConversionAvailableException
                    annasw

                    My project does not have META-INF directory or TypeConverter file. It works without it in Eclipse. Do I need to create META-INF directory in my project? I need to get Camel Component running from jar without maven.

                     

                    Thank you very much!

                     

                    Edited by: asilchenko on May 12, 2010 4:43 PM

                    • 7. Re: Camel File Component - NoTypeConversionAvailableException
                      davsclaus

                      Dont mess with the .jars.

                       

                      Just start it using a script which sets the classpath and then invoke you main class.

                      • 8. Re: Camel File Component - NoTypeConversionAvailableException
                        annasw

                        I was hoping to satisfy a requirement by using executable jar file but looks like it might not be a best way.

                        Thank you,

                        Anna

                         

                        Edited by: asilchenko on May 12, 2010 6:40 PM

                        • 9. Re: Camel File Component - NoTypeConversionAvailableException
                          annasw

                          I am trying to add missing TypeConverter to classpath. I am seeing TypeConverter in camel-core-2.2.0.jar and some other jars. Could you please let me know which one gets used? Which jar I need to include for TypeConverter?

                          Thank you very much!

                           

                          Edited by: asilchenko on May 13, 2010 8:11 PM

                          • 10. Re: Camel File Component - NoTypeConversionAvailableException
                            davsclaus

                            You cannot do this.

                             

                            Its a special file in META-INF/services/org/apache/camel named TypeConverter which has a list of the package names it should scan.

                             

                            And if you merge many .jars -> 1 jar then the TypeConverter file should be merged as well to include all the package names from all the jars. Right now I bet it just add the TypeConverter file from either the first or last .jar.

                            • 11. Re: Camel File Component - NoTypeConversionAvailableException
                              annasw

                              Thank you for your response. I could not get META-INF/services/org/apache/camel to work. But I got around my problem by sending message thought bean processor class. And, everything works now from executable jar file.

                               

                               

                               

                              public InputStream convertBody(GenericFile file)

                                  {

                                       InputStream inputStream = null;

                                       try

                                        {

                                             inputStream = new BufferedInputStream(new FileInputStream((File)file.getFile()));

                                        }

                                       catch (FileNotFoundException e)

                                        {

                                             // TODO Auto-generated catch block

                                             e.printStackTrace();

                                        }          

                                      return inputStream;

                                  }

                               

                              Thank you very much,

                              Anna