Search code examples
file-ionullunmarshallingjaxb2camel-ftp

File Object from Camel-exchange body is null in Camel FTP


The route definition is simple based on FTP2 component.

        Endpoint[sftp://server.com:22//path/to/file/?consumer.delay=900000&password=xxxxxx&username=user]

I am trying to read a file from a FTP folder.

   JAXBContext jaxBContext = JAXBContext.newInstance(ObjectFactory.class);
   Unmarshaller unmarshaller = jaxBContext.createUnmarshaller();
   File authBatchFile = exchange.getIn().getBody(File.class);
   AuthorizationFeed batchAuthFeed = (AuthorizationFeed) JAXBIntrospector
            .getValue(unmarshaller.unmarshal(authBatchFile)); 

The exchange has everything it should have

    Body                [Body is file based: RemoteFile[fileName.txt]]

Header also shows the size of the file CamelFileLength=81612. However, I am getting the below exception just after the exchange trace.

  java.lang.IllegalArgumentException: The value for the "java.io.File" parameter cannot be null.
at com.ibm.xml.xlxp2.jaxb.unmarshal.AbstractUnmarshallerImpl.reportNullParameter(AbstractUnmarshallerImpl.java:180)
at com.ibm.xml.xlxp2.jaxb.unmarshal.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:72)
at com.wellpoint.clihub.hie.um.camel.processor.BatchCFFProcessor.process(BatchCFFProcessor.java:47)

Solution

  • I found the solution to it by adding to the route definition

    &localWorkDirectory=/tmp. 
    

    That way it doesn't consider it to be a remote file and considers it to be a java.io.File. I think Camel should incorporate that as a default feature when dealing with remote files. Per their documentation,

    The route above is ultra efficient as it avoids reading the entire file content into memory. It will download the remote file directly to a local file stream. The java.io.File handle is then used as the Exchange body.