Search in sources :

Example 61 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class SslContextFactoryReloadTest method start.

private void start(Handler handler) throws Exception {
    server = new Server();
    sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(KEYSTORE_1);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyStoreType("JKS");
    sslContextFactory.setKeyStoreProvider(null);
    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
}
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) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 62 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class TestServer method main.

public static void main(String[] args) throws Exception {
    ((StdErrLog) Log.getLog()).setSource(false);
    String jetty_root = "../../..";
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(100);
    // Setup server
    Server server = new Server(threadPool);
    server.manage(threadPool);
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    server.addBean(Log.getLog());
    // Common HTTP configuration
    HttpConfiguration config = new HttpConfiguration();
    config.setSecurePort(8443);
    config.addCustomizer(new ForwardedRequestCustomizer());
    config.addCustomizer(new SecureRequestCustomizer());
    config.setSendDateHeader(true);
    config.setSendServerVersion(true);
    // Http Connector
    HttpConnectionFactory http = new HttpConnectionFactory(config);
    ServerConnector httpConnector = new ServerConnector(server, http);
    httpConnector.setPort(8080);
    httpConnector.setIdleTimeout(30000);
    server.addConnector(httpConnector);
    // Handlers
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    // Add restart handler to test the ability to save sessions and restart
    RestartHandler restart = new RestartHandler();
    restart.setHandler(handlers);
    server.setHandler(restart);
    // Setup context
    HashLoginService login = new HashLoginService();
    login.setName("Test Realm");
    login.setConfig(jetty_root + "/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties");
    server.addBean(login);
    File log = File.createTempFile("jetty-yyyy_mm_dd", "log");
    NCSARequestLog requestLog = new NCSARequestLog(log.toString());
    requestLog.setExtended(false);
    requestLogHandler.setRequestLog(requestLog);
    server.setStopAtShutdown(true);
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/test");
    webapp.setParentLoaderPriority(true);
    webapp.setResourceBase("./src/main/webapp");
    webapp.setAttribute("testAttribute", "testValue");
    File sessiondir = File.createTempFile("sessions", null);
    if (sessiondir.exists())
        sessiondir.delete();
    sessiondir.mkdir();
    sessiondir.deleteOnExit();
    DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
    FileSessionDataStore sds = new FileSessionDataStore();
    ss.setSessionDataStore(sds);
    sds.setStoreDir(sessiondir);
    webapp.getSessionHandler().setSessionCache(ss);
    contexts.addHandler(webapp);
    ContextHandler srcroot = new ContextHandler();
    srcroot.setResourceBase(".");
    srcroot.setHandler(new ResourceHandler());
    srcroot.setContextPath("/src");
    contexts.addHandler(srcroot);
    server.start();
    server.join();
}
Also used : DefaultSessionCache(org.eclipse.jetty.server.session.DefaultSessionCache) StdErrLog(org.eclipse.jetty.util.log.StdErrLog) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HashLoginService(org.eclipse.jetty.security.HashLoginService) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) FileSessionDataStore(org.eclipse.jetty.server.session.FileSessionDataStore) File(java.io.File)

Example 63 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class TestTransparentProxyServer method main.

public static void main(String[] args) throws Exception {
    ((StdErrLog) Log.getLog()).setSource(false);
    String jetty_root = "../../..";
    // Setup Threadpool
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMaxThreads(100);
    // Setup server
    Server server = new Server(threadPool);
    server.manage(threadPool);
    // Setup JMX
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    server.addBean(Log.getLog());
    // Common HTTP configuration
    HttpConfiguration config = new HttpConfiguration();
    config.setSecurePort(8443);
    config.addCustomizer(new ForwardedRequestCustomizer());
    config.setSendDateHeader(true);
    config.setSendServerVersion(true);
    // Http Connector
    HttpConnectionFactory http = new HttpConnectionFactory(config);
    ServerConnector httpConnector = new ServerConnector(server, http);
    httpConnector.setPort(8080);
    httpConnector.setIdleTimeout(30000);
    server.addConnector(httpConnector);
    // SSL configurations
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setTrustStorePath(jetty_root + "/jetty-server/src/main/config/etc/keystore");
    sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    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");
    sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
    // HTTPS Configuration
    HttpConfiguration https_config = new HttpConfiguration(config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP2 factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h2.getProtocol());
    // SSL Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    http2Connector.setIdleTimeout(15000);
    server.addConnector(http2Connector);
    // Handlers
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });
    server.setHandler(handlers);
    // Setup proxy webapp
    WebAppContext webapp = new WebAppContext();
    webapp.setResourceBase("src/main/webapp");
    contexts.addHandler(webapp);
    // start server
    server.setStopAtShutdown(true);
    server.start();
    server.join();
}
Also used : StdErrLog(org.eclipse.jetty.util.log.StdErrLog) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ForwardedRequestCustomizer(org.eclipse.jetty.server.ForwardedRequestCustomizer) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2Cipher(org.eclipse.jetty.http2.HTTP2Cipher) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 64 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class WordPressHTTP2FastCGIProxyServer method main.

public static void main(String[] args) throws Exception {
    int tlsPort = 8443;
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setEndpointIdentificationAlgorithm("");
    sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
    sslContextFactory.setTrustStorePassword("storepwd");
    sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
    Server server = new Server();
    // HTTP(S) Configuration
    HttpConfiguration config = new HttpConfiguration();
    HttpConfiguration https_config = new HttpConfiguration(config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP2 factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h2.getProtocol());
    // SSL Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(tlsPort);
    http2Connector.setIdleTimeout(15000);
    server.addConnector(http2Connector);
    String root = "/home/simon/programs/wordpress-3.7.1";
    ServletContextHandler context = new ServletContextHandler(server, "/wp");
    context.setResourceBase(root);
    context.setWelcomeFiles(new String[] { "index.php" });
    // Serve static resources
    ServletHolder defaultServlet = new ServletHolder("default", DefaultServlet.class);
    context.addServlet(defaultServlet, "/");
    FilterHolder tryFilesFilter = context.addFilter(TryFilesFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    //        tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path $path/index.php"); // Permalink /?p=123
    // Permalink /%year%/%monthnum%/%postname%
    tryFilesFilter.setInitParameter(TryFilesFilter.FILES_INIT_PARAM, "$path /index.php?p=$path");
    // FastCGI
    ServletHolder fcgiServlet = context.addServlet(FastCGIProxyServlet.class, "*.php");
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, root);
    fcgiServlet.setInitParameter("proxyTo", "http://localhost:9000");
    fcgiServlet.setInitParameter("prefix", "/");
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
    server.start();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2Cipher(org.eclipse.jetty.http2.HTTP2Cipher) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 65 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project jetty.project by eclipse.

the class DrupalHTTP2FastCGIProxyServer method main.

public static void main(String[] args) throws Exception {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setEndpointIdentificationAlgorithm("");
    sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
    sslContextFactory.setTrustStorePassword("storepwd");
    sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
    Server server = new Server();
    // HTTP(S) Configuration
    HttpConfiguration config = new HttpConfiguration();
    HttpConfiguration https_config = new HttpConfiguration(config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP2 factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(h2.getProtocol());
    // SSL Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // HTTP2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    http2Connector.setIdleTimeout(15000);
    server.addConnector(http2Connector);
    // Drupal seems to only work on the root context,
    // at least out of the box without additional plugins
    String root = "/home/simon/programs/drupal-7.23";
    ServletContextHandler context = new ServletContextHandler(server, "/");
    context.setResourceBase(root);
    context.setWelcomeFiles(new String[] { "index.php" });
    // Serve static resources
    ServletHolder defaultServlet = new ServletHolder(DefaultServlet.class);
    defaultServlet.setName("default");
    context.addServlet(defaultServlet, "/");
    // FastCGI
    ServletHolder fcgiServlet = new ServletHolder(FastCGIProxyServlet.class);
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, root);
    fcgiServlet.setInitParameter("proxyTo", "http://localhost:9000");
    fcgiServlet.setInitParameter("prefix", "/");
    fcgiServlet.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+\\.php)");
    context.addServlet(fcgiServlet, "*.php");
    server.start();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2Cipher(org.eclipse.jetty.http2.HTTP2Cipher) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)99 ServerConnector (org.eclipse.jetty.server.ServerConnector)71 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)70 Server (org.eclipse.jetty.server.Server)55 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)40 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)40 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)36 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)25 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)19 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Connector (org.eclipse.jetty.server.Connector)11 IOException (java.io.IOException)10 File (java.io.File)9 ServletException (javax.servlet.ServletException)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)8 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)7 Request (org.eclipse.jetty.server.Request)7