Camel endpoint with choice and jsonpath works correctly when tried as an independent endpoint but when I introduce rest endpoint in route configuration choice stops filtering for the content-based routing of messages send from postman. Is there something that I am missing here?
I have tried directly sending the json message to endpoint and it correctly routes. But when adding restConfiguration and try bringing up the route it stops routing or sending to correct methods.
Main class-
static String jsonMsg = "{\n" +
" \"Header\": {\n" +
" \"MessageType\": \"Request1\",\n" +
" \"MessageID\": \"12345\",\n" +
" }\n" +
"}";
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new HelloRoute());
context.start();
//ProducerTemplate producer = context.createProducerTemplate();
//producer.sendBody("direct:helloRoute", jsonMsg);
}
HelloRoute class-
@Override
public void configure() throws Exception {
restConfiguration()
.component("jetty")
.host("0.0.0.0")
.port("9281")
.scheme("http")
.componentProperty("minThreads", "1")
.componentProperty("maxThreads", "16");rest("/helloCamel/").consumes("application/json").produces("application/json").post().to("direct:helloRoute");
from("direct:helloRoute")
.choice()
.when().jsonpath("$.Header[?(@.MessageType == 'Request1')]",true)
.bean(HelloRoute.class, "Route1")
.when().jsonpath("$.Header[?(@.MessageType == 'Request2')]",true)
.bean(HelloRoute.class, "Route2")
.otherwise()
.bean(HelloRoute.class,"otherwiseRoute")
.endChoice();
}
Currently, with rest if above JSON is changed to "MessageType": "Request2" then it jumps to otherwise clause instead of going to the "Route2" method.