You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Debraj Manna <su...@gmail.com> on 2016/10/17 13:03:42 UTC

Content Based Routing based on JSON Request Body

Hi

I have a camel REST endpoint which receives a request of the form:-

{"method" : "getHello"}

Based on the value in the method field in the request body I want to route
the request to different routes. So I tried something like this below:-

from("jetty:http://localhost:8888/hello").unmarshal().json(JsonLibrary.
Jackson, RouteRequest.class)

.choice()

.when(method(DynamicRouter.class, "route").isEqualTo("getHello")).to(
"stream:out")

.otherwise()

.log("Processing Failed");


Dynamic Router class is like below:-


public class DynamicRouter {

public String route(RouteRequest req) {

switch (req.getMethod()) {

case "getHello":

return "xxxx";

}

return null;

}

}


Even though I am returning xxxx from route() but the below Predicate is
always evaluating to true and it is never going to .otherwise


isEqualTo("getHello")).to("stream:out")


Can someone let me know what I am doing wrong?


Thanks,