0 Replies Latest reply on Sep 17, 2010 1:32 AM by unwired

    ftp, file, onException + aggregation + FileNotFound storing orig file.

    unwired

      Hi,

       

      Hopefully this is user error, but i'm having troubles storing an original message (i.e. a file) which appears to be related to the combination of my use of aggregation with exception handling but I can not understand what the problem is.

      Route:

      from("ftp://user@server:port/directory?binary=true&delete=true&localWorkDirectory=/tmp&maximumReconnectAttempts=5&password=xxxx&readLock=true&reconnectDelay=10000&recursive=true") // NB - does NOT happen if i don't use localWorkDirectory as per note below.
      .setHeader("originalBody", body()) // saving the file so we can write it later. explored useOriginalBody but causes issues because i want the route to keep going on exception. we need to persist whatever records we did extract.
            .to("bean:collectorParser") // parse the file.
               // handles Runtime or checked (i.e. IOException)
            .onException(Exception.class)
               .to("direct:continueProcessingAfterFailure")
               .end()
            .to("direct:aggregateAndPersist")
            .setBody(header("originalBody"))
            .to("file://" + postProcessingDirectory);
               
            from("direct:continueProcessingAfterFailure")
               .setBody(header("originalBody"))
               .to("file://" + failedDirectory)
               .to("direct:aggregateAndPersist");
               
               from("direct:failedProcessing")
               .setBody(header("originalBody"))
            //   .convertBodyTo(InputStream.class) - tried to convert as per error message but think the error's a bit of a red herring. i'm not sure why it's trying to access that tmp file when it is but that's the "real" problem i think.. it seems to be gone.
               .to("file://" + failedDirectory);
      
            // aggregate the data and persist the records we've extracted.
            from("direct:aggregateAndPersist")
               .onException(Exception.class)
               .to("direct:failedProcessing")
               .end()
      // if i comment the aggregate, it does NOT happen. the file CAN be written and I do not get the FileNotFound error.
            .aggregate(header("cpe_status"),new CpeBsDataSetAggregationStrategy())
            .batchSize(100)
            .to("bean:collectorHandler"); // for current test, this is where exception is thrown.
      

      What's happening, is if I use both localWorkDirectory and use aggregation (see notes below), I get the following error when it attempt to write the file:

       

      Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: GenericFile[SiteID_13-UploadTime_20100913_232403_0370.chrlog] of type: org.apache.camel.component.file.remote.RemoteFile on: Message: GenericFile[SiteID_13-UploadTime_20100913_232403_0370.chrlog]. Caused by: No type converter available to convert from type: org.apache.camel.component.file.remote.RemoteFile to the required type: java.io.InputStream with value GenericFile[SiteID_13-UploadTime_20100913_232403_0370.chrlog]. Exchange[Message: GenericFile[SiteID_13-UploadTime_20100913_232403_0370.chrlog]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.file.remote.RemoteFile to the required type: java.io.InputStream with value GenericFile[SiteID_13-UploadTime_20100913_232403_0370.chrlog]]
              at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:103)
              at org.apache.camel.util.ExchangeHelper.getMandatoryInBody(ExchangeHelper.java:116)
              at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:203)
              ... 46 more
      Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.camel.component.file.remote.RemoteFile to the required type: java.io.InputStream with value GenericFile[SiteID_13-UploadTime_20100913_232403_0370.chrlog]
              at org.apache.camel.impl.converter.DefaultTypeConverter.mandatoryConvertTo(DefaultTypeConverter.java:119)
              at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)
              ... 48 more
      Caused by: org.apache.camel.RuntimeCamelException: org.apache.camel.RuntimeCamelException: java.io.FileNotFoundException: /tmp/SiteID_13-UploadTime_20100913_232403_0370.chrlog (No such file or directory)
              at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:740)
              at org.apache.camel.impl.converter.StaticMethodFallbackTypeConverter.convertTo(StaticMethodFallbackTypeConverter.java:54)
              at org.apache.camel.impl.converter.DefaultTypeConverter.doConvertTo(DefaultTypeConverter.java:159)
              at org.apache.camel.impl.converter.DefaultTypeConverter.mandatoryConvertTo(DefaultTypeConverter.java:117)
      

       

       

       

      A few notes:

      there is NO issues with writing the file if an exception is not thrown on the route.

      If I do NOT use "&localWorkDirectory=/tmp" as part of my ftp url, then the issue does NOT

      If I write the ftp files to a local file and use 'moveFailed' as part of the file url, the file is appropriately moved. The problem with this is

      a)i need to keep  processing even if there is an exception which i could not seem to get to work using the moveFailed. All subsequent steps on the route did not seem to get performed. Is there a way to continue the route in case of an exception?

      b) i don't really need to write to a local file first but not a major issue.

       

      Any ideas why this is happening and/or what's the best solution?

       

      cheers.