I have a direct Camel route triggered by a restful. The restful passes the name of a file (which needs to be processed) inside the Exchange body. The route is very simple:
from("direct:myRoute")
.log("Reading file with name ${in.body}")
.pollEnrich().simple(inboundUri).timeout(5000)
.choice()
.when(body().isNull())
.log("Cannot read file. Body is null")
.otherwise()
.log("Processing file: ${in.headers.CamelFileAbsolutePath}")
...
where inboundUri is:
smb://DOMAIN;username:password@myLocation/myFolder/?include=${in.body}.csv&delay=5000&noop=true&idempotent=false&readLock=none&recursive=false&sortBy=reverse:file:modified
The first time I trigger this route I always get "Cannot read file. Body is null".
But if I trigger it again, it then works fine and the file gets processed.
Any idea why?
P.S. I've tried to set CAMEL in DEBUG mode, but I struggle to understand what it does. The first time I run it I get things like:
DefaultCamelContext : Using ComponentResolver: org.apache.camel.impl.DefaultComponentResolver@1016b44e to resolve component with name: smb
ResolverHelper : Lookup Component with name smb in registry. Found: null
ResolverHelper : Lookup Component with name smb-component in registry. Found: null
DefaultComponentResolver : Found component: smb via type: org.apacheextras.camel.component.jcifs.SmbComponent via: META-INF/services/org/apache/camel/component/smb
DefaultManagementAgent : Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=components,name="smb"
...
PollEnricher : Consumer received no exchange
FilterProcessor : Filter matches: true for exchange: Exchange[ID-server-43626-1517937470434-0-2]
The second time the output is much shorter and the main differences seems to be:
ServiceHelper : Resuming service Consumer[smb://DOMAIN;username:password@myLocation/myFolder/?include=${in.body}.csv&delay=5000&noop=true&idempotent=false&readLock=none&recursive=false&sortBy=reverse:file:modified]
PollEnricher : Consumer received: Exchange[]
FilterProcessor : Filter matches: false for exchange: Exchange[ID-server-43626-1517937470434-0-4]
Set the delay value in your inbound uri to a lower value as it has a delay of 5000 which is the same as your timeout, so that does not allow enough time for it to run. Set it to 1000 or 500 or something.