Search in sources :

Example 46 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project saga by timurstrekalov.

the class InstrumentingProxyServer method start.

public int start() {
    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(0);
    server.addConnector(connector);
    final HandlerCollection handlers = new HandlerCollection();
    // Setup proxy servlet
    final ServletContextHandler context = new ServletContextHandler(handlers, "/");
    context.setAttribute(InstrumentingProxyServlet.INSTRUMENTER, instrumenter);
    context.addServlet(new ServletHolder(InstrumentingProxyServlet.class), "/*");
    // Setup proxy handler to handle CONNECT methods
    final ConnectHandler connectProxy = new ConnectHandler();
    handlers.addHandler(connectProxy);
    server.setHandler(handlers);
    try {
        server.start();
        logger.info("Proxy server started on port {}", connector.getLocalPort());
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    return connector.getLocalPort();
}
Also used : SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) ConnectHandler(org.eclipse.jetty.server.handler.ConnectHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 47 with HandlerCollection

use of org.eclipse.jetty.server.handler.HandlerCollection in project saga by timurstrekalov.

the class FileServer method start.

public int start() {
    final SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(0);
    server.addConnector(connector);
    final HandlerCollection handlers = new HandlerCollection();
    final ResourceHandler resourceHandler = new ResourceHandler() {

        @Override
        protected void doResponseHeaders(final HttpServletResponse response, final Resource resource, final String mimeType) {
            response.addDateHeader("Expires", 0L);
        }
    };
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setResourceBase(resourceBase);
    handlers.addHandler(resourceHandler);
    server.setHandler(handlers);
    try {
        server.start();
        logger.info("File server started on port {}", connector.getLocalPort());
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    return connector.getLocalPort();
}
Also used : SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Resource(org.eclipse.jetty.util.resource.Resource) HttpServletResponse(javax.servlet.http.HttpServletResponse) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 48 with HandlerCollection

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

the class WebService method start.

public void start() throws PulsarServerException {
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(WebService.HANDLER_REQUEST_LOG_TZ);
        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("Web Service started at {}", pulsar.getWebServiceAddress());
    } 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) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) 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) GeneralSecurityException(java.security.GeneralSecurityException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 49 with HandlerCollection

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

the class JettyHelper method initJetty.

public static Server initJetty(final String bindAddress, final int port, SSLConfig sslConfig) {
    final Server jettyServer = new Server();
    // Add a handler collection here, so that each new context adds itself
    // to this collection.
    jettyServer.setHandler(new HandlerCollection());
    ServerConnector connector = null;
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSecureScheme(HTTPS);
    httpConfig.setSecurePort(port);
    if (sslConfig.isEnabled()) {
        SslContextFactory sslContextFactory = new SslContextFactory();
        if (StringUtils.isNotBlank(sslConfig.getAlias())) {
            sslContextFactory.setCertAlias(sslConfig.getAlias());
        }
        sslContextFactory.setNeedClientAuth(sslConfig.isRequireAuth());
        if (StringUtils.isNotBlank(sslConfig.getCiphers()) && !"any".equalsIgnoreCase(sslConfig.getCiphers())) {
            // If use has mentioned "any" let the SSL layer decide on the ciphers
            sslContextFactory.setIncludeCipherSuites(SSLUtil.readArray(sslConfig.getCiphers()));
        }
        String protocol = SSLUtil.getSSLAlgo(SSLUtil.readArray(sslConfig.getProtocols()));
        if (protocol != null) {
            sslContextFactory.setProtocol(protocol);
        } else {
            logger.warn(ManagementStrings.SSL_PROTOCOAL_COULD_NOT_BE_DETERMINED);
        }
        if (StringUtils.isBlank(sslConfig.getKeystore())) {
            throw new GemFireConfigException("Key store can't be empty if SSL is enabled for HttpService");
        }
        sslContextFactory.setKeyStorePath(sslConfig.getKeystore());
        if (StringUtils.isNotBlank(sslConfig.getKeystoreType())) {
            sslContextFactory.setKeyStoreType(sslConfig.getKeystoreType());
        }
        if (StringUtils.isNotBlank(sslConfig.getKeystorePassword())) {
            sslContextFactory.setKeyStorePassword(sslConfig.getKeystorePassword());
        }
        if (StringUtils.isNotBlank(sslConfig.getTruststore())) {
            sslContextFactory.setTrustStorePath(sslConfig.getTruststore());
        }
        if (StringUtils.isNotBlank(sslConfig.getTruststorePassword())) {
            sslContextFactory.setTrustStorePassword(sslConfig.getTruststorePassword());
        }
        httpConfig.addCustomizer(new SecureRequestCustomizer());
        // Somehow With HTTP_2.0 Jetty throwing NPE. Need to investigate further whether all GemFire
        // web application(Pulse, REST) can do with HTTP_1.1
        connector = new ServerConnector(jettyServer, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpConfig));
        connector.setPort(port);
    } else {
        connector = new ServerConnector(jettyServer, new HttpConnectionFactory(httpConfig));
        connector.setPort(port);
    }
    jettyServer.setConnectors(new Connector[] { connector });
    if (StringUtils.isNotBlank(bindAddress)) {
        connector.setHost(bindAddress);
    }
    if (bindAddress != null && !bindAddress.isEmpty()) {
        JettyHelper.bindAddress = bindAddress;
    }
    JettyHelper.port = port;
    return jettyServer;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) GemFireConfigException(org.apache.geode.GemFireConfigException) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 50 with HandlerCollection

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

the class JettyHelper method addWebApplication.

public static Server addWebApplication(final Server jetty, final String webAppContext, final String warFilePath) {
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath(webAppContext);
    webapp.setWar(warFilePath);
    webapp.setParentLoaderPriority(false);
    webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    File tmpPath = new File(getWebAppBaseDirectory(webAppContext));
    tmpPath.mkdirs();
    webapp.setTempDirectory(tmpPath);
    ((HandlerCollection) jetty.getHandler()).addHandler(webapp);
    return jetty;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) File(java.io.File)

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