title: Apache Camel - Filname to process
body: <p>I have a route , that is downloading a file from FTP. After that I just would like to send the filename to a jms:queue and not anything else. Ho to do that?</p>
  
  <p>Actually I have this route</p>
  
  <pre><code>&lt;from uri="ftp://ftp.x.com?username=x&amp;amp;password=x&amp;amp;binary=true&amp;amp;stepwise=false&amp;amp;delay=20000"    /&gt;
  &lt;to uri="file://{{download_folder}}?fileName=${date:file:yyyyMMdd}_${file:name}&amp;amp;keepLastModified=true"  /&gt; 
  &lt;to uri="processFileNameToBody" /&gt;
  &lt;to uri="jms:queue:File.Process" /&gt;
  </code></pre>
  
  <p>with this in processFileNameToBody (org.apache.camel.Processor)</p>
  
  <pre><code> public void process(Exchange exchange) throws Exception {
          try {
              if (exchange.getIn() instanceof GenericFileMessage) {               
                  log.info("Starting Processing FileName to body");
                  Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                  String file = (String) exchange.getIn().getHeader("CamelFileNameProduced");
                  map.put("file", file);
                  XStream xs = new XStream();
                  String xml = xs.toXML(map);
                  exchange.getOut().setBody(xml);     
                  log.info("Finished Processing FileName to body:" + file);
              }
          }
          catch (Exception e) {
              log.error("", e);
              throw e;
          }
      }
  </code></pre>
  
  <p>but it does not work. I got a NPE in GenericFileConverter.convert.to</p>
  
  <pre><code>Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: RemoteFile[
  </code></pre>
  
  <p>Perhaps anybody has a solution for this. It can't be so complicated, but actually I fail. I think it has something to do when the file is written. It is writte at the end, but I already changed the body.</p>
  
  <p>Help is appreciated. Thanks</p>