4 Replies Latest reply on Jan 18, 2011 12:47 AM by Claus Ibsen

    Problem file component  - help

    Peter Chandler Master

      I do a camel from file:, I get the file name and size. But when I try to get the body, as a string, I get null with no errors?

       

       

      Camel Context:

        <camelContext id="myContext" xmlns="http://camel.apache.org/schema/spring">
          <route>  
            <from uri="file:/peter?consumer.delay=1000"></from>
            <to uri="bean:myProcessor"></to>
          </route>
         </camelContext>
      

       

      myProcessor (java):

                Message inMessage = exchange.getIn();
                
      
                Object obj = inMessage.getBody();
                GenericFile inFile = null;
                
                if (obj instanceof GenericFile)
                {
                     inFile = (GenericFile)inMessage.getBody();
                }
                else
                {
                     logger.error(">> body is not a GenericFile");
                     return;
                }
      
                logger.info(">> RECEIVED: FileName:   " + inFile.getFileName());
                logger.info(">> RECEIVED: FileLength: " + inFile.getFileLength());
      
                String inString = inMessage.getBody(String.class);
                if (inString == null)
                {
                     logger.error(">> Can't get body as a string inMessage.getBody(String.class) ???");
                     return;
                }
      

       

      LogFile:

      18:36:10,640 INFO - >> RECEIVED: FileName:   Test.txt
      18:36:10,640 INFO - >> RECEIVED: FileLength: 579
      18:36:10,640 TRACE - Converting org.apache.camel.component.file.GenericFile -> java.lang.String with value: GenericFile[/peter/Test.txt]
      18:36:10,641 TRACE - Converting org.apache.camel.component.file.GenericFileMessage -> java.lang.String with value: GenericFileMessage with file: GenericFile[/peter/Test.txt]
      18:36:10,641 ERROR - >> Can't get body as a string inMessage.getBody(String.class) ???