Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

 

 

 

 

 

 

 

 

 

Introduction 

The JAX-RS 2.0 specification (JSR-339) mandates the support of CDI and Apache CXF starting from the version 3.0 introduces the initial support of this feature. As the starting point, the emphasis has been done on supporting embedded Jety 8/9 and Tomcat 7/8 containers as primary deployment (though other application servers will be supported in the future). 

...

With Jetty 8/9 it possible to create fully embeddable REST / JAX-RS servers without web.xml or WAR files involved. For Apache CXF applications which are using CDI 1.1, the CXFCdiServlet servlet should be used as a starting point. Following examples example demonstrates the necessary configuration points in order to create embedded   embedded  Jetty 8/9 instance. As a CDI 1.1 implementatoin, JBoss Weld 2.0 is being used.

Code Block
java
java
System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi");
System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");

// Register and map the dispatcher servlet
                final ServletHolder servletHolder = new ServletHolder(new CXFCdiServlet());
                final ServletContextHandler context = new ServletContextHandler();         
                context.setContextPath(contextPath);          
                context.addEventListener(new Listener());         
                context.addEventListener(new BeanManagerResourceBindingListener());
                context.addServlet(servletHolder, "/rest/*");
                server.setHandler(context);

 

 

 

 

 

 

 

 

 

 

);
server.start();

This code snippet is enough to trigger the CDI portable extension discovery and to wire up all dependencies. 

Deploying with embedded Jetty 8/9 (WAR-based deployment) 

...