Search in sources :

Example 1 with FilterHolder

use of org.mortbay.jetty.servlet.FilterHolder in project dubbo by alibaba.

the class JettyContainer method start.

public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletHandler(org.mortbay.jetty.servlet.ServletHandler) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Example 2 with FilterHolder

use of org.mortbay.jetty.servlet.FilterHolder in project incubator-dubbo-ops by apache.

the class JettyContainer method start.

public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
Also used : SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) ServletHandler(org.mortbay.jetty.servlet.ServletHandler) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Example 3 with FilterHolder

use of org.mortbay.jetty.servlet.FilterHolder in project nutch by apache.

the class NutchUiServer method startServer.

private static void startServer() throws Exception, InterruptedException {
    Server server = new Server(port);
    Context context = new Context(server, "/", Context.SESSIONS);
    context.addServlet(DefaultServlet.class, "/*");
    context.addEventListener(new ContextLoaderListener(getContext()));
    context.addEventListener(new RequestContextListener());
    WicketFilter filter = new WicketFilter();
    filter.setFilterPath("/");
    FilterHolder holder = new FilterHolder(filter);
    holder.setInitParameter("applicationFactoryClassName", APP_FACTORY_NAME);
    context.addFilter(holder, "/*", Handler.DEFAULT);
    server.setHandler(context);
    server.start();
    server.join();
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) Context(org.mortbay.jetty.servlet.Context) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) RequestContextListener(org.springframework.web.context.request.RequestContextListener) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) WicketFilter(org.apache.wicket.protocol.http.WicketFilter) ContextLoaderListener(org.springframework.web.context.ContextLoaderListener)

Example 4 with FilterHolder

use of org.mortbay.jetty.servlet.FilterHolder in project incubator-myriad by apache.

the class MyriadWebServer method start.

public void start() throws Exception {
    this.jetty.addConnector(connector);
    ServletHandler servletHandler = new ServletHandler();
    String filterName = "MyriadGuiceFilter";
    FilterHolder holder = new FilterHolder(filter);
    holder.setName(filterName);
    FilterMapping filterMapping = new FilterMapping();
    filterMapping.setPathSpec("/*");
    filterMapping.setDispatches(Handler.ALL);
    filterMapping.setFilterName(filterName);
    servletHandler.addFilter(holder, filterMapping);
    Context context = new Context();
    context.setServletHandler(servletHandler);
    context.addServlet(DefaultServlet.class, "/");
    String staticDir = this.getClass().getClassLoader().getResource("webapp/public").toExternalForm();
    context.setResourceBase(staticDir);
    this.jetty.addHandler(context);
    this.jetty.start();
}
Also used : Context(org.mortbay.jetty.servlet.Context) ServletHandler(org.mortbay.jetty.servlet.ServletHandler) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) FilterMapping(org.mortbay.jetty.servlet.FilterMapping)

Example 5 with FilterHolder

use of org.mortbay.jetty.servlet.FilterHolder in project registry by hortonworks.

the class AuthenticatorTestCase method startJetty.

protected void startJetty() throws Exception {
    server = new Server(0);
    context = new Context();
    context.setContextPath("/foo");
    server.setHandler(context);
    context.addFilter(new FilterHolder(TestFilter.class), "/*", 0);
    context.addServlet(new ServletHolder(TestServlet.class), "/bar");
    host = "localhost";
    port = getLocalPort();
    server.getConnectors()[0].setHost(host);
    server.getConnectors()[0].setPort(port);
    server.start();
    System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}
Also used : Context(org.mortbay.jetty.servlet.Context) FilterHolder(org.mortbay.jetty.servlet.FilterHolder) Server(org.mortbay.jetty.Server) ServletHolder(org.mortbay.jetty.servlet.ServletHolder)

Aggregations

FilterHolder (org.mortbay.jetty.servlet.FilterHolder)6 Server (org.mortbay.jetty.Server)4 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)4 Context (org.mortbay.jetty.servlet.Context)3 ServletHandler (org.mortbay.jetty.servlet.ServletHandler)3 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)2 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 WicketFilter (org.apache.wicket.protocol.http.WicketFilter)1 FilterMapping (org.mortbay.jetty.servlet.FilterMapping)1 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 RequestContextListener (org.springframework.web.context.request.RequestContextListener)1 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)1