Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
I am a newbie on talend ESB.
I'm trying to get the content of files put in the source folder. And for that, I typed in the following expression.
System.out.println("File content: "+exchange.getIn().getBody());
Unfortunately it doesn't print the file I put content's.
Example: when I put a text file containing "lorem ipsum" , I am expecting to print that content to the output console but instead I get printed to the console GenericFile[C:\rep1\Finish.log] (see image below)
So I want to figure out why Message object doesn't represent the file content.
Thanx!
Hi gjeremy,
Unfortunately I get an error with your code. Find below the error !![
ERROR]: org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID-LAPTOP-FDV0N478-1626698516345-0-2 on ExchangeId: ID-LAPTOP-FDV0N478-1626698516345-0-1). Exhausted after delivery attempt: 1 caught: java.lang.ClassCastException: org.apache.camel.component.file.GenericFile cannot be cast to [B
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[Lab4_route1_cFile_] [Lab4_route1_cFile_] [file://C:/rep1?autoCreate=true&bufferSize=128&flatten=true&noop=false ] [ 8]
[Lab4_route1_cFile_] [Lab4_route1_cProce] [Processor@0x6ebaaba3 ] [ 3]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.lang.ClassCastException: org.apache.camel.component.file.GenericFile cannot be cast to [B
at demoesb.lab4_route1_0_1.Lab4_route1$1.process(Lab4_route1.java:145)
at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:110)
at demoesb.lab4_route1_0_1.Lab4_route1$2$1$1.process(Lab4_route1.java:224)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:110)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:138)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:452)
at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:219)
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:183)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
it seem you can use the getFile()method of org.apache.camel.component.file.GenericFile to get the file,
then you have to read his content
with common io package for example
String data = FileUtils.readFileToString(your file, "UTF-8");