Search in sources :

Example 56 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project druid by druid-io.

the class AsyncQueryForwardingServletTest method makeTestDeleteServer.

private static Server makeTestDeleteServer(int port, final CountDownLatch latch) {
    Server server = new Server(port);
    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new HttpServlet() {

        @Override
        protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
            latch.countDown();
            resp.setStatus(200);
        }
    }), "/default/*");
    server.setHandler(handler);
    return server;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 57 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project keycloak by keycloak.

the class JettyAppServer method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    log.info("Deploying archive " + archive.getName());
    if (!(archive instanceof WebArchive)) {
        throw new IllegalArgumentException("JettyContainer only supports WebArchives.");
    }
    WebArchive webArchive = (WebArchive) archive;
    try {
        KeycloakAdapterApp app = appProvider.createApp(webArchive);
        WebAppContext webAppContext = (WebAppContext) app.getContextHandler();
        addAdditionalConfigurations(webAppContext);
        setContextRoot(webArchive, app, webAppContext);
        if (app.usesOIDCAuthenticator()) {
            addOIDCAuthenticator(webAppContext);
        }
        if (app.usesSAMLAuthenticator()) {
            addSAMLAuthenticator(webAppContext);
        }
        if (app.usesJaxrs()) {
            addRestEasyServlet(webArchive, webAppContext);
        }
        setEmbeddedClassloaderForDeployment(webAppContext);
        deployer.addApp(app);
        deployer.requestAppGoal(app, AppLifeCycle.STARTED);
        deployedApps.put(archive.getId(), app);
        HTTPContext httpContext = new HTTPContext(configuration.getBindAddress(), configuration.getBindHttpPort());
        ServletHandler servletHandler = webAppContext.getServletHandler();
        for (ServletHolder servlet : servletHandler.getServlets()) {
            log.debugf("Servlet context mapping: %s => %s", servlet.getName(), servlet.getContextPath());
            httpContext.add(new Servlet(servlet.getName(), servlet.getContextPath()));
        }
        if (log.isInfoEnabled()) {
            for (ServletMapping mapping : server.getChildHandlerByClass(ServletHandler.class).getServletMappings()) {
                log.debugf("Servlet mapping: %s => %s", mapping.getServletName(), Arrays.toString(mapping.getPathSpecs()));
            }
        }
        return new ProtocolMetaData().addContext(httpContext);
    } catch (Exception e) {
        throw new DeploymentException("Unable to deploy archive", e);
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 58 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project knox 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 59 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project knox 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 (ServletMapping servletMapping : servletMappings) {
        if (servletMapping.containsPathSpec(pathSpec)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found existing " + servletMapping.getServletName() + " servlet at path " + pathSpec + "; will replace mapping" + " with " + holder.getName() + " servlet");
            }
            ServletMapping[] newServletMappings = ArrayUtil.removeFromArray(servletMappings, servletMapping);
            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)

Aggregations

ServletHandler (org.eclipse.jetty.servlet.ServletHandler)59 Server (org.eclipse.jetty.server.Server)24 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)24 ServerConnector (org.eclipse.jetty.server.ServerConnector)12 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 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)5 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)5 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InetSocketAddress (java.net.InetSocketAddress)3 HttpServlet (javax.servlet.http.HttpServlet)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2