camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Debraj Manna <subharaj.ma...@gmail.com>
Subject Content Based Routing based on JSON Request Body
Date Mon, 17 Oct 2016 13:03:42 GMT
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,

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message