camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonin Stefanutti <anto...@stefanutti.fr>
Subject Re: Camel - CDI and Servlet Context Implementation
Date Mon, 01 Feb 2016 09:26:38 GMT
Hi Tim,

You’ll find an example of using REST DSL with the Servlet component and CDI here:

https://github.com/apache/camel/tree/674b8cd2eb1f2c937121a62fc0ce8cb0df9a4c9f/examples/camel-example-cdi-rest-servlet

That uses the work done at https://github.com/astefanutti/camel-cdi that has recently been
merged into Camel master branch so that it will be part of the upcoming 2.17.0 release.

Let me know if the example needs to be improved.

Antonin

> On 26 Jan 2016, at 18:58, Tim Dudgeon <tdudgeon.ml@gmail.com> wrote:
> 
> I didn't see any answer to this, and have hit the same.
> 
> I've got Camel running in Tomcat using camel-servlet and camel-servletlistener as described
here:
> http://camel.apache.org/servletlistener-component.html
> 
> Also, independently I've used the new camel-cdi stuff found here:
> https://github.com/astefanutti/camel-cdi
> to get a very basic Camel implementation running using CDI e.g. creating a CDI injected
subclass of HttpServlet annotated with @WebServlet.
> 
> But its not clear how to combine the two. In my case I've got routes that use the REST
DSL and are using the camel-servlet component.
> 
> e.g. starting from a RouteBuilder that looks like this:
> 
>    @Inject Something something
> 
>    @Override
>    public void configure() throws Exception {
> 
>        restConfiguration().component("servlet").host("0.0.0.0");
> 
>        rest("/ping")
>                .get()
>                .produces("text/plain")
>                .route()
>                .transform(constant("Ping\n")).endRest();
>    }
> 
> 
> what's the shortest path of travel to get this working e.g. how to define the servlet?
> 
> Thanks
> Tim
> 
> 
> On 19/03/2015 08:02, Naveen Subramanian wrote:
>> Hi,
>> 
>> I have implemented Camel with Servlet implementation using ServletContext.
>> I wish to implement CDI as well (which needs CdiCamelConext).
>> 
>> I am unable to find a way to implement both. Please suggest.
>> 
>> 
>> My web.xml
>> 
>> <context-param>
>> <param-name>routeBuilder-routes</param-name>
>> <param-value>packagescan:com.example.api.routes</param-value>
>> </context-param>
>> 
>> <context-param>
>> <param-name>CamelContextLifecycle</param-name>
>> <param-value>com.example.api.camel.CustomCamelContextLifeCycle</param-value>
>> </context-param>
>> <listener>
>> <listener-class>org.apache.camel.component.servletlistener.SimpleCamelServletContextListener</listener-class>
>> </listener>
>> 
>> 
>> <!-- Servlet mapping -->
>> 
>> <servlet>
>> <display-name>APIServerServlet</display-name>
>> <servlet-name>CamelServlet</servlet-name>
>> <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
>> <load-on-startup>1</load-on-startup>
>> </servlet>
>> 
>> <servlet-mapping>
>> <servlet-name>CamelServlet</servlet-name>
>> <url-pattern>/*</url-pattern>
>> </servlet-mapping>
>> 
>> 
>> 
>> (P.S no Spring )
>> 
> 

Mime
View raw message