reta / jax-rs-2.0-cdi

Apache CXF 3.0 and CDI 1.1
Apache License 2.0
2 stars 5 forks source link

Example for Tomcat8 (not embedded) #3

Closed fuschl closed 9 years ago

fuschl commented 9 years ago

Hi Reta, I did not find any example anywhere how to get CXF 3 / JAX-RS 2 / CDI 1.1 / Tomcat 7/8 (not embedded) working together? I am not sure if is supported at all because an example was left out and this combination was not mentioned on http://cxf.apache.org/docs/using-cxf-and-cdi-11-jsr-346.html.

Thanks, Fuschl

reta commented 9 years ago

Hi Fuschl,

Thanks a lot for bringing up this topic. The not embedded (or WAR-based deployment) requires only web.xml with org.jboss.weld.environment.servlet.Listener and org.apache.cxf.cdi.CXFCdiServlet to be declared, for example:

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <listener>
        <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
    </listener>

    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <display-name>CXF Servlet</display-name>
        <servlet-class>org.apache.cxf.cdi.CXFCdiServlet</servlet-class>    
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <resource-env-ref>
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
    </resource-env-ref>
</web-app>

With that, CXF 3 / JAX-RS 2 / CDI 1.1 / Tomcat 7/8 do work together very well :-) Please let me know if it answers your question. I will be happy to share sample project with you if you need one.

Thank you.

Best Regards, Andriy Redko

fuschl commented 9 years ago

Hi Andriy, a sample project would be highly appreciated! I gave it a try, but got error messages like "Can't find the the request for http://:/mycontextpath/rest/api/people's Observer" Furthermore does this setup require or just allow Servlet API 3.1? I think if it requires it I will have to use Tomcat 8 (see http://tomcat.apache.org/whichversion.html)

Thanks for your helping! Fuschl

reta commented 9 years ago

Hi Fuschl,

I have pushed the branch for you: https://github.com/reta/jax-rs-2.0-cdi/tree/tomcat-war This is ready to be deployed WAR, I have tested it with Tomcat v8.0. It does not really need 3.1 servlet spec and uses 3.0 instead (src/main/webapp/WEB-INF/web.xml).

Please give it a try. Thank you!

Best Regards, Andriy Redko

fuschl commented 9 years ago

Works! Thanks a lot