title: Apache Camel, FTP consumer: How to take header parameters of the previous route?
body: <p>I have several camel routes and I set a header in the Exchange object with the name FILE_NAME in the one route while reading the data from a DB. <strong>As a next step this route goes further to my FTP route where the file should be downloaded.</strong> The problem is that the FTP route does not receive the headers of the previous route with the contentEnricher I am using. This is the official behaviour: <a href="http://camel.apache.org/content-enricher.html" rel="nofollow noreferrer">http://camel.apache.org/content-enricher.html</a> However, "fileName" parameter of the FTP endpoint could be constructed dynamically to download a particular file.</p>
  
  <p>My FTP route looks like this, with schematic data now:</p>
  
  <pre><code>from("direct:myRoute")   
  .pollEnrich("ftp://foo@localhost/public/reports?password=secret&amp;binary=true&amp;fileName=data.txt") 
  .to("mock:result");
  </code></pre>
  
  <p>How could I download just the file provided in the header value of the previous route? Should I not use content enricher or should I store the fileName in a variable somewhere else? Thanks also in advance for your response.</p>
  
  <p><strong>EDIT1:</strong></p>
  
  <p>Thanks for the posts I got further but I need to come back to the same point as I can access the header values from Java DSL also from the simple expression in pollEnrich() but not in the to(). The process(Exchange exchange) prints the correct header values, the pollEnrich with the <strong>sftp consumer fetches the file from</strong> the sftp server <strong>but neither ${header.FILE_NAME_ONLY} nor ${in.header.FILE_NAME_ONLY} access it in the to()</strong>. So the file created will be named "value of obNumber"_ . Could you please have a look what is incorrect in the code snippet below?</p>
  
  <pre><code>from("direct:SFTP").routeId("SFTP")
          .log("### SFTP")
          .process(new Processor() {
                  public void process(Exchange exchange) throws Exception {
                          LOGGER.info("### Process SFTP " +
                              "FILE_NAME_ONLY = " + exchange.getIn().getHeader("FILE_NAME_ONLY" ) +
                              " FILE_PATH = " + exchange.getIn().getHeader("FILE_PATH") +
                              " AGG = " + exchange.getIn().getHeader("AGG"));
                   }
          })
          .choice()
              .when(header("FILE_NAME_ONLY").isEqualTo(""))
                  .log("### SFTP FILE_NAME_ONLY is null!")
                  .endChoice()
              .otherwise()
                  .log("### SFTP FILE_NAME_ONLY is NOT null!")
                  .pollEnrich().simple("sftp:" + ftpUid + "@" + ftpHost + "/" + ftpBasePath + "/${header.FILE_PATH}?password=" + 
                                      ftpPwd + "&amp;binary=true&amp;fileName=${header.FILE_NAME_ONLY}")
                  .to("file:extract?fileName=" + obNumber + "_${header.FILE_NAME_ONLY}")
          .end();
  </code></pre>
  
  <p><strong>Solution:</strong></p>
  
  <p>The final solution was the dynamic router as Jeremie B proposed on 25 Febr. The problem is that pollEnrich() swallows up the previous header variables. So they are available to construct the URI but cannot be accessed afterwards to name the file. I was using camel 2.16.1.</p>
  
  <p>What I did:</p>
  
  <ol>
  <li>created a route with the dynamic router</li>
  <li>created a bean that is called for determining the next route to get to</li>
  <li>before the pollEnrich I save the necessary header values in a map of the exchange</li>
  <li>after the pollEnrich I get the saved header values and set them as headers</li>
  <li>then it is routed to a routed where it writes the file. (It can already access the newly set header variables)</li>
  </ol>
  
  <p>Two examples that helped:</p>
  
  <ul>
  <li><a href="http://www.systemmobile.com/?p=427" rel="nofollow noreferrer">http://www.systemmobile.com/?p=427</a>           "[...] To determine the
  destination endpoint after each point in the route, we need to use a
  Dynamic Router. [...]"</li>
  <li><a href="http://camel.apache.org/dynamic-router.html" rel="nofollow noreferrer">http://camel.apache.org/dynamic-router.html</a></li>
  </ul>