Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 741
Jason Carreira Avatar asked Oct 17 '17 19:10

Jason Carreira


People also ask

What is endpoint in Apache Camel?

Camel supports the Message Endpoint pattern using the Endpoint interface. Endpoints are created by a Component and these endpoints are referred to in the DSL via their endpoint URIs.

What is DSL in Camel?

Camel uses a Java Domain Specific Language or DSL for creating Enterprise Integration Patterns or Routes in a variety of domain-specific languages (DSL) as listed below: Java DSL - A Java based DSL using the fluent builder style.

How does Apache Camel route work?

A route in Apache Camel is a sequence of steps, executed in order by Camel, that consume and process a message. A Camel route starts with a consumer, and is followed by a chain of endpoints and processors. So firstly, a route receives a message, using a consumer – perhaps from a file on disk, or a message queue.


1 Answers

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

like image 159
ltsallas Avatar answered Oct 29 '22 11:10

ltsallas