What version of Camel are you using?
I am using 2.8.3 version of Camel. Blueprint. FUSE ESB 4.4.1-fuse-01-06.
Ah okay so you have a custom data format, and in the marshal() method you need access to the attachments?
You should be able to access them from the OUT message on the Exchange.
As always create a small unit test, and set a break point, and debug. And see what you got on the passed in Exchange parameter.
Thanks for the response Claus!
I have a custom DataFormat - MultiPartDataFormat.
I debugged the code as you mentioned but the attachments are not present in both In and Out referneces of the exchange.
I had implemented the Processor interface on the same MultiPartDataFormat class and invoked the unmarshal() method from the process() method - just that no other code change. Changed the route to call process( (Processor) multiPartDataFormat) instead of unmarshal(multiPartDataFormat) and then the attachments are retained in the In message itself and were available in the MultiPartDataFormat.marshal(...).
The only difference in both the methods is unmarshal() has a return type and I returned what forms the body() of the In message as seen on an example (http://camel.apache.org/custom-dataformat.html).
Not sure what to return so I tried returning the whole exchange object but then it looks like it goes into an infinite loop and goes out of memory.
For now calling the processor has solved my problem but I feel DataFormat/unmarshall/marshal way would be more meaningful for the purpose.
Ah yeah there is a difference between marshal and unmarshal. Where the latter, is supposed to construct a new message body.
We should look into allowing you to return a Message instance, or possible just the plain Exchange as alternative. And then Camel should detect that if its a Message or Exchange then react differently. We do this for the Splitter EIP etc.
I will log a JIRA.