Search in sources :

Example 41 with HttpConfiguration

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

the class JettyHTTPServerEngineTest method testSetConnector.

@Test
public void testSetConnector() throws Exception {
    URL url = new URL("http://localhost:" + PORT4 + "/hello/test");
    JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true);
    JettyHTTPTestHandler handler2 = new JettyHTTPTestHandler("string2", true);
    JettyHTTPServerEngine engine = new JettyHTTPServerEngine();
    engine.setPort(PORT4);
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(PORT4);
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.addCustomizer(new org.eclipse.jetty.server.ForwardedRequestCustomizer());
    HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
    Collection<ConnectionFactory> connectionFactories = new ArrayList<>();
    connectionFactories.add(httpFactory);
    connector.setConnectionFactories(connectionFactories);
    engine.setConnector(connector);
    List<Handler> handlers = new ArrayList<>();
    handlers.add(handler1);
    engine.setHandlers(handlers);
    engine.finalizeConfig();
    engine.addServant(url, handler2);
    String response = null;
    try {
        response = getResponse(url.toString());
        assertEquals("the jetty http handler1 did not take effect", response, "string1string2");
    } catch (Exception ex) {
        fail("Can't get the reponse from the server " + ex);
    }
    engine.stop();
    JettyHTTPServerEngineFactory.destroyForPort(PORT4);
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) URL(java.net.URL) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) Test(org.junit.Test)

Example 42 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project scheduling by ow2-proactive.

the class ErrorCases method startHttpsServer.

@BeforeClass
public static void startHttpsServer() throws Exception {
    skipIfHeadlessEnvironment();
    server = new Server();
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(ErrorCases.class.getResource("keystore").getPath());
    sslContextFactory.setKeyStorePassword("activeeon");
    HttpConfiguration httpConfig = new HttpConfiguration();
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    ServerConnector sslConnector = new ServerConnector(server, new ConnectionFactory[] { new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig) });
    server.addConnector(sslConnector);
    server.start();
    serverUrl = "https://localhost:" + sslConnector.getLocalPort() + "/rest";
}
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) BeforeClass(org.junit.BeforeClass)

Example 43 with HttpConfiguration

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

the class AthenzJettyContainer method addHTTPSConnector.

void addHTTPSConnector(HttpConfiguration httpConfig, int httpsPort, boolean proxyProtocol, String listenHost, int idleTimeout, boolean needClientAuth) {
    // SSL Context Factory
    SslContextFactory sslContextFactory = createSSLContextObject(needClientAuth);
    // SSL HTTP Configuration
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.setSecureScheme("https");
    httpsConfig.setSecurePort(httpsPort);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    // SSL Connector
    ServerConnector sslConnector = null;
    if (proxyProtocol) {
        sslConnector = new ServerConnector(server, new ProxyConnectionFactory(), new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    } else {
        sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    }
    sslConnector.setPort(httpsPort);
    sslConnector.setIdleTimeout(idleTimeout);
    server.addConnector(sslConnector);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Example 44 with HttpConfiguration

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

the class AthenzJettyContainer method createJettyContainer.

public static AthenzJettyContainer createJettyContainer() {
    AthenzJettyContainer container = null;
    // retrieve our http and https port numbers
    int httpPort = ConfigProperties.getPortNumber(AthenzConsts.ATHENZ_PROP_HTTP_PORT, AthenzConsts.ATHENZ_HTTP_PORT_DEFAULT);
    int httpsPort = ConfigProperties.getPortNumber(AthenzConsts.ATHENZ_PROP_HTTPS_PORT, AthenzConsts.ATHENZ_HTTPS_PORT_DEFAULT);
    // for status port we'll use the protocol specified for the regular http
    // port. if both http and https are provided then https will be picked
    // it could also be either one of the values specified as well
    int statusPort = ConfigProperties.getPortNumber(AthenzConsts.ATHENZ_PROP_STATUS_PORT, 0);
    String serverHostName = getServerHostName();
    container = new AthenzJettyContainer();
    container.setBanner("http://" + serverHostName + " http port: " + httpPort + " https port: " + httpsPort + " status port: " + statusPort);
    int maxThreads = Integer.parseInt(System.getProperty(AthenzConsts.ATHENZ_PROP_MAX_THREADS, Integer.toString(AthenzConsts.ATHENZ_HTTP_MAX_THREADS)));
    container.createServer(maxThreads);
    HttpConfiguration httpConfig = container.newHttpConfiguration();
    container.addHTTPConnectors(httpConfig, httpPort, httpsPort, statusPort);
    container.addServletHandlers(serverHostName);
    container.addRequestLogHandler();
    return container;
}
Also used : HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 45 with HttpConfiguration

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

the class AthenzJettyContainerTest method testHttpConfigurationValidHttpsPort.

@Test
public void testHttpConfigurationValidHttpsPort() {
    AthenzJettyContainer container = new AthenzJettyContainer();
    container.createServer(100);
    System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_SERVER_VERSION, "true");
    System.setProperty(AthenzConsts.ATHENZ_PROP_SEND_DATE_HEADER, "false");
    System.setProperty(AthenzConsts.ATHENZ_PROP_OUTPUT_BUFFER_SIZE, "128");
    System.setProperty(AthenzConsts.ATHENZ_PROP_REQUEST_HEADER_SIZE, "256");
    System.setProperty(AthenzConsts.ATHENZ_PROP_RESPONSE_HEADER_SIZE, "512");
    HttpConfiguration httpConfig = container.newHttpConfiguration();
    assertNotNull(httpConfig);
    assertEquals(httpConfig.getOutputBufferSize(), 128);
    assertFalse(httpConfig.getSendDateHeader());
    assertTrue(httpConfig.getSendServerVersion());
    assertEquals(httpConfig.getRequestHeaderSize(), 256);
    assertEquals(httpConfig.getResponseHeaderSize(), 512);
    // it defaults to https even if we have no value specified
    assertEquals(httpConfig.getSecureScheme(), "https");
}
Also used : HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Test(org.testng.annotations.Test)

Aggregations

HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)199 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)148 ServerConnector (org.eclipse.jetty.server.ServerConnector)148 Server (org.eclipse.jetty.server.Server)103 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)88 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)88 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)81 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)42 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)40 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)34 IOException (java.io.IOException)24 Connector (org.eclipse.jetty.server.Connector)23 File (java.io.File)20 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)17 ServletException (javax.servlet.ServletException)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)15 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)15 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)15 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)13