Obtaining a previous message within an Apache Camel route

apache-camel

Solution

You should preserve the message in the `Exchange` property `setProperty("originalMessage", body())` before transforming it. Afterwards you can access that property using `getProperty("originalMessage")`

Problem

I'm pretty new to camel so perhaps I'm going about this the wrong way but I'm routing messages from one endpoint to another and transforming them on the way. However the next stage is to add authentication to the pipeline. I have a service that tracks authenticated users. My plan is to, in the first stage of the route, to add a filter that checks to see if the current user is authenticated. If the user is not I want to transform the message into an authentication request and send that to my endpoint. All good so far, however, after authentication (if successful) I want to send the original message down the pipeline. Is this something that can be done? A simplified version of my route would be: ``` from("seda:in"). filter(method(Authentication.class, "isNotAuthenticated")). bean(AuthenticationTransformer.class) to("cxfbean:out") .end() .bean(RequestTransformer.class) .to("cxfbean:out") ``` The same message would be sent to both transformer beans.

Original source