Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
taslimanka
Contributor
Contributor

Why Message Object does not represent file content?

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()); 

0695b00000GiB4zAAF.png

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)

0695b00000GiB6vAAF.png

So I want to figure out why Message object doesn't represent the file content.

Thanx!

Labels (3)
3 Replies
gjeremy1617088143
Creator III
Creator III

Hi ,@mohamed sylla​ ,

maybe you can try :

System.out.println("File content: "+ new String((byte[]) exchange.getIn().getBody())); 

let me know if it's working.

Send me love and Kudos

 

 

taslimanka
Contributor
Contributor
Author

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)

 

gjeremy1617088143
Creator III
Creator III

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");