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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With