Search in sources :

Example 16 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project pulsar by yahoo.

the class ProxyServer method start.

public void start() throws PulsarServerException {
    log.info("Starting web socket proxy at port {}", conf.getWebServicePort());
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone("GMT");
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);
        server.start();
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
Also used : Slf4jRequestLog(org.eclipse.jetty.server.Slf4jRequestLog) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletException(javax.servlet.ServletException) DeploymentException(javax.websocket.DeploymentException) GeneralSecurityException(java.security.GeneralSecurityException) MalformedURLException(java.net.MalformedURLException) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 17 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project pulsar by yahoo.

the class ServerManager method start.

public void start() throws Exception {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLog requestLog = new Slf4jRequestLog();
    requestLog.setExtended(true);
    requestLog.setLogTimeZone("GMT");
    requestLog.setLogLatency(true);
    requestLogHandler.setRequestLog(requestLog);
    handlers.add(0, new ContextHandlerCollection());
    handlers.add(requestLogHandler);
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    server.setHandler(handlerCollection);
    server.start();
    log.info("Server started at end point {}", getServiceUri());
}
Also used : Slf4jRequestLog(org.eclipse.jetty.server.Slf4jRequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 18 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project cdap by caskdata.

the class ExternalAuthenticationServer method startUp.

@Override
protected void startUp() throws Exception {
    try {
        server = new Server();
        try {
            bindAddress = InetAddress.getByName(cConfiguration.get(Constants.Security.AUTH_SERVER_BIND_ADDRESS));
        } catch (UnknownHostException e) {
            LOG.error("Error finding host to connect to.", e);
            throw e;
        }
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setMaxThreads(maxThreads);
        server.setThreadPool(threadPool);
        initHandlers();
        ServletContextHandler context = new ServletContextHandler();
        context.setServer(server);
        context.addServlet(HttpServletDispatcher.class, "/");
        context.addEventListener(new AuthenticationGuiceServletContextListener(handlers));
        context.setSecurityHandler(authenticationHandler);
        // Status endpoint should be handled without the authentication
        ContextHandler statusContext = new ContextHandler();
        statusContext.setContextPath(Constants.EndPoints.STATUS);
        statusContext.setServer(server);
        statusContext.setHandler(new StatusRequestHandler());
        if (cConfiguration.getBoolean(Constants.Security.SSL.EXTERNAL_ENABLED, false)) {
            SslContextFactory sslContextFactory = new SslContextFactory();
            String keyStorePath = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PATH);
            String keyStorePassword = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PASSWORD);
            String keyStoreType = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_TYPE, Constants.Security.AuthenticationServer.DEFAULT_SSL_KEYSTORE_TYPE);
            String keyPassword = sConfiguration.get(Constants.Security.AuthenticationServer.SSL_KEYPASSWORD);
            Preconditions.checkArgument(keyStorePath != null, "Key Store Path Not Configured");
            Preconditions.checkArgument(keyStorePassword != null, "KeyStore Password Not Configured");
            sslContextFactory.setKeyStorePath(keyStorePath);
            sslContextFactory.setKeyStorePassword(keyStorePassword);
            sslContextFactory.setKeyStoreType(keyStoreType);
            if (keyPassword != null && keyPassword.length() != 0) {
                sslContextFactory.setKeyManagerPassword(keyPassword);
            }
            String trustStorePath = cConfiguration.get(Constants.Security.AuthenticationServer.SSL_TRUSTSTORE_PATH);
            if (StringUtils.isNotEmpty(trustStorePath)) {
                String trustStorePassword = cConfiguration.get(Constants.Security.AuthenticationServer.SSL_TRUSTSTORE_PASSWORD);
                String trustStoreType = cConfiguration.get(Constants.Security.AuthenticationServer.SSL_TRUSTSTORE_TYPE, Constants.Security.AuthenticationServer.DEFAULT_SSL_KEYSTORE_TYPE);
                // SSL handshaking will involve requesting for a client certificate, if cert is not provided
                // server continues with the connection but the client is considered to be unauthenticated
                sslContextFactory.setWantClientAuth(true);
                sslContextFactory.setTrustStore(trustStorePath);
                sslContextFactory.setTrustStorePassword(trustStorePassword);
                sslContextFactory.setTrustStoreType(trustStoreType);
                sslContextFactory.setValidateCerts(true);
            }
            // TODO Figure out how to pick a certificate from key store
            SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
            sslConnector.setHost(bindAddress.getCanonicalHostName());
            sslConnector.setPort(port);
            server.setConnectors(new Connector[] { sslConnector });
        } else {
            SelectChannelConnector connector = new SelectChannelConnector();
            connector.setHost(bindAddress.getCanonicalHostName());
            connector.setPort(port);
            server.setConnectors(new Connector[] { connector });
        }
        HandlerCollection handlers = new HandlerCollection();
        handlers.addHandler(statusContext);
        handlers.addHandler(context);
        // AuditLogHandler must be last, since it needs the response that was sent to the client
        handlers.addHandler(auditLogHandler);
        server.setHandler(handlers);
    } catch (Exception e) {
        LOG.error("Error while starting Authentication Server.", e);
    }
    try {
        server.start();
    } catch (Exception e) {
        if ((Throwables.getRootCause(e) instanceof BindException)) {
            throw new ServiceBindException("Authentication Server", bindAddress.getCanonicalHostName(), port, e);
        }
        throw e;
    }
    // assumes we only have one connector
    Connector connector = server.getConnectors()[0];
    InetSocketAddress inetSocketAddress = new InetSocketAddress(connector.getHost(), connector.getLocalPort());
    serviceCancellable = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(Constants.Service.EXTERNAL_AUTHENTICATION, inetSocketAddress)));
}
Also used : SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) Discoverable(org.apache.twill.discovery.Discoverable) ResolvingDiscoverable(co.cask.cdap.common.discovery.ResolvingDiscoverable) ServiceBindException(co.cask.cdap.common.ServiceBindException) Server(org.eclipse.jetty.server.Server) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) BindException(java.net.BindException) ServiceBindException(co.cask.cdap.common.ServiceBindException) BindException(java.net.BindException) ServiceBindException(co.cask.cdap.common.ServiceBindException) UnknownHostException(java.net.UnknownHostException) SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 19 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project hbase by apache.

the class HttpServer method initializeWebServer.

private void initializeWebServer(String name, String hostName, Configuration conf, String[] pathSpecs) throws FileNotFoundException, IOException {
    Preconditions.checkNotNull(webAppContext);
    HandlerCollection handlerCollection = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLog requestLog = HttpRequestLog.getRequestLog(name);
    if (requestLog != null) {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        requestLogHandler.setRequestLog(requestLog);
        handlerCollection.addHandler(requestLogHandler);
    }
    final String appDir = getWebAppsPath(name);
    handlerCollection.addHandler(contexts);
    handlerCollection.addHandler(webAppContext);
    webServer.setHandler(handlerCollection);
    addDefaultApps(contexts, appDir, conf);
    addGlobalFilter("safety", QuotingInputFilter.class.getName(), null);
    Map<String, String> params = new HashMap<>();
    params.put("xframeoptions", conf.get("hbase.http.filter.xframeoptions.mode", "DENY"));
    addGlobalFilter("clickjackingprevention", ClickjackingPreventionFilter.class.getName(), params);
    final FilterInitializer[] initializers = getFilterInitializers(conf);
    if (initializers != null) {
        conf = new Configuration(conf);
        conf.set(BIND_ADDRESS, hostName);
        for (FilterInitializer c : initializers) {
            c.initFilter(this, conf);
        }
    }
    addDefaultServlets();
    if (pathSpecs != null) {
        for (String path : pathSpecs) {
            LOG.info("adding path spec: " + path);
            addFilterPathMapping(path, webAppContext);
        }
    }
}
Also used : RequestLog(org.eclipse.jetty.server.RequestLog) Configuration(org.apache.hadoop.conf.Configuration) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HashMap(java.util.HashMap) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 20 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project camel by apache.

the class WebsocketComponent method createContext.

protected ServletContextHandler createContext(Server server, Connector connector, List<Handler> handlers) throws Exception {
    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    server.addConnector(connector);
    if (handlers != null && !handlers.isEmpty()) {
        for (Handler handler : handlers) {
            if (handler instanceof HandlerWrapper) {
                ((HandlerWrapper) handler).setHandler(server.getHandler());
                server.setHandler(handler);
            } else {
                HandlerCollection handlerCollection = new HandlerCollection();
                handlerCollection.addHandler(server.getHandler());
                handlerCollection.addHandler(handler);
                server.setHandler(handlerCollection);
            }
        }
    }
    return context;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper)

Aggregations

HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)50 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)25 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)22 Server (org.eclipse.jetty.server.Server)21 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)18 ServerConnector (org.eclipse.jetty.server.ServerConnector)17 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)14 Handler (org.eclipse.jetty.server.Handler)13 Test (org.junit.Test)12 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)8 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)8 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)7 URI (java.net.URI)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)6 File (java.io.File)5 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)5 HttpURLConnection (java.net.HttpURLConnection)4 NCSARequestLog (org.eclipse.jetty.server.NCSARequestLog)4 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)4