Maybe this helps:
public class MapMessageTest extends CamelTestSupport {
private Map<String, Object> createMap(String option) {
Map<String,Object> map = new HashMap<String, Object>();
map.put("OPTION", option);
map.put("text", "Hello " + option);
return map;
}
@Test
public void isMap() throws InterruptedException {
template.sendBody("direct:in", createMap("does not
matter"));
}
@Test
public void isNotMap() throws InterruptedException {
template.sendBody("direct:in", "just string");
}
@Test
public void optionC() {
template.sendBody("direct:in", createMap("C"));
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
private Processor transformMessage = new Processor()
{
@Override
public void process(Exchange exchange)
throws Exception {
Map<String,Object> newBody = new
HashMap<String, Object>();
newBody.put("account_ID", "1234");
exchange.getIn().setBody(newBody);
System.out.println("-- process --");
}
};
@Override
public void configure() throws Exception {
// General check: right message type?
from("direct:in")
.choice()
.when().simple("${body} is
'java.util.Map'")
.to("direct:valid")
.otherwise()
.setHeader("type").constant("otherwise")
.to("direct:invalid")
.end();
// Ok, now route according to the chosen
option
from("direct:valid")
.choice()
.when(isOption("C")).to("direct:optionC")
.otherwise().to("direct:process")
.end();
// Final processing
from("direct:invalid").to("stream:err");
from("direct:optionC")
.process(transformMessage)
.to("direct:process");
from("direct:process").to("stream:out");
}
private Predicate isOption(final String
exptectedOptionValue) {
return new Predicate() {
@Override
public boolean matches(Exchange
exchange) {
Object option =
exchange.getIn().getBody(Map.class).get("OPTION");
return option != null &&
option.equals(exptectedOptionValue);
}
};
}
};
}
}
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[email protected]]
> Gesendet: Montag, 30. September 2013 11:35
> An: [email protected]
> Betreff: Re: AW: Camel Routing using map message help required
>
>
> Please provide some example...
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-
> Routing-using-map-message-help-required-tp5740305p5740469.html
> Sent from the Camel - Users mailing list archive at Nabble.com.