Search in sources :

Example 31 with Handler

use of org.eclipse.jetty.server.Handler in project calcite-avatica by apache.

the class HandlerFactoryTest method testProtobuf.

@Test
public void testProtobuf() {
    Handler handler = factory.getHandler(service, Serialization.PROTOBUF);
    assertTrue("Expected an implementation of the AvaticaProtobufHandler, " + "but got " + handler.getClass(), handler instanceof AvaticaProtobufHandler);
}
Also used : Handler(org.eclipse.jetty.server.Handler) Test(org.junit.Test)

Example 32 with Handler

use of org.eclipse.jetty.server.Handler in project calcite-avatica by apache.

the class HttpServer method internalStart.

protected void internalStart() {
    if (server != null) {
        throw new RuntimeException("Server is already started");
    }
    final QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setDaemon(true);
    server = new Server(threadPool);
    server.manage(threadPool);
    final ServerConnector connector = configureConnector(getConnector(), port);
    ConstraintSecurityHandler securityHandler = null;
    if (null != this.config) {
        switch(config.getAuthenticationType()) {
            case SPNEGO:
                // Get the Handler for SPNEGO authentication
                securityHandler = configureSpnego(server, connector, this.config);
                break;
            case BASIC:
                securityHandler = configureBasicAuthentication(server, connector, config);
                break;
            case DIGEST:
                securityHandler = configureDigestAuthentication(server, connector, config);
                break;
            default:
                // Pass
                break;
        }
    }
    server.setConnectors(new Connector[] { connector });
    // Default to using the handler that was passed in
    final HandlerList handlerList = new HandlerList();
    Handler avaticaHandler = handler;
    // Wrap the provided handler for security if we made one
    if (null != securityHandler) {
        securityHandler.setHandler(handler);
        avaticaHandler = securityHandler;
    }
    handlerList.setHandlers(new Handler[] { avaticaHandler, new DefaultHandler() });
    server.setHandler(handlerList);
    try {
        server.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    port = connector.getLocalPort();
    LOG.info("Service listening on port {}.", getPort());
    // Set the information about the address for this server
    try {
        this.handler.setServerRpcMetadata(createRpcServerMetadata(connector));
    } catch (UnknownHostException e) {
        // Failed to do the DNS lookup, bail out.
        throw new RuntimeException(e);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) UnknownHostException(java.net.UnknownHostException) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) Handler(org.eclipse.jetty.server.Handler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) LoginException(javax.security.auth.login.LoginException) UnknownHostException(java.net.UnknownHostException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 33 with Handler

use of org.eclipse.jetty.server.Handler in project gerrit by GerritCodeReview.

the class JettyServer method makeContext.

private Handler makeContext(final JettyEnv env, final Config cfg) {
    final Set<String> paths = new HashSet<>();
    for (URI u : listenURLs(cfg)) {
        String p = u.getPath();
        if (p == null || p.isEmpty()) {
            p = "/";
        }
        while (1 < p.length() && p.endsWith("/")) {
            p = p.substring(0, p.length() - 1);
        }
        paths.add(p);
    }
    final List<ContextHandler> all = new ArrayList<>();
    for (String path : paths) {
        all.add(makeContext(path, env, cfg));
    }
    if (all.size() == 1) {
        //
        return all.get(0);
    }
    // We have more than one path served out of this container so
    // combine them in a handler which supports dispatching to the
    // individual contexts.
    //
    final ContextHandlerCollection r = new ContextHandlerCollection();
    r.setHandlers(all.toArray(new Handler[0]));
    return r;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ArrayList(java.util.ArrayList) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) URI(java.net.URI) HashSet(java.util.HashSet)

Example 34 with Handler

use of org.eclipse.jetty.server.Handler in project JMRI by JMRI.

the class WebServer method registerResource.

/**
     * Register a URL pattern to return resources from the file system. The
     * filePath may start with any of the following:
     * <ol>
     * <li>{@link jmri.util.FileUtil#PREFERENCES}
     * <li>{@link jmri.util.FileUtil#PROFILE}
     * <li>{@link jmri.util.FileUtil#SETTINGS}
     * <li>{@link jmri.util.FileUtil#PROGRAM}
     * </ol>
     * Note that the filePath can be overridden by an otherwise identical
     * filePath starting with any of the portable paths above it in the
     * preceding list.
     *
     * @param urlPattern the pattern to get resources for
     * @param filePath   the portable path for the resources
     * @throws IllegalArgumentException if urlPattern is already registered to
     *                                  deny access or for a servlet or if
     *                                  filePath is not allowed
     */
public void registerResource(String urlPattern, String filePath) throws IllegalArgumentException {
    if (this.registeredUrls.get(urlPattern) != null) {
        throw new IllegalArgumentException("urlPattern \"" + urlPattern + "\" is already registered.");
    }
    this.registeredUrls.put(urlPattern, Registration.RESOURCE);
    ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    servletContext.setContextPath(urlPattern);
    HandlerList handlers = new HandlerList();
    if (filePath.startsWith(FileUtil.PROGRAM) && !filePath.equals(FileUtil.PROGRAM)) {
        // make it possible to override anything under program: with an identical path under preference:, profile:, or settings:
        log.debug("Setting up handler chain for {}", urlPattern);
        ResourceHandler preferenceHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath.replace(FileUtil.PROGRAM, FileUtil.PREFERENCES)));
        ResourceHandler projectHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath.replace(FileUtil.PROGRAM, FileUtil.PROFILE)));
        ResourceHandler settingsHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath.replace(FileUtil.PROGRAM, FileUtil.SETTINGS)));
        ResourceHandler programHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath));
        handlers.setHandlers(new Handler[] { preferenceHandler, projectHandler, settingsHandler, programHandler, new DefaultHandler() });
    } else if (filePath.startsWith(FileUtil.SETTINGS) && !filePath.equals(FileUtil.SETTINGS)) {
        // make it possible to override anything under settings: with an identical path under preference: or profile:
        log.debug("Setting up handler chain for {}", urlPattern);
        ResourceHandler preferenceHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath.replace(FileUtil.SETTINGS, FileUtil.PREFERENCES)));
        ResourceHandler projectHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath.replace(FileUtil.PROGRAM, FileUtil.PROFILE)));
        ResourceHandler settingsHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath));
        handlers.setHandlers(new Handler[] { preferenceHandler, projectHandler, settingsHandler, new DefaultHandler() });
    } else if (filePath.startsWith(FileUtil.PROFILE) && !filePath.equals(FileUtil.PROFILE)) {
        // make it possible to override anything under profile: with an identical path under preference:
        log.debug("Setting up handler chain for {}", urlPattern);
        ResourceHandler preferenceHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath.replace(FileUtil.SETTINGS, FileUtil.PREFERENCES)));
        ResourceHandler projectHandler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath.replace(FileUtil.PROGRAM, FileUtil.PROFILE)));
        handlers.setHandlers(new Handler[] { preferenceHandler, projectHandler, new DefaultHandler() });
    } else if (FileUtil.isPortableFilename(filePath)) {
        log.debug("Setting up handler chain for {}", urlPattern);
        ResourceHandler handler = new DirectoryHandler(FileUtil.getAbsoluteFilename(filePath));
        handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
    } else if (URIforPortablePath(filePath) == null) {
        throw new IllegalArgumentException("\"" + filePath + "\" is not allowed.");
    }
    ContextHandler handlerContext = new ContextHandler();
    handlerContext.setContextPath(urlPattern);
    handlerContext.setHandler(handlers);
    ((ContextHandlerCollection) this.server.getHandler()).addHandler(handlerContext);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) DirectoryHandler(jmri.web.servlet.directory.DirectoryHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) DirectoryHandler(jmri.web.servlet.directory.DirectoryHandler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 35 with Handler

use of org.eclipse.jetty.server.Handler in project processdash by dtuma.

the class WebServer method setRoots.

public synchronized void setRoots(URL[] roots) {
    SET_ROOTS_PERMISSION.checkPermission();
    // find or build web apps for each of the given URLs
    List<WebAppContextDashboard> newWebApps = new ArrayList();
    for (URL u : roots) if (!u.toString().toLowerCase().contains("/tpidw.jar!/"))
        newWebApps.add(getWebAppForUrl(u));
    webApps.setHandlers(newWebApps.toArray(new Handler[newWebApps.size()]));
    writePackagesToDefaultEnv();
}
Also used : ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) URL(java.net.URL)

Aggregations

Handler (org.eclipse.jetty.server.Handler)63 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 Server (org.eclipse.jetty.server.Server)14 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)13 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)12 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)10 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)10 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)10 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)7 ServerConnector (org.eclipse.jetty.server.ServerConnector)7 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)7 HandlerList (org.eclipse.jetty.server.handler.HandlerList)7 ArrayList (java.util.ArrayList)6 Connector (org.eclipse.jetty.server.Connector)6 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)6 Test (org.junit.Test)6 HandlerWrapper (org.eclipse.jetty.server.handler.HandlerWrapper)5 GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)5 URI (java.net.URI)4