Reputation: 1361
In our project we are planning to use apache camel for web request routing / orchestration.
Its basically a web project talking to several other internal web-services to prepare the final response to the requester.
Can someone suggest, what is the best/standard way to consume the web requests in a camel web application ?
I believe its possible in camel with several options :
It would be really helpful if some has done this before and can guide. Any pointers like pros and cons are also well appreciated.
Note: As I mentioned above, we don't want to have any spring related dependencies in the project.
Upvotes: 4
Views: 2586
Reputation: 7067
Jetty is the simplest way to receive a request from some given URL.
from("jetty:http://localhost:{{port}}/myapp/myservice")
.process() // do something with the Exchange
This is easy to get running however you may end up with some tricky routing rules to differentiate between GETs, POSTs and so on. IMHO multiple paths of execution in a camel route (ie with splits, choices etc) can/will become a trap for the unwary.
Servlets are trickier as you need to write the Servlet implementation and register it in the Servlet container (eg via web.xml) and the result is the same - you get a HTTP request as an exchange.
web.xml
<web-app>
<servlet>
<servlet-name>CamelServlet</servlet-name>
<display-name>Camel Http Transport Servlet</display-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CamelServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
RouteBuilder
from("servlet:///hello?matchOnUriPrefix=true").process(new Processor() {
// do stuff
I dont think there's any advantage to this over the jetty component.
Camel Rest DSL is my pick. It's a simple DSL for describing HTTP endpoints with nice REST semantics, it's clear what the routing rules are and it's relatively succinct. This only works with 2.14 onwards though..
rest("/say")
.get("/hello").to("direct:hello")
.get("/bye").consumes("application/json").to("direct:bye")
.post("/bye").to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
from("direct:bye")
.transform().constant("Bye World");
Upvotes: 4