Search code examples
spring-bootapache-camel

Apache Camel Rest endpoint with DSL in Spring Boot adds /camel to the path


I'm trying to build a module to plug into a Spring Boot application. This module should expose some REST endpoints and I'm trying out building them with Camel because I don't want to have to add things to web.xml, etc.

restConfiguration().component("servlet")
      .contextPath("/my")
      .apiContextPath("/api-doc")
      .apiProperty("api.title", "My REST API")
      .apiProperty("cors", "true")
      .apiContextRouteId("my-api")
      .bindingMode(RestBindingMode.json);

rest("/my").description("My REST Services")
      .get("foo/{id}").route().routeId("foo")
      .to("direct:foo");

from("direct:foo")
      .process(new FooParamParser())
      .log("Done");

The problem I'm having is that instead of being at /my/foo/123?status=abc I have to hit it at /camel/my/foo/123?status=abc.

It's doing this because it's defaulting to using the Camel Servlet as the REST endpoint from the DSL, and I'm fine with that, but I don't want it to put the "/camel" at the start of my path. I should note that this behavior is the same with or without the .component("servlet")

Any way to change that?


Solution

  • You can control this in your application.properties or application.yml

    e.g

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

    Reference https://github.com/apache/camel/blob/master/examples/camel-example-spring-boot-rest-jpa/src/main/resources/application.yml