1
votes

Using Camel 2.19.3 REST DSL with Spring Boot

We want a Camel route to listen on the endpoint /myservice

(note, No base path like /rest/myservice or /camel/myservice)

Meanwhile, we also want the Spring Boot actuator endpoints to work, e.g. /health

Is there a way to do this, if we use Camel Servlet as the component?

Our web.xml does not work with:

<servlet>
    <servlet-name>CamelServlet</servlet-name>
    <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>CamelServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping> 

The Camel REST service works, but the Spring actuator endpoints do not.

1

1 Answers

3
votes

You can make a bean of CamelServlet. In this case it will be picked up and regestered to the servlet container.

You can register servlets from annotation-based configuration using ServletRegistrationBean.

@Bean
public ServletRegistrationBean camelServletRegistrationBean(){
    return new ServletRegistrationBean(new CamelHttpTransportServlet(),"/*");
}

But in both cases the servlet will be regestered in the servlet container and the routing to the servlet will be handled by that servlet container. Spring will not decide whether to process a request with actuator or forward it to the camel servlet because the choise between CamelHttpTransportServlet and DispatcherServlet (Spring) will be made before the request is handed to the DispatcherServlet (Spring).

Hence the servlet mapping should be different at the servlet container level. If you mapp both of servlets to the root (<url-pattern>/</url-pattern>), the servlet container will not be able to decide which request should go to which servlet.