Search in sources :

Example 41 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler 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 42 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler 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)

Example 43 with DefaultHandler

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

the class AsyncContextTest method setUp.

@Before
public void setUp() throws Exception {
    _server = new Server();
    _connector = new LocalConnector(_server);
    _connector.setIdleTimeout(5000);
    _connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setSendDateHeader(false);
    _server.addConnector(_connector);
    _contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    _contextHandler.setContextPath("/ctx");
    _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/servletPath");
    _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/path with spaces/servletPath");
    _contextHandler.addServlet(new ServletHolder(new TestServlet2()), "/servletPath2");
    _contextHandler.addServlet(new ServletHolder(new TestStartThrowServlet()), "/startthrow/*");
    _contextHandler.addServlet(new ServletHolder(new ForwardingServlet()), "/forward");
    _contextHandler.addServlet(new ServletHolder(new AsyncDispatchingServlet()), "/dispatchingServlet");
    _contextHandler.addServlet(new ServletHolder(new ExpireServlet()), "/expire/*");
    _contextHandler.addServlet(new ServletHolder(new BadExpireServlet()), "/badexpire/*");
    _contextHandler.addServlet(new ServletHolder(new ErrorServlet()), "/error/*");
    ErrorPageErrorHandler error_handler = new ErrorPageErrorHandler();
    _contextHandler.setErrorHandler(error_handler);
    error_handler.addErrorPage(500, "/error/500");
    error_handler.addErrorPage(IOException.class.getName(), "/error/IOE");
    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) Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) IOException(java.io.IOException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) Before(org.junit.Before)

Example 44 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler in project metrics by dropwizard.

the class InstrumentedHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    handler.setName("handler");
    handler.setHandler(new DefaultHandler());
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
    client.start();
}
Also used : DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) Before(org.junit.Before)

Example 45 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler in project blade by biezhi.

the class EmbedJettyServer method startup.

@Override
public void startup(int port, String contextPath, String webRoot) throws EmbedServerException {
    this.port = port;
    Config config = Blade.$().config();
    int minThreads = config.getInt("server.jetty.min-threads", 8);
    int maxThreads = config.getInt("server.jetty.max-threads", 200);
    String poolName = config.get("server.jetty.pool-name", "blade-pool");
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(minThreads);
    threadPool.setMaxThreads(maxThreads);
    threadPool.setName(poolName);
    this.server = new org.eclipse.jetty.server.Server(threadPool);
    this.webAppContext = new WebAppContext();
    this.webAppContext.setContextPath(contextPath);
    this.webAppContext.setResourceBase("");
    int securePort = config.getInt("server.jetty.http.secure-port", 9443);
    int outputBufferSize = config.getInt("server.jetty.http.output-buffersize", 32 * 1024);
    int requestHeaderSize = config.getInt("server.jetty.http.request-headersize", 8 * 1024);
    int responseHeaderSize = config.getInt("server.jetty.http.response-headersize", 8 * 1024);
    // HTTP Configuration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecurePort(securePort);
    http_config.setOutputBufferSize(outputBufferSize);
    http_config.setRequestHeaderSize(requestHeaderSize);
    http_config.setResponseHeaderSize(responseHeaderSize);
    long idleTimeout = config.getLong("server.jetty.http.idle-timeout", 30000L);
    String host = config.get("server.host", "0.0.0.0");
    ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(http_config));
    serverConnector.setHost(host);
    serverConnector.setPort(this.port);
    serverConnector.setIdleTimeout(idleTimeout);
    server.setConnectors(new Connector[] { serverConnector });
    boolean isAsync = config.getBoolean("server.async", false);
    Class<? extends Servlet> servlet = isAsync ? AsyncDispatcherServlet.class : DispatcherServlet.class;
    ServletHolder servletHolder = new ServletHolder(servlet);
    servletHolder.setAsyncSupported(isAsync);
    servletHolder.setInitOrder(1);
    webAppContext.addEventListener(new BladeInitListener());
    Set<String> statics = Blade.$().bConfig().getStatics();
    defaultHolder = new ServletHolder(DefaultServlet.class);
    defaultHolder.setInitOrder(0);
    if (StringKit.isNotBlank(classPath)) {
        LOGGER.info("add classpath : {}", classPath);
        defaultHolder.setInitParameter("resourceBase", classPath);
    }
    statics.forEach(s -> {
        if (s.indexOf(".") != -1) {
            webAppContext.addServlet(defaultHolder, s);
        } else {
            s = s.endsWith("/") ? s + '*' : s + "/*";
            webAppContext.addServlet(defaultHolder, s);
        }
    });
    webAppContext.addServlet(defaultHolder, "/favicon.ico");
    webAppContext.addServlet(servletHolder, "/");
    try {
        this.loadServlets(webAppContext);
        this.loadFilters(webAppContext);
        HandlerList handlerList = new HandlerList();
        handlerList.setHandlers(new Handler[] { webAppContext, new DefaultHandler() });
        server.setHandler(handlerList);
        server.setStopAtShutdown(true);
        server.start();
        LOGGER.info("Blade Server Listen on {}:{}", host, this.port);
        server.join();
    } catch (Exception e) {
        throw new EmbedServerException(e);
    }
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) org.eclipse.jetty.server(org.eclipse.jetty.server) EmbedServerException(com.blade.exception.EmbedServerException) Config(com.blade.kit.base.Config) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) BladeInitListener(com.blade.mvc.context.BladeInitListener) EmbedServerException(com.blade.exception.EmbedServerException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Aggregations

DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)63 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)44 Server (org.eclipse.jetty.server.Server)29 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)26 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)19 URISyntaxException (java.net.URISyntaxException)18 ServerConnector (org.eclipse.jetty.server.ServerConnector)17 HandlerList (org.eclipse.jetty.server.handler.HandlerList)17 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)15 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)13 Handler (org.eclipse.jetty.server.Handler)10 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)10 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)8 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 Test (org.junit.Test)8 File (java.io.File)7 URI (java.net.URI)7 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7