Search in sources :

Example 1 with BeanManagerResourceBindingListener

use of org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener in project fabric8 by fabric8io.

the class Servers method startServer.

public static Server startServer(String appName, Function<ServletContextHandler, Void> contextCallback, String defaultPort) throws Exception {
    String port = Systems.getEnvVarOrSystemProperty("HTTP_PORT", "HTTP_PORT", defaultPort);
    Integer num = Integer.parseInt(port);
    String service = Systems.getEnvVarOrSystemProperty("WEB_CONTEXT_PATH", "WEB_CONTEXT_PATH", "");
    String servicesPath = "cxf/servicesList";
    String servletContextPath = "/" + service;
    ManagedApi.setSingletonCxfServletContext(servletContextPath);
    String url = "http://localhost:" + port + servletContextPath;
    if (!url.endsWith("/")) {
        url += "/";
    }
    System.out.println();
    System.out.println("-------------------------------------------------------------");
    System.out.println(appName + " is now running at: " + url);
    System.out.println("-------------------------------------------------------------");
    System.out.println();
    final Server server = new Server(num);
    // Register and map the dispatcher servlet
    final ServletHolder servletHolder = new ServletHolder(new CXFCdiServlet());
    // change default service list URI
    servletHolder.setInitParameter("service-list-path", "/" + servicesPath);
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addEventListener(new Listener());
    context.addEventListener(new BeanManagerResourceBindingListener());
    String servletPath = "/*";
    if (Strings.isNotBlank(service)) {
        servletPath = servletContextPath + "/*";
    }
    context.addServlet(servletHolder, servletPath);
    server.setHandler(context);
    EnumSet<DispatcherType> dispatches = EnumSet.allOf(DispatcherType.class);
    context.addFilter(RestCorsFilter.class, "/*", dispatches);
    if (contextCallback != null) {
        contextCallback.apply(context);
    }
    server.start();
    return server;
}
Also used : Listener(org.jboss.weld.environment.servlet.Listener) BeanManagerResourceBindingListener(org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener) Server(org.eclipse.jetty.server.Server) BeanManagerResourceBindingListener(org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType) CXFCdiServlet(org.apache.cxf.cdi.CXFCdiServlet)

Aggregations

DispatcherType (javax.servlet.DispatcherType)1 CXFCdiServlet (org.apache.cxf.cdi.CXFCdiServlet)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 BeanManagerResourceBindingListener (org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener)1 Listener (org.jboss.weld.environment.servlet.Listener)1