1
votes

I'm trying to get Apache Camel's REST DSL working but it's not connecting for me.

I've got a RouteBuilder that's being called:

@Override
public void configure() {
restConfiguration().component("servlet")
      .contextPath("/")
      .enableCORS(true)
      .dataFormatProperty("prettyPrint", "true")
      .apiContextPath("/api-doc")
      .apiProperty("api.version", buildVersion)
      .apiProperty("cors", "true")
      .bindingMode(RestBindingMode.json);

rest("/say/hello")
      .get().route().transform().constant("Hello World");
}

but then the routes don't actually work.

This is inside a Spring Boot app that has other REST endpoints defined via JAX-RS but this is an integration package that I want to be able to keep separate. The weird thing is that this WAS working a few months ago before I had to work on other things, but now, coming back to it, I can't even get this simple endpoint working.

I've got Camel in my Maven pom.xml and everything seems to be starting correctly, but nothing happens when I hit http:://localhost:9071/say/hello, I just get the standard Tomcat 404 page.

Any thoughts on what I'm missing?

1
Have you added your RouteBuilder to CamelContext? - daBigBug
Also watchout for your url http:://localhost:9071/say/hello. It has an extra colon. Removing it might do the trick - daBigBug
Camel REST DSL adds /rest to the URI. Try this instead: http://localhost:9071/rest/say/hello. - Erik Karlstrand
I suspect your route is not added to the camelcontext and hence the 404. See in spring boot if the route is actually "alive". - Souciance Eqdam Rashti
How do you see in Spring Boot if the route is actually "alive"? I know my RouteBuilder is being called because it hits a breakpoint. I also set breakpoints in the CamelServlet class and it's being instantiated and initialized. In its initialization it has the configuration set up in my route builder. - Jason Carreira

1 Answers

4
votes

According to this: http://www.baeldung.com/apache-camel-spring-boot

As of Camel’s version 2.19, this configuration has been dropped as the CamelServlet is by default set to “/camel”.

so /camel/say/hello is the correct URL and it works for me. Still looking at how to customize this.

EDIT:

Here's how to customize this under Spring Boot. You add a property to application.properties like this:

camel.component.servlet.mapping.contextPath=/*