Search in sources :

Example 46 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 47 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 48 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)

Example 49 with DefaultHandler

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

the class DigestServer method run.

protected void run() {
    // System.out.println("Starting Server");
    server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
    WebAppContext webappcontext = new WebAppContext();
    webappcontext.setContextPath("/digestauth");
    String warPath = null;
    try {
        URL res = getClass().getResource("/digestauth");
        warPath = res.toURI().getPath();
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
    }
    webappcontext.setWar(warPath);
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[] { webappcontext, new DefaultHandler() });
    server.setHandler(handlers);
    try {
        configureServer();
        server.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 50 with DefaultHandler

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

the class AbstractJettyServer method run.

protected void run() {
    System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi");
    System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");
    server = new Server(port);
    try {
        if (resourcePath == null) {
            // Register and map the dispatcher servlet
            final ServletHolder servletHolder = new ServletHolder(new CXFCdiServlet());
            final ServletContextHandler context = new ServletContextHandler();
            context.setContextPath(contextPath);
            context.addEventListener(listener);
            context.addServlet(servletHolder, "/rest/*");
            server.setHandler(context);
        } else {
            final WebAppContext context = new WebAppContext();
            context.setContextPath(contextPath);
            context.setWar(getClass().getResource(resourcePath).toURI().getPath());
            context.setServerClasses(new String[] { "org.eclipse.jetty.servlet.ServletContextHandler.Decorator" });
            HandlerCollection handlers = new HandlerCollection();
            handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
            server.setHandler(handlers);
        }
        server.start();
    } catch (final Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) CXFCdiServlet(org.apache.cxf.cdi.CXFCdiServlet) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Aggregations

DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)63 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)44 Server (org.eclipse.jetty.server.Server)29 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)26 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)19 URISyntaxException (java.net.URISyntaxException)18 ServerConnector (org.eclipse.jetty.server.ServerConnector)17 HandlerList (org.eclipse.jetty.server.handler.HandlerList)17 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)15 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)13 Handler (org.eclipse.jetty.server.Handler)10 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)10 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)8 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 Test (org.junit.Test)8 File (java.io.File)7 URI (java.net.URI)7 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7