Search in sources :

Example 26 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project killbill by killbill.

the class HttpServer method configure.

public void configure(final HttpServerConfig config, final Iterable<EventListener> eventListeners, final Map<FilterHolder, String> filterHolders) {
    server.setStopAtShutdown(true);
    // Setup JMX
    configureJMX(ManagementFactory.getPlatformMBeanServer());
    // HTTP Configuration
    final HttpConfiguration httpConfiguration = new HttpConfiguration();
    httpConfiguration.setSecurePort(config.getServerSslPort());
    // Configure main connector
    final ServerConnector http = configureMainConnector(httpConfiguration, config.isJettyStatsOn(), config.getServerHost(), config.getServerPort());
    // Configure SSL, if enabled
    final ServerConnector https;
    if (config.isSSLEnabled()) {
        https = configureSslConnector(httpConfiguration, config.isJettyStatsOn(), config.getServerSslPort(), config.getSSLkeystoreLocation(), config.getSSLkeystorePassword());
        server.setConnectors(new Connector[] { http, https });
    } else {
        server.setConnectors(new Connector[] { http });
    }
    // Configure the thread pool
    configureThreadPool(config);
    // Configure handlers
    final HandlerCollection handlers = new HandlerCollection();
    final ServletContextHandler servletContextHandler = createServletContextHandler(config.getResourceBase(), eventListeners, filterHolders);
    handlers.addHandler(servletContextHandler);
    final RequestLogHandler logHandler = createLogHandler(config);
    handlers.addHandler(logHandler);
    final HandlerList rootHandlers = new HandlerList();
    rootHandlers.addHandler(handlers);
    server.setHandler(rootHandlers);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 27 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.

the class WebAppContextTest method testContextWhiteList.

/**
     * tests that the servlet context white list works
     *
     * @throws Exception on test failure
     */
@Test
public void testContextWhiteList() throws Exception {
    Server server = new Server(0);
    HandlerList handlers = new HandlerList();
    WebAppContext contextA = new WebAppContext(".", "/A");
    contextA.addServlet(ServletA.class, "/s");
    handlers.addHandler(contextA);
    WebAppContext contextB = new WebAppContext(".", "/B");
    contextB.addServlet(ServletB.class, "/s");
    contextB.setContextWhiteList(new String[] { "/doesnotexist", "/B/s" });
    handlers.addHandler(contextB);
    server.setHandler(handlers);
    server.start();
    // context A should be able to get both A and B servlet contexts
    Assert.assertNotNull(contextA.getServletHandler().getServletContext().getContext("/A/s"));
    Assert.assertNotNull(contextA.getServletHandler().getServletContext().getContext("/B/s"));
    // context B has a contextWhiteList set and should only be able to get ones that are approved
    Assert.assertNull(contextB.getServletHandler().getServletContext().getContext("/A/s"));
    Assert.assertNotNull(contextB.getServletHandler().getServletContext().getContext("/B/s"));
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) Test(org.junit.Test)

Example 28 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.

the class FastFileServer method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { new FastFileHandler(new File(System.getProperty("user.dir"))), new DefaultHandler() });
    server.setHandler(handlers);
    server.start();
    server.join();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 29 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.

the class AliasedConstraintTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    connector = new LocalConnector(server);
    server.setConnectors(new Connector[] { connector });
    ContextHandler context = new ContextHandler();
    SessionHandler session = new SessionHandler();
    TestLoginService loginService = new TestLoginService(TEST_REALM);
    loginService.putUser("user0", new Password("password"), new String[] {});
    loginService.putUser("user", new Password("password"), new String[] { "user" });
    loginService.putUser("user2", new Password("password"), new String[] { "user" });
    loginService.putUser("admin", new Password("password"), new String[] { "user", "administrator" });
    loginService.putUser("user3", new Password("password"), new String[] { "foo" });
    context.setContextPath("/ctx");
    context.setResourceBase(MavenTestingUtils.getTestResourceDir("docroot").getAbsolutePath());
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
    server.setHandler(handlers);
    context.setHandler(session);
    // context.addAliasCheck(new AllowSymLinkAliasChecker());
    server.addBean(loginService);
    security = new ConstraintSecurityHandler();
    session.setHandler(security);
    ResourceHandler handler = new ResourceHandler();
    security.setHandler(handler);
    List<ConstraintMapping> constraints = new ArrayList<>();
    Constraint constraint0 = new Constraint();
    constraint0.setAuthenticate(true);
    constraint0.setName("forbid");
    ConstraintMapping mapping0 = new ConstraintMapping();
    mapping0.setPathSpec("/forbid/*");
    mapping0.setConstraint(constraint0);
    constraints.add(mapping0);
    Set<String> knownRoles = new HashSet<>();
    knownRoles.add("user");
    knownRoles.add("administrator");
    security.setConstraintMappings(constraints, knownRoles);
    server.start();
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) Constraint(org.eclipse.jetty.util.security.Constraint) LocalConnector(org.eclipse.jetty.server.LocalConnector) ArrayList(java.util.ArrayList) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) Matchers.containsString(org.hamcrest.Matchers.containsString) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Password(org.eclipse.jetty.util.security.Password) HashSet(java.util.HashSet) BeforeClass(org.junit.BeforeClass)

Example 30 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.

the class AsyncContextDispatchWithQueryStrings method setUp.

@Before
public void setUp() throws Exception {
    _connector.setIdleTimeout(30000);
    _server.setConnectors(new Connector[] { _connector });
    _contextHandler.setContextPath("/");
    _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/initialCall");
    _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/firstDispatchWithNewQueryString");
    _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/secondDispatchNewValueForExistingQueryString");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { _contextHandler, new DefaultHandler() });
    _server.setHandler(handlers);
    _server.start();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) Before(org.junit.Before)

Aggregations

HandlerList (org.eclipse.jetty.server.handler.HandlerList)40 Server (org.eclipse.jetty.server.Server)22 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)13 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)11 Handler (org.eclipse.jetty.server.Handler)9 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)9 IOException (java.io.IOException)7 ServerConnector (org.eclipse.jetty.server.ServerConnector)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 File (java.io.File)5 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)5 ServletException (javax.servlet.ServletException)4 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 URI (java.net.URI)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)3