The impact of camel routes as REST services in a web container

I have a Camel route that I would like to open as a REST web service. The application is deployed in a web container (Jetty / Tomcat) and Spring is also used for DI and other "infrastructure" things.

I looked at the components of camel-restlet and camel-cxfrs , and although they both provide support for expanding routes as REST services, I could not learn how to avoid starting a separate server. What I'm really looking for is the ability to define a Camel route in the same way that routes are defined for Spring -WS input endpoints, for example.

 from("restlet://application/user/{id}").to(...) 

The configuration of the web application must take care of accepting the requests and passing them to the corresponding endpoints.

Frankly, I was very surprised that I could not find enough information on this topic, and I do not think that my requirements are very exotic.

+4
source share
2 answers

See this example http://camel.apache.org/cxf-tomcat-example.html

For Apache CXF, you can use the servlet porting, which allows you to use Tomcat / Jetty, which is the host container.

And if you use OSGi, then take a look at this: http://camel.apache.org/cxf-example-osgi.html it shows how to use CXF using the OSGi HTTP service, which should also work for CXFRS.

+5
source

This is a late answer, but may help others.

Apache Camel now has support for publishing the Restlet web service using a host container (e.g. Tomcat / Jetty)

=============== 8 <snip snip ==========================

Using the Restlet servlet inside webapp

Available on Camel 2.8 There are three possible ways to configure the Restlet application in the servlet container, and using the SpringServerServlet subclass allows you to configure in Camel by introducing the Restlet component. Using the Restlet servlet in the servlet container allows routes to be configured with relative paths in the URI (removing restrictions on hard-coded absolute URIs) and for the hosting servlet container to handle incoming requests (instead of creating a separate server process on the new port). To customize, add the following to your camel-context.xml;

 <camelContext> <route id="RS_RestletDemo"> <from uri="restlet:/demo/{id}" /> <transform> <simple>Request type : ${header.CamelHttpMethod} and ID : ${header.id}</simple> </transform> </route> </camelContext> <bean id="RestletComponent" class="org.restlet.Component" /> <bean id="RestletComponentService" class="org.apache.camel.component.restlet.RestletComponent"> <constructor-arg index="0"> <ref bean="RestletComponent" /> </constructor-arg> </bean> And add this to your web.xml; <!-- Restlet Servlet --> <servlet> <servlet-name>RestletServlet</servlet-name> <servlet-class>org.restlet.ext.spring.SpringServerServlet</servlet-class> <init-param> <param-name>org.restlet.component</param-name> <param-value>RestletComponent</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>RestletServlet</servlet-name> <url-pattern>/rs/*</url-pattern> </servlet-mapping> 

Then you can access the expanded route in

 http://localhost:8080/mywebapp/rs/demo/1234 where localhost:8080 is the server and port of your servlet container 

=============== snip snip> 8 ==========================

This information was found at the bottom of http://camel.apache.org/restlet.html dated January 16, 2014.

+3
source

Source: https://habr.com/ru/post/1348127/


All Articles