Search in sources :

Example 1 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class WebSocketCdiInitializer method onStartup.

@Override
public void onStartup(Set<Class<?>> c, ServletContext context) throws ServletException {
    ContextHandler handler = ContextHandler.getContextHandler(context);
    if (handler == null) {
        throw new ServletException("Not running on Jetty, WebSocket+CDI support unavailable");
    }
    if (!(handler instanceof ServletContextHandler)) {
        throw new ServletException("Not running in Jetty ServletContextHandler, WebSocket+CDI support unavailable");
    }
    ServletContextHandler jettyContext = (ServletContextHandler) handler;
    try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader())) {
        addListeners(jettyContext);
    }
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ServletException(javax.servlet.ServletException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ThreadClassLoaderScope(org.eclipse.jetty.util.thread.ThreadClassLoaderScope)

Example 2 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class BalancerServletTest method createServer.

private Server createServer(ServletHolder servletHolder, String nodeName) {
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(server, CONTEXT_PATH, ServletContextHandler.SESSIONS);
    context.addServlet(servletHolder, SERVLET_PATH + "/*");
    if (nodeName != null) {
        DefaultSessionIdManager sessionIdManager = new DefaultSessionIdManager(server);
        sessionIdManager.setWorkerName(nodeName);
        server.setSessionIdManager(sessionIdManager);
    }
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 3 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class ProxyServletTest method startServer.

private void startServer(HttpServlet servlet) throws Exception {
    QueuedThreadPool serverPool = new QueuedThreadPool();
    serverPool.setName("server");
    server = new Server(serverPool);
    serverConnector = new ServerConnector(server);
    server.addConnector(serverConnector);
    ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
    ServletHolder appServletHolder = new ServletHolder(servlet);
    appCtx.addServlet(appServletHolder, "/*");
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 4 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class ReverseProxyTest method startServer.

private void startServer(HttpServlet servlet) throws Exception {
    server = new Server();
    serverConnector = new ServerConnector(server);
    server.addConnector(serverConnector);
    ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
    ServletHolder appServletHolder = new ServletHolder(servlet);
    appCtx.addServlet(appServletHolder, "/*");
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 5 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project jetty.project by eclipse.

the class ProxyServletTest method startProxy.

private void startProxy(Map<String, String> initParams) throws Exception {
    QueuedThreadPool proxyPool = new QueuedThreadPool();
    proxyPool.setName("proxy");
    proxy = new Server(proxyPool);
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendDateHeader(false);
    configuration.setSendServerVersion(false);
    String value = initParams.get("outputBufferSize");
    if (value != null)
        configuration.setOutputBufferSize(Integer.valueOf(value));
    proxyConnector = new ServerConnector(proxy, new HttpConnectionFactory(configuration));
    proxy.addConnector(proxyConnector);
    proxyContext = new ServletContextHandler(proxy, "/", true, false);
    ServletHolder proxyServletHolder = new ServletHolder(proxyServlet);
    proxyServletHolder.setInitParameters(initParams);
    proxyContext.addServlet(proxyServletHolder, "/*");
    proxy.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)390 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)253 Server (org.eclipse.jetty.server.Server)217 ServerConnector (org.eclipse.jetty.server.ServerConnector)98 Test (org.junit.Test)70 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)56 IOException (java.io.IOException)42 HttpServletRequest (javax.servlet.http.HttpServletRequest)39 HttpClient (org.eclipse.jetty.client.HttpClient)39 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)39 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)37 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)37 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)32 Connector (org.eclipse.jetty.server.Connector)29 Request (org.eclipse.jetty.client.api.Request)27 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)24 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)24 ServletException (javax.servlet.ServletException)22 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)22 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)22