Search in sources :

Example 66 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project spring-boot by spring-projects.

the class EmbeddedJarStarter method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(SpringConfiguration.class);
    DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext);
    context.addServlet(new ServletHolder(dispatcherServlet), "/*");
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 67 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project async-http-client by AsyncHttpClient.

the class RetryNonBlockingIssue method setUpGlobal.

@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
    server = new Server();
    ServerConnector connector = addHttpConnector(server);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addServlet(new ServletHolder(new MockExceptionServlet()), "/*");
    server.setHandler(context);
    server.start();
    port1 = connector.getLocalPort();
}
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) BeforeClass(org.testng.annotations.BeforeClass)

Example 68 with ServletContextHandler

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

the class ServerManager method addServlet.

public void addServlet(String path, Class<? extends Servlet> servlet, Map<String, String> initParameters) {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(path);
    ServletHolder holder = new ServletHolder(servlet);
    holder.setInitParameters(initParameters);
    context.addServlet(holder, path);
    handlers.add(context);
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 69 with ServletContextHandler

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

the class WebSocketPlugin method initializePlugin.

@Override
public void initializePlugin(final PluginManager manager, final File pluginDirectory) {
    if (Boolean.valueOf(JiveGlobals.getBooleanProperty(HttpBindManager.HTTP_BIND_ENABLED, true))) {
        Log.info(String.format("Initializing websocket plugin"));
        try {
            ContextHandlerCollection contexts = HttpBindManager.getInstance().getContexts();
            contextHandler = new ServletContextHandler(contexts, "/ws", ServletContextHandler.SESSIONS);
            contextHandler.addServlet(new ServletHolder(this), "/*");
        } catch (Exception e) {
            Log.error("Failed to start websocket plugin", e);
        }
    } else {
        Log.warn("Failed to start websocket plugin; http-bind is disabled");
    }
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 70 with ServletContextHandler

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

the class JettyServer method makeContext.

private ContextHandler makeContext(final String contextPath, final JettyEnv env, final Config cfg) {
    final ServletContextHandler app = new ServletContextHandler();
    // This enables the use of sessions in Jetty, feature available
    // for Gerrit plug-ins to enable user-level sessions.
    //
    app.setSessionHandler(new SessionHandler());
    app.setErrorHandler(new HiddenErrorHandler());
    // This is the path we are accessed by clients within our domain.
    //
    app.setContextPath(contextPath);
    // HTTP front-end filters to be used as surrogate of Apache HTTP
    // reverse-proxy filtering.
    // It is meant to be used as simpler tiny deployment of custom-made
    // security enforcement (Security tokens, IP-based security filtering, others)
    String[] filterClassNames = cfg.getStringList("httpd", null, "filterClass");
    for (String filterClassName : filterClassNames) {
        try {
            @SuppressWarnings("unchecked") Class<? extends Filter> filterClass = (Class<? extends Filter>) Class.forName(filterClassName);
            Filter filter = env.webInjector.getInstance(filterClass);
            app.addFilter(new FilterHolder(filter), "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
        } catch (Throwable e) {
            String errorMessage = "Unable to instantiate front-end HTTP Filter " + filterClassName;
            log.error(errorMessage, e);
            throw new IllegalArgumentException(errorMessage, e);
        }
    }
    // Perform the same binding as our web.xml would do, but instead
    // of using the listener to create the injector pass the one we
    // already have built.
    //
    GuiceFilter filter = env.webInjector.getInstance(GuiceFilter.class);
    app.addFilter(new FilterHolder(filter), "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    app.addEventListener(new GuiceServletContextListener() {

        @Override
        protected Injector getInjector() {
            return env.webInjector;
        }
    });
    // Jetty requires at least one servlet be bound before it will
    // bother running the filter above. Since the filter has all
    // of our URLs except the static resources, the only servlet
    // we need to bind is the default static resource servlet from
    // the Jetty container.
    //
    final ServletHolder ds = app.addServlet(DefaultServlet.class, "/");
    ds.setInitParameter("dirAllowed", "false");
    ds.setInitParameter("redirectWelcome", "false");
    ds.setInitParameter("useFileMappedBuffer", "false");
    ds.setInitParameter("gzip", "true");
    app.setWelcomeFiles(new String[0]);
    return app;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) GuiceFilter(com.google.inject.servlet.GuiceFilter) Filter(javax.servlet.Filter) GuiceFilter(com.google.inject.servlet.GuiceFilter) Injector(com.google.inject.Injector) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) GuiceServletContextListener(com.google.inject.servlet.GuiceServletContextListener)

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