Search in sources :

Example 36 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler in project jetty.project by eclipse.

the class HostnameVerificationTest method setUp.

@Before
public void setUp() throws Exception {
    QueuedThreadPool serverThreads = new QueuedThreadPool();
    serverThreads.setName("server");
    server = new Server(serverThreads);
    SslContextFactory serverSslContextFactory = new SslContextFactory();
    serverSslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
    serverSslContextFactory.setKeyStorePassword("storepwd");
    connector = new ServerConnector(server, serverSslContextFactory);
    server.addConnector(connector);
    server.setHandler(new DefaultHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            response.getWriter().write("foobar");
        }
    });
    server.start();
    // keystore contains a hostname which doesn't match localhost
    clientSslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
    clientSslContextFactory.setKeyStorePassword("storepwd");
    QueuedThreadPool clientThreads = new QueuedThreadPool();
    clientThreads.setName("client");
    client = new HttpClient(clientSslContextFactory);
    client.setExecutor(clientThreads);
    client.start();
}
Also used : Server(org.eclipse.jetty.server.Server) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Before(org.junit.Before)

Example 37 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler in project gravel by gravel-st.

the class StartJetty method main.

public static void main(String[] args) throws Exception {
    File fn;
    int port = 8080;
    if (args.length == 0) {
        fn = ImageBootstrapper.defaultSourceFolder();
    } else {
        fn = new File(args[0]);
        if (args.length != 1) {
            port = Integer.parseInt(args[1]);
        }
    }
    ImageBootstrapper.bootstrap(fn);
    Server server = new Server(port);
    ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletContext.setContextPath("/browser");
    ResourceHandler staticFilesHandler = new ResourceHandler();
    staticFilesHandler.setResourceBase("src/main/html");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { servletContext, staticFilesHandler, new DefaultHandler() });
    Object stServlet = getStServlet();
    servletContext.addServlet(new ServletHolder(new JettyToStHttpServletConverter(stServlet)), "/*");
    server.setHandler(handlers);
    server.start();
    server.join();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 38 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler in project Openfire by igniterealtime.

the class HttpBindManager method configureHttpBindServer.

/**
     * Starts an HTTP Bind server on the specified port and secure port.
     *
     * @param port the port to start the normal (unsecured) HTTP Bind service on.
     * @param securePort the port to start the TLS (secure) HTTP Bind service on.
     */
private synchronized void configureHttpBindServer(int port, int securePort) {
    // this is the number of threads allocated to each connector/port
    final int processingThreads = JiveGlobals.getIntProperty(HTTP_BIND_THREADS, HTTP_BIND_THREADS_DEFAULT);
    final QueuedThreadPool tp = new QueuedThreadPool(processingThreads);
    tp.setName("Jetty-QTP-BOSH");
    httpBindServer = new Server(tp);
    if (JMXManager.isEnabled()) {
        JMXManager jmx = JMXManager.getInstance();
        httpBindServer.addBean(jmx.getContainer());
    }
    createConnector(port);
    createSSLConnector(securePort);
    if (httpConnector == null && httpsConnector == null) {
        httpBindServer = null;
        return;
    }
    if (httpConnector != null) {
        httpBindServer.addConnector(httpConnector);
    }
    if (httpsConnector != null) {
        httpBindServer.addConnector(httpsConnector);
    }
    //contexts = new ContextHandlerCollection();
    // TODO implement a way to get plugins to add their their web services to contexts
    createBoshHandler(contexts, "/http-bind");
    createCrossDomainHandler(contexts, "/crossdomain.xml");
    loadStaticDirectory(contexts);
    HandlerCollection collection = new HandlerCollection();
    httpBindServer.setHandler(collection);
    collection.setHandlers(new Handler[] { contexts, new DefaultHandler() });
}
Also used : JMXManager(org.jivesoftware.openfire.JMXManager) XMPPServer(org.jivesoftware.openfire.XMPPServer) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 39 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler in project sonarqube by SonarSource.

the class SSLTest method startSSLTransparentReverseProxy.

public static void startSSLTransparentReverseProxy(boolean requireClientAuth) throws Exception {
    int httpPort = NetworkUtils.getNextAvailablePort();
    httpsPort = NetworkUtils.getNextAvailablePort();
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(500);
    server = new Server(threadPool);
    // HTTP Configuration
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSecureScheme("https");
    httpConfig.setSecurePort(httpsPort);
    httpConfig.setSendServerVersion(true);
    httpConfig.setSendDateHeader(false);
    // Handler Structure
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { proxyHandler(), new DefaultHandler() });
    server.setHandler(handlers);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
    http.setPort(httpPort);
    server.addConnector(http);
    Path serverKeyStore = Paths.get(SSLTest.class.getResource("/analysis/SSLTest/serverkeystore.jks").toURI()).toAbsolutePath();
    String keyStorePassword = "serverkeystorepwd";
    String serverKeyPassword = "serverp12pwd";
    Path serverTrustStore = Paths.get(SSLTest.class.getResource("/analysis/SSLTest/servertruststore.jks").toURI()).toAbsolutePath();
    String trustStorePassword = "servertruststorepwd";
    // SSL Context Factory
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(serverKeyStore.toString());
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    sslContextFactory.setKeyManagerPassword(serverKeyPassword);
    sslContextFactory.setTrustStorePath(serverTrustStore.toString());
    sslContextFactory.setTrustStorePassword(trustStorePassword);
    sslContextFactory.setNeedClientAuth(requireClientAuth);
    sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5", "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
    // SSL HTTP Configuration
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    // SSL Connector
    ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    sslConnector.setPort(httpsPort);
    server.addConnector(sslConnector);
    server.start();
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 40 with DefaultHandler

use of org.eclipse.jetty.server.handler.DefaultHandler 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)

Aggregations

DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)40 Server (org.eclipse.jetty.server.Server)25 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)22 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)18 ServerConnector (org.eclipse.jetty.server.ServerConnector)16 HandlerList (org.eclipse.jetty.server.handler.HandlerList)16 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)15 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)11 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)10 Handler (org.eclipse.jetty.server.Handler)9 URI (java.net.URI)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)7 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)7 Test (org.junit.Test)7 File (java.io.File)6 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)6 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)6 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)5