Search in sources :

Example 1 with CXFCdiServlet

use of org.apache.cxf.cdi.CXFCdiServlet in project cxf by apache.

the class AbstractJettyServer method run.

protected void run() {
    System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi");
    System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");
    server = new Server(port);
    try {
        if (resourcePath == null) {
            // Register and map the dispatcher servlet
            final ServletHolder servletHolder = new ServletHolder(new CXFCdiServlet());
            final ServletContextHandler context = new ServletContextHandler();
            context.setContextPath(contextPath);
            context.addEventListener(listener);
            context.addServlet(servletHolder, "/rest/*");
            server.setHandler(context);
        } else {
            final WebAppContext context = new WebAppContext();
            context.setContextPath(contextPath);
            context.setWar(getClass().getResource(resourcePath).toURI().getPath());
            context.setServerClasses(new String[] { "org.eclipse.jetty.servlet.ServletContextHandler.Decorator" });
            HandlerCollection handlers = new HandlerCollection();
            handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
            server.setHandler(handlers);
        }
        server.start();
    } catch (final Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) CXFCdiServlet(org.apache.cxf.cdi.CXFCdiServlet) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Aggregations

CXFCdiServlet (org.apache.cxf.cdi.CXFCdiServlet)1 Server (org.eclipse.jetty.server.Server)1 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)1 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1