Ad 1) See the properties component http://camel.apache.org/properties
Ad 2) Use stop() On Thu, Sep 2, 2010 at 11:17 AM, Bengt Rodehav <be...@rodehav.com> wrote: > Thanks Willem it worked perfectly. > > However, I now have two other problems (if you bear with me...): > > I want to use this interceptor: > > *interceptFrom().when(PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} > == null"))).to("file://${file:path}/${date:now:yyyyMMdd}/skipped").end();* > > 1. I get the following exception: > > *java.lang.IllegalArgumentException: Invalid directory: > skipped/${date:now:yyyyMMdd}. Dynamic expressions with ${ } placeholders is > not allowed. Use the fileName option to set the dynamic expression.* > > How can I direct the file to a directory that I need properties (file and > date) to calculate? > > 2. The interceptor does not "skip" the file. It sends it both to the > original endpoint and to my "skipped" folder. How can I make it NOT send the > file to the original endpoint. I've seen the > > *interceptSendToEndpoint("...").skipSendToOriginalEndpoint();* > > but in this case I want to use the interceptFrom() since I want to intercept > the route at the earliest possible stage. > > /Bengt > > > > 2010/9/2 Claus Ibsen <claus.ib...@gmail.com> > >> On Thu, Sep 2, 2010 at 9:20 AM, Bengt Rodehav <be...@rodehav.com> wrote: >> > Hi Willem, >> > >> > Thanks for the info. I assume then that as long as I'm on Camel 2.4 I'll >> > check for null but when I upgrade to Camel 2.5 I'll start checking for >> zero >> > instead. >> > >> > However, that issue aside, I still get the same problems that I wrote >> about. >> > Can you confirm that the following syntax is correct? >> > >> > interceptFrom().when(simple("${file:length} == 0")).to(skipped).end(); >> > >> > OR (as long as I stay on Camel 2.4) >> > >> > interceptFrom().when(simple("${file:length} == null")).to(skipped).end(); >> > >> > Both of the above give me a compilation error since the "when()" method >> > expects a "Predicate" while "simple()" returns a String. If I instead use >> > "simple(..)..isEqualTo(0)" then the compiler accepts it (since >> "isEqualTo()" >> > returns a Predicate), but then I get the runtime exception instead. >> > >> >> That is also part of Camel 2.5 that simple is easier to use in the >> RouteBuilder out of the box. >> >> Just use a PredicateBuilder.toPredicate(SimpleLanguage.simple("foo") >> to construct the predicate. >> >> >> > I'v double checked my dependencies and it turns out that I'm using a >> > snapshot version of Camel 2.4 based on revision 958950. Maybe my problems >> > stem from that... I will check of course. >> > >> > Do you know if the "when()" method will accept a String as parameter in >> > Camel 2.4? >> > >> > /Bengt >> > >> > >> > 2010/9/2 Willem Jiang <willem.ji...@gmail.com> >> > >> >> Hi Bengt, >> >> >> >> I tried to reproduce you issue in Camel trunk, and found this bug[1]. >> >> BTW, If you just want to filter the zero length file, you can take a >> look >> >> this unit test file[2] and change the simple expression to >> "${file:length} >> >> == null" as in Camel 2.4.0, ${file:length} is null if the file.length is >> 0. >> >> >> >> >> >> [1]https://issues.apache.org/activemq/browse/CAMEL-3100 >> >> [2] >> >> >> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIntercepEmptyFileTest.java >> >> >> >> Willem >> >> >> >> >> >> Bengt Rodehav wrote: >> >> >> >>> I've developed a file transfer service (for file/ftp/ftps/sftp) that >> uses >> >>> Camel 2.4. I need to be able to skip transferring empty files and was >> >>> hoping >> >>> to use an interceptor to accomplish this. Below is the relevant code: >> >>> >> >>> String skippedUri = >> "file://skipped/${date:now:yyyyMMdd}/${file:name}"; >> >>> >> >>> >> interceptFrom().when(simple("${file:length}").isEqualTo(0)).to(skippedUri).end(); >> >>> >> >>> This compiles but in runtime a get the following exception when trying >> to >> >>> start the route: >> >>> >> >>> *java.lang.NoSuchMethodError: >> >>> >> >>> >> se.digia.connect.services.skandia.filetransfer.FileTransferService$1.simple(Ljava/lang/String;)Lorg/apache/camel/builder/ValueBuilder; >> >>> * >> >>> * **at >> >>> >> >>> >> se.digia.connect.services.skandia.filetransfer.FileTransferService$1.configure(FileTransferService.java:279) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:295) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:250) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:236) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:498) >> >>> * >> >>> * **at >> >>> >> >>> >> se.digia.connect.core.service.RouteServiceBase.doStart(RouteServiceBase.java:42) >> >>> * >> >>> * **at >> >>> se.digia.connect.core.service.ServiceBase.start(ServiceBase.java:49)* >> >>> * **at >> >>> >> >>> >> se.digia.connect.services.skandia.filetransfer.FileTransferService.__start(FileTransferService.java:60) >> >>> * >> >>> * **at >> >>> >> >>> >> se.digia.connect.services.skandia.filetransfer.FileTransferService.start(FileTransferService.java) >> >>> * >> >>> * **at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)* >> >>> * **at >> >>> >> >>> >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) >> >>> * >> >>> * **at >> >>> >> >>> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) >> >>> * >> >>> * **at java.lang.reflect.Method.invoke(Method.java:597)* >> >>> * **at org.apache.felix.ipojo.util.Callback.call(Callback.java:235)* >> >>> * **at org.apache.felix.ipojo.util.Callback.call(Callback.java:191)* >> >>> * **at >> >>> >> >>> >> org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__stateChanged(LifecycleCallbackHandler.java:162) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java) >> >>> * >> >>> * **at >> >>> >> org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:440)* >> >>> * **at >> >>> org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:321)* >> >>> * **at >> >>> >> >>> >> org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:155) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:298) >> >>> * >> >>> * **at >> >>> >> >>> >> org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:235) >> >>> * >> >>> * **at >> org.apache.felix.ipojo.IPojoFactory.updated(IPojoFactory.java:603)* >> >>> * **at >> >>> >> >>> >> org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceFactoryUpdate.run(ConfigurationManager.java:1279) >> >>> * >> >>> * **at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:88)* >> >>> >> >>> I've also tried the following: >> >>> >> >>> interceptFrom().when(simple("${file:length} == >> >>> 0")).to(skipped).end(); >> >>> >> >>> But it gives the following compilation error: >> >>> >> >>> *The method when(Predicate) in the type InterceptDefinition is not >> >>> applicable for the arguments (ValueBuilder)* >> >>> >> >>> What am I missing? This is the first time I'm using simple language and >> >>> the >> >>> first time I'm using interceptors. I should also mention that I deploy >> the >> >>> camel route in Karaf 1.6.0 which means that OSGI could play a part I >> >>> guess. >> >>> >> >>> /Bengt >> >>> >> >>> >> >> >> > >> >> >> >> -- >> Claus Ibsen >> Apache Camel Committer >> >> Author of Camel in Action: http://www.manning.com/ibsen/ >> Open Source Integration: http://fusesource.com >> Blog: http://davsclaus.blogspot.com/ >> Twitter: http://twitter.com/davsclaus >> > -- Claus Ibsen Apache Camel Committer Author of Camel in Action: http://www.manning.com/ibsen/ Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/ Twitter: http://twitter.com/davsclaus