title: Apache Camel 2.17 RouteBuilder when file is empty route not working
body: <p>I am trying to route NULL or Empty messages to a local archive on system, and process files having content. Using Camel 2.17, Jboss Fuse servicemix bundle. I can't get it to work correctly. it has to be something I'm doing wrong. I've tried a few different things seen below ( all commented ).</p>
  
  <p>Examples Tried:</p>
  
  <pre><code>    } else if (Boolean.parseBoolean(isCompressedOnly)) { //Only Zipped or Compressed
          // .when(simple("${file:length} == 0"))  
          // .when(simple("${header.CamelFileLength} == 0" )) 
          // .when(header("CamelFileLength").isEqualTo(0))
          // .when(body().isNull())
          // .when(header("CamelFileLength").isEqualTo(0))
          // .when(simple("${header.CamelFileLength} &amp;lt; 10" ))
          // .when(simple("${header.CamelFileLength} &amp;eq; 0" ))
          // .when(simple("${file:length} == null"))  
  
          ZipFileDataFormat zipFile = new ZipFileDataFormat();
          zipFile.setUsingIterator(true);
  
          from(fromStr)
          .routeId("Zipped.Only")
          .log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
          .unmarshal(zipFile)
          .split(body(Iterator.class))
          .streaming()
          .convertBodyTo(String.class)
          .choice()
          .when(simple("${file:length} == null"))
          .wireTap("file" + errorArchive)
          .log(LoggingLevel.INFO,"File Size: ${header.CamelFileLength}, File is Empty or Zero Length!")
          .endChoice()
          .otherwise()
              .wireTap("file:" + fileArchive)
              .split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
              .process(new EndpointParametersProcessor(decoderName))
              .end()
              .to(toStr);
      } else {
  </code></pre>
  
  <p>The only statement that works kind of ( because all messages get routed to the null file endpoint, even if they have length/size/data/content )</p>
  
  <pre><code>.when(simple("${header.CamelFileLength} &amp;lt; 10" ))
  </code></pre>
  
  <p>can you tell me what I am doing wrong? thank you!</p>
  
  <p>Where can I find the methods associated with Header? e.g.<br>
   .when(header("result").isEqualTo("A")
            .to(routeA)</p>
  
  <p>I have tried not nesting the choice()'s but everything gets routed thru the first when(). </p>
  
  <pre><code>        ZipFileDataFormat zipFile = new ZipFileDataFormat();
          zipFile.setUsingIterator(true);
  
          from(fromStr)
          .routeId("Zipped.Only")
          .log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
          .unmarshal(zipFile)
          .split(body(Iterator.class))
          .streaming()
          .convertBodyTo(String.class)
          .choice()
              .when(simple("${header.CamelFileLength} &amp;lt; 10" ))
                  .wireTap("file:" + errorArchive)
                  .log(LoggingLevel.INFO,"File Size: ${header.CamelFileLength}, File is Empty or Zero Length!")
              .endChoice()
              .when(simple("${header.CamelFileLength} &amp;gt; 10" ))
                  .wireTap("file:" + fileArchive)
                  .split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
                  .process(new EndpointParametersProcessor(decoderName))
                  .end()
                  .to(toStr)
              .endChoice()
          .end();
  
  ├── [drwxr-xr-x 4.0K]  core
  │   ├── [drwxr-xr-x 4.0K]  enriched
  │   ├── [drwxr-xr-x 4.0K]  mt1
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   ├── [drwxr-xr-x 4.0K]  mt2
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   ├── [drwxr-xr-x 4.0K]  mt3
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   └── [drwxr-xr-x 4.0K]  tobeprocessed
  ├── [drwxr-xr-x 4.0K]  dbase
  ├── [drwxr-xr-x 4.0K]  fleet
  │   └── [drwxr-xr-x 4.0K]  core
  │       ├── [drwxr-xr-x 4.0K]  archive
  │       └── [drwxr-xr-x 4.0K]  error
  │           ├── [-rw-r--r--    0]  GCMS_20190420-0815.csv
  │           ├── [-rw-r--r--    0]  GCMS_20190420-0816.csv
  │           ├── [-rw-r--r--    0]  GCMS_20190420-0817.csv
  │           ├── [-rw-r--r-- 1.1M]  GCMS_20190420-0945.csv
  │           ├── [-rw-r--r-- 1.1M]  GCMS_20190420-0953.csv
  │           └── [-rw-r--r-- 1.1M]  GCMS_20190420-1001.csv
  └── [drwxr-xr-x 4.0K]  upload
  </code></pre>
  
  <p>Claus, I have tried the readlock limit, it has no impact here.</p>
  
  <pre><code>@Override
  public void configure() throws Exception {
  
      if (validateConfiguration()) {
  
          final String fromStr = String.format("%s://%s@%s:%s/%s?password=RAW(%s)&amp;recursive=%s&amp;stepwise=%s&amp;useList=%s&amp;passiveMode=%s&amp;disconnect=%s"
                  + "&amp;move=.processed"
                  + "&amp;maxMessagesPerPoll=0"
                  + "&amp;eagerMaxMessagesPerPoll=false"
                  + "&amp;sortBy=file:modified"
                  + "&amp;sendEmptyMessageWhenIdle=false"
                  + "&amp;delay=60000"
                  + "&amp;initialDelay=60000"
                  + "&amp;connectTimeout=15000"
                  + "&amp;localWorkDirectory=/tmp"
                  + "&amp;readLockMinLength=0"
                  , transport, username, host, port, path, password, recursive, stepwise, useList, passiveMode, disconnect);
  
          // Format the To Endpoint from Parameter(s).
          final String toStr = String.format("%s", toEndpoint);
  </code></pre>
  
  <p>I have changed the route to look like the following, tried to simplify it. but it still doesn't work, in that it accepts all files even -0- zero length files which I do not want to process. 
  I do believe it is how the choice.when simple statement is formed, something isn't quit right. I've tried many combinations all yielding same result.</p>
  
  <pre><code>            from(fromStr)
              .routeId("Zipped.Only")
              .log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
              .unmarshal(zipFile)
              .split(body(Iterator.class))
              .streaming()
              .convertBodyTo(String.class)
              .wireTap("file:" + fileArchive)
              .choice()
               .when(simple("${header.CamelFileLength} &gt; 0" ))
                 .split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
                   .process(new EndpointParametersProcessor(decoderName))
                 .end()
                 .to(toStr)
              .endChoice()
              .end();
  </code></pre>
  
  <p>yields, I only want to process or move to the tobeprocessed folder when the file has data or file.length != 0.  something is wrong with how the simple statement used??? I'll keep trying.</p>
  
  <pre><code>ge-digital/
  ├── [drwxr-xr-x 4.0K]  core
  │   ├── [drwxr-xr-x 4.0K]  enriched
  │   ├── [drwxr-xr-x 4.0K]  mt1
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   ├── [drwxr-xr-x 4.0K]  mt2
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   ├── [drwxr-xr-x 4.0K]  mt3
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   └── [drwxr-xr-x 4.0K]  tobeprocessed
  │       ├── [-rw-r--r--    0]  GCMS_20190420-0815.csv
  │       ├── [-rw-r--r--    0]  GCMS_20190420-0816.csv
  │       └── [-rw-r--r--    0]  GCMS_20190420-0817.csv
  ├── [drwxr-xr-x 4.0K]  dbase
  ├── [drwxr-xr-x 4.0K]  fleet
  │   └── [drwxr-xr-x 4.0K]  core
  │       ├── [drwxr-xr-x 4.0K]  archive
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0815.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0816.csv
  │       │   └── [-rw-r--r--    0]  GCMS_20190420-0817.csv
  │       └── [drwxr-xr-x 4.0K]  error
  └── [drwxr-xr-x 4.0K]  upload
  </code></pre>
  
  <p>The route basically working now EXCEPT the file length/size is wrong. it is the original file length NOT the split out files length.  How can I get around this?<br>
  before split - CamelFileLength: 598 and file.length: 598
  after split - CamelFileLength: 598 and file.length: 598</p>
  
  <pre><code>        from(fromStr)
          .routeId("Zipped.Only")
          .log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
          .unmarshal(zipFile)
          .split(body(Iterator.class))
          .streaming()
          .convertBodyTo(String.class)
          .wireTap("file:" + fileArchive)
          .log(LoggingLevel.INFO, "before split - CamelFileLength: ${header.CamelFileLength} and file.length: ${file:length}")
          .split(body().tokenize("\n"), new FleetAggregationStrategy())  //.streaming()
          .process(new EndpointParametersProcessor(decoderName))
          .end()
          .choice()
          //.when(simple("${file:length} &gt; 0"))
          .when(simple("${header.CamelFileLength} &gt; '0'")) 
             .log(LoggingLevel.INFO, "after split - CamelFileLength: ${header.CamelFileLength} and file.length: ${file:length}")
             .to(toStr)
          .otherwise()
             .log(LoggingLevel.INFO, "Message received ${file:name} is Empty or Null")
             .to("file:" + errorArchive)
          .end();
  </code></pre>
  
  <p>FINAL, ok, we finally have it working.  man, little things like this can set you back a bit.  for those interested and may help you.</p>
  
  <p>I was using body.size, hmmm, wasn't giving the size of the body, I then used body.length and that worked.  many of the nice static methods i could not get working, I think I need to upgrade to new camel release. anyway, the problem is that the headers such as CamelFileLength and such carry the original file's length/size and not that which was split out by unmarshalling zipfile and splitting out all the files.  I was using headers until I realized the above, so, we used the body() for our predicate, and this worked, and use length</p>
  
  <pre><code>} else if (Boolean.parseBoolean(isCompressedOnly)) { //Only Zipped or Compressed
  
      ZipFileDataFormat zipFile = new ZipFileDataFormat();
      zipFile.setUsingIterator(true);
  
      from(fromStr)
      .routeId("Zipped.Only")
      .log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
      .unmarshal(zipFile)
      .split(body(Iterator.class))
      .streaming()
      .convertBodyTo(String.class)
      .wireTap("file:" + fileArchive)
      .split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
      .process(new EndpointParametersProcessor(decoderName))
      .end()
      .choice()
      .when(simple("${body.length} &gt; '0'" ))
      .to(toStr)
      .end();
      // .when(simple("${file:length} == 0"))  
      // .when(simple("${header.CamelFileLength} == 0" )) 
      // .when(header("CamelFileLength").isEqualTo(0))
      // .when(body().isNull())
      // .when(body().isNotNull())
      // .when(header("CamelFileLength").isEqualTo(0))
      // .when(simple("${header.CamelFileLength} &amp;lt; 10" ))
      // .when(simple("${header.CamelFileLength} &amp;eq; 0" ))
      // .when(simple("${file:length} == null"))                  
  } else {
  </code></pre>
  
  <p>Yields:</p>
  
  <pre><code>ge-digital/
  ├── [drwxr-xr-x 4.0K]  core
  │   ├── [drwxr-xr-x 4.0K]  enriched
  │   ├── [drwxr-xr-x 4.0K]  error
  │   │   └── [-rw-r--r--   47]  GCMS_2019-04-23_05-27-18.666.csv
  │   ├── [drwxr-xr-x 4.0K]  mt1
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   ├── [drwxr-xr-x 4.0K]  mt2
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   ├── [drwxr-xr-x 4.0K]  mt3
  │   │   └── [drwxr-xr-x 4.0K]  processed
  │   │       ├── [-rw-r--r-- 2.9K]  GCMS_112-A-001_Gas_Turbine_2019-04-23_05-29-18.csv
  │   │       ├── [-rw-r--r-- 2.1K]  GCMS_112-A-001_Gas_Turbine_cw_2019-04-23_05-29-18.csv
  │   │       ├── [-rw-r--r--  911]  GCMS_112-A-001_Generator_2019-04-23_05-29-18.csv
  │   │       ├── [-rw-r--r-- 2.8K]  GCMS_112-A-002_Gas_Turbine_2019-04-23_05-29-18.csv
  │   │       ├── [-rw-r--r-- 2.1K]  GCMS_112-A-002_Gas_Turbine_cw_2019-04-23_05-29-18.csv
  │   │       └── [-rw-r--r--  888]  GCMS_112-A-002_Generator_2019-04-23_05-29-18.csv
  │   └── [drwxr-xr-x 4.0K]  tobeprocessed
  │       ├── [-rw-r--r-- 935K]  GCMS_2019-04-23_05-27-44.673.csv
  │       ├── [-rw-r--r--    0]  GCMS_2019-04-23_05-27-44.673.csv.camelLock
  │       ├── [-rw-r--r-- 941K]  GCMS_2019-04-23_05-28-07.013.csv
  │       ├── [-rw-r--r-- 936K]  GCMS_2019-04-23_05-28-33.694.csv
  │       ├── [-rw-r--r-- 939K]  GCMS_2019-04-23_05-29-02.300.csv
  │       └── [-rw-r--r-- 946K]  GCMS_2019-04-23_05-29-28.928.csv
  ├── [drwxr-xr-x 4.0K]  dbase
  ├── [drwxr-xr-x 4.0K]  fleet
  │   └── [drwxr-xr-x 4.0K]  core
  │       ├── [drwxr-xr-x 4.0K]  archive
  │       │   ├── [-rw-r--r-- 981K]  GCMS_20190319-0429.csv
  │       │   ├── [-rw-r--r-- 977K]  GCMS_20190319-0437.csv
  │       │   ├── [-rw-r--r-- 982K]  GCMS_20190319-0446.csv
  │       │   ├── [-rw-r--r-- 977K]  GCMS_20190319-0454.csv
  │       │   ├── [-rw-r--r-- 980K]  GCMS_20190319-0502.csv
  │       │   ├── [-rw-r--r-- 988K]  GCMS_20190319-0511.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0815.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0816.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0817.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0818.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0819.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0820.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0821.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0822.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0823.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0824.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0825.csv
  │       │   ├── [-rw-r--r--  15K]  GCMS_20190420-0826.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0827.csv
  │       │   ├── [-rw-r--r--    0]  GCMS_20190420-0828.csv
  │       │   └── [-rw-r--r--    0]  GCMS_20190420-0829.csv
  │       └── [drwxr-xr-x 4.0K]  error
  └── [drwxr-xr-x 4.0K]  upload
  </code></pre>