I'm trying to setup a Camel Rest service in Wildfly Swarm and I'm not sure how the RouteBuilder
class gets instantiated, or even how the CamelContext
is instantiated. I've downloaded the Wildfly Swarm examples and had a look at the Camel CXF-JAXRS project, which makes sense, but it uses XML to define the route. I'd like to use Java DSL. My RouteBuilder
class looks like this:
public class GreetingService extends RouteBuilder {
@Override
public void configure() {
System.out.println("RouteBuilder.configure");
restConfiguration().host("localhost").port("9797");
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");
}
}
I have tried this with and without the camel-context.xml
file. Swarm start up, but I can't browse to the rest service endpoint.
How does the RouteBuilder
get called? Should I have some sort of main
method that instantiates the CamelContext
?
I am using Widlfy Swarm 2017.8.1 and the class is in a war
file.
You can add this listener in your web.xml to bootstrap camel.
org.apache.camel.component.servletlistener.SimpleCamelServletContextListener
Or you can use spring to define camel context