Search in sources :

Example 26 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project sonarqube by SonarSource.

the class SSLTest method newServletHandler.

private static ServletHandler newServletHandler() {
    ServletHandler handler = new ServletHandler();
    ServletHolder holder = handler.addServletWithMapping(ProxyServlet.Transparent.class, "/*");
    holder.setInitParameter("proxyTo", orchestrator.getServer().getUrl());
    return handler;
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ProxyServlet(org.eclipse.jetty.proxy.ProxyServlet)

Example 27 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project hadoop by apache.

the class HttpServer2 method addInternalServlet.

/**
   * Add an internal servlet in the server, specifying whether or not to
   * protect with Kerberos authentication.
   * Note: This method is to be used for adding servlets that facilitate
   * internal communication and not for user facing functionality. For
   * servlets added using this method, filters (except internal Kerberos
   * filters) are not enabled.
   *
   * @param name The name of the servlet (can be passed as null)
   * @param pathSpec The path spec for the servlet
   * @param clazz The servlet class
   * @param requireAuth Require Kerberos authenticate to access servlet
   */
public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) {
    ServletHolder holder = new ServletHolder(clazz);
    if (name != null) {
        holder.setName(name);
    }
    // Jetty doesn't like the same path spec mapping to different servlets, so
    // if there's already a mapping for this pathSpec, remove it and assume that
    // the newest one is the one we want
    final ServletMapping[] servletMappings = webAppContext.getServletHandler().getServletMappings();
    for (int i = 0; i < servletMappings.length; i++) {
        if (servletMappings[i].containsPathSpec(pathSpec)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found existing " + servletMappings[i].getServletName() + " servlet at path " + pathSpec + "; will replace mapping" + " with " + holder.getName() + " servlet");
            }
            ServletMapping[] newServletMappings = ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
            webAppContext.getServletHandler().setServletMappings(newServletMappings);
            break;
        }
    }
    webAppContext.addServlet(holder, pathSpec);
    if (requireAuth && UserGroupInformation.isSecurityEnabled()) {
        LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
        ServletHandler handler = webAppContext.getServletHandler();
        FilterMapping fmap = new FilterMapping();
        fmap.setPathSpec(pathSpec);
        fmap.setFilterName(SPNEGO_FILTER);
        fmap.setDispatches(FilterMapping.ALL);
        handler.addFilterMapping(fmap);
    }
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) FilterMapping(org.eclipse.jetty.servlet.FilterMapping)

Example 28 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project hadoop by apache.

the class HttpServer2 method defineFilter.

/**
   * Define a filter for a context and set up default url mappings.
   */
private static void defineFilter(ServletContextHandler ctx, FilterHolder holder, FilterMapping fmap) {
    ServletHandler handler = ctx.getServletHandler();
    handler.addFilter(holder, fmap);
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler)

Example 29 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project hadoop by apache.

the class HttpServer2 method addFilterPathMapping.

/**
   * Add the path spec to the filter path mapping.
   * @param pathSpec The path spec
   * @param webAppCtx The WebApplicationContext to add to
   */
protected void addFilterPathMapping(String pathSpec, ServletContextHandler webAppCtx) {
    ServletHandler handler = webAppCtx.getServletHandler();
    for (String name : filterNames) {
        FilterMapping fmap = new FilterMapping();
        fmap.setPathSpec(pathSpec);
        fmap.setFilterName(name);
        fmap.setDispatches(FilterMapping.ALL);
        handler.addFilterMapping(fmap);
    }
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) FilterMapping(org.eclipse.jetty.servlet.FilterMapping)

Example 30 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project jackrabbit-oak by apache.

the class RemoteServer method createHandler.

private Handler createHandler(RemoteRepository repository) {
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new RemoteServlet(repository)), "/*");
    return handler;
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) RemoteServlet(org.apache.jackrabbit.oak.remote.http.RemoteServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Aggregations

ServletHandler (org.eclipse.jetty.servlet.ServletHandler)54 Server (org.eclipse.jetty.server.Server)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)22 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)8 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InetSocketAddress (java.net.InetSocketAddress)3 HttpServlet (javax.servlet.http.HttpServlet)3 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2