How to get original message?
sanya.sokolov Aug 31, 2011 4:19 AMHi,
I run into problem getting original body/message from route on exception/completion.
The flow is like:
- get message from source
- transform
- split
- an exception occurcs during processing parts
- catch exception and log original message as it came from source
Here is the test describing this behaviour:
public class TestSplitterAggregator extends CamelTestSupport {
@Produce(uri = "direct:start")
protected ProducerTemplate templ;
@Test
public void testFreshTrades() throws Exception {
templ.sendBody("ORIGINAL");
}
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
onCompletion().process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("Original Body after completion: " + exchange.getUnitOfWork().getOriginalInMessage().getBody());
}
});
onException(Exception.class).handled(true)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("Original Body after exception: " + exchange.getUnitOfWork().getOriginalInMessage().getBody());
}
});
from("direct:start").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Processor1");
System.out.println("Processor1: Original Body " + exchange.getUnitOfWork().getOriginalInMessage().getBody());
}
})
.split().method(new Splitter(), "split").stopOnException()
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
if ("Part2".equals(exchange.getIn().getBody(String.class)))
throw new Exception("Exception!");
System.out.println("Processor2: Original Body " + exchange.getUnitOfWork().getOriginalInMessage().getBody());
exchange.getIn().setBody("Processor2");
}
}).end();
}
};
}
public static class Splitter {
public List split() {
return Arrays.asList(new String[] {"Part1", "Part2", "Part3"});
}
};
}
-
The output:
Processor1: Original Body ORIGINAL
Processor2: Original Body Part1
Original Body after exception: Part2
Original Body after completion: Part2
-
used Camel 2.6
Is there a way to get original message (e.g. ORIGINAL) after route completed/failed?