camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Keep original message several "steps" back.
Date Wed, 17 Feb 2010 20:32:56 GMT
On Wed, Feb 17, 2010 at 8:01 PM, ankelee <andreasasmuss@gmail.com> wrote:
>
> The latter two suggestions I can get to work, but I just get null when trying
> to get the body as a String.
>
> I'm not sure what is going on behind the scenes here. As stated I want to be
> able to recover from an exception if a transformation goes wrong and write
> the file to an error directory, and another directory if everything
> succeeds. Is Camel keeping the original file "safe" internally no matter
> which way I do it? Can I always use the file handle to get first original
> message?

The file component can do this by default using these options:
moveFailed = move to a error folder if processing of the file failed
move = move to a backup folder if processing succeeded

http://camel.apache.org/file2.html

So is this not something like that you want to do?



>
> getUnitOfWork() will always refer to the original entry point of the message
> or? I thought it would only keep knowledge about the latest node that the
> message had been through.
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Wed, Feb 17, 2010 at 5:04 PM, ankelee <andreasasmuss@gmail.com> wrote:
>>>
>>> Hello
>>>
>>> I'm trying to build a system where I consume files from a directory,
>>> perform
>>> transformations in several steps and finally deliver at an endpoint. In
>>> case
>>> the delivery of the transformed message succeeds, I want to route a copy
>>> of
>>> the original file as it was before consumation to a backup directory on
>>> disk. If the transformation fails, I want a copy of the original file
>>> copied
>>> to an error directory.
>>>
>>> I have thought up a couple of solutions but I don't think they are best
>>> practice. One is somehow keeping a copy in a queue and then going back
>>> and
>>> identifying on an id and copy the. The other one is bundling the original
>>> file with the transforming message and then extracting the original file
>>> and
>>> write it to the according directory/queue.
>>>
>>> What kind of approach would be good?
>>> --
>>
>> In the future Camel will have a some sort of better API to traverse
>> the message history so you can see the modifications.
>>
>> Anyway the original input message is avail as follows
>>
>> Exchange exchange = ...
>>
>> Message in = exchange.getUnitOfWork().getOriginalInMessage();
>> // will read the file content
>> String body = in.getBody(String.class);
>>
>> but as yours is a file you should be able to do
>> GenericFile<File> file = in.getBody(GenericFile.class);
>>
>> if you want to use the file handle instead.
>>
>>
>> You can also just extract the file name from the header and do
>>
>> File file = new File(exchange.getIn().getHeader(Exchange.FILE_NAME,
>> String.class));
>>
>>
>>
>>> View this message in context:
>>> http://old.nabble.com/Keep-original-message-several-%22steps%22-back.-tp27626057p27626057.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> 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
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Keep-original-message-several-%22steps%22-back.-tp27626057p27628689.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
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

Mime
View raw message