Search in sources :

Example 21 with HttpConfiguration

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

the class HttpInputIntegrationTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    __config = new HttpConfiguration();
    __server = new Server();
    LocalConnector local = new LocalConnector(__server, new HttpConnectionFactory(__config));
    local.setIdleTimeout(4000);
    __server.addConnector(local);
    ServerConnector http = new ServerConnector(__server, new HttpConnectionFactory(__config), new HTTP2CServerConnectionFactory(__config));
    http.setIdleTimeout(4000);
    __server.addConnector(http);
    // SSL Context Factory for HTTPS and HTTP/2
    String jetty_distro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
    __sslContextFactory = new SslContextFactory();
    __sslContextFactory.setKeyStorePath(jetty_distro + "/../../../jetty-server/src/test/config/etc/keystore");
    __sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    __sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    // HTTPS Configuration
    __sslConfig = new HttpConfiguration(__config);
    __sslConfig.addCustomizer(new SecureRequestCustomizer());
    // HTTP/1 Connection Factory
    HttpConnectionFactory h1 = new HttpConnectionFactory(__sslConfig);
    /* TODO
        // HTTP/2 Connection Factory
        HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(__sslConfig);
        
        NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
        ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
        alpn.setDefaultProtocol(h1.getProtocol());
        */
    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(__sslContextFactory, h1.getProtocol());
    // HTTP/2 Connector
    ServerConnector http2 = new ServerConnector(__server, ssl, /*TODO alpn,h2,*/
    h1);
    http2.setIdleTimeout(4000);
    __server.addConnector(http2);
    ServletContextHandler context = new ServletContextHandler(__server, "/ctx");
    ServletHolder holder = new ServletHolder(new TestServlet());
    holder.setAsyncSupported(true);
    context.addServlet(holder, "/*");
    __server.start();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BeforeClass(org.junit.BeforeClass)

Example 22 with HttpConfiguration

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

the class HttpBindManager method createConnector.

private void createConnector(int port) {
    httpConnector = null;
    if (port > 0) {
        HttpConfiguration httpConfig = new HttpConfiguration();
        configureProxiedConnector(httpConfig);
        ServerConnector connector = new ServerConnector(httpBindServer, new HttpConnectionFactory(httpConfig));
        // Listen on a specific network interface if it has been set.
        connector.setHost(getBindInterface());
        connector.setPort(port);
        httpConnector = connector;
    }
}
Also used : HTTPSPDYServerConnector(org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnector) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 23 with HttpConfiguration

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

the class HBaseRESTTestingUtility method startServletContainer.

public void startServletContainer(Configuration conf) throws Exception {
    if (server != null) {
        LOG.error("ServletContainer already running");
        return;
    }
    // Inject the conf for the test by being first to make singleton
    RESTServlet.getInstance(conf, UserProvider.instantiate(conf));
    // set up the Jersey servlet container for Jetty
    ResourceConfig app = new ResourceConfig().packages("org.apache.hadoop.hbase.rest").register(Jackson1Feature.class);
    ServletHolder sh = new ServletHolder(new ServletContainer(app));
    // set up Jetty and run the embedded server
    server = new Server(0);
    LOG.info("configured " + ServletContainer.class.getName());
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSendDateHeader(false);
    httpConfig.setSendServerVersion(false);
    ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
    serverConnector.setPort(testServletPort);
    server.addConnector(serverConnector);
    // set up context
    ServletContextHandler ctxHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    ctxHandler.addServlet(sh, "/*");
    // Load filters specified from configuration.
    String[] filterClasses = conf.getStrings(Constants.FILTER_CLASSES, ArrayUtils.EMPTY_STRING_ARRAY);
    for (String filter : filterClasses) {
        filter = filter.trim();
        ctxHandler.addFilter(filter, "/*", EnumSet.of(DispatcherType.REQUEST));
    }
    LOG.info("Loaded filter classes :" + filterClasses);
    conf.set(RESTServer.REST_CSRF_BROWSER_USERAGENTS_REGEX_KEY, ".*");
    RESTServer.addCSRFFilter(ctxHandler, conf);
    HttpServerUtil.constrainHttpMethods(ctxHandler);
    // start the server
    server.start();
    // get the port
    testServletPort = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
    LOG.info("started " + server.getClass().getName() + " on port " + testServletPort);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 24 with HttpConfiguration

use of org.eclipse.jetty.server.HttpConfiguration in project qi4j-sdk by Qi4j.

the class SecureJettyMixin method specializeHttp.

@Override
protected HttpConfiguration specializeHttp(HttpConfiguration httpConfig) {
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    return httpsConfig;
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 25 with HttpConfiguration

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

the class JettyHttpContainerFactory method createServer.

/**
     * Create a {@link Server} that registers an {@link org.eclipse.jetty.server.Handler} that
     * in turn manages all root resource and provider classes found by searching the
     * classes referenced in the java classpath.
     *
     * @param uri               the URI to create the http server. The URI scheme must be
     *                          equal to {@code https}. The URI user information and host
     *                          are ignored. If the URI port is not present then port
     *                          {@value org.glassfish.jersey.server.spi.Container#DEFAULT_HTTPS_PORT} will be
     *                          used. The URI path, query and fragment components are ignored.
     * @param sslContextFactory this is the SSL context factory used to configure SSL connector
     * @param handler           the container that handles all HTTP requests
     * @param start             if set to false, server will not get started, this allows end users to set
     *                          additional properties on the underlying listener.
     * @return newly created {@link Server}.
     *
     * @throws ProcessingException      in case of any failure when creating a new Jetty {@code Server} instance.
     * @throws IllegalArgumentException if {@code uri} is {@code null}.
     * @see JettyHttpContainer
     */
public static Server createServer(final URI uri, final SslContextFactory sslContextFactory, final JettyHttpContainer handler, final boolean start) {
    if (uri == null) {
        throw new IllegalArgumentException(LocalizationMessages.URI_CANNOT_BE_NULL());
    }
    final String scheme = uri.getScheme();
    int defaultPort = Container.DEFAULT_HTTP_PORT;
    if (sslContextFactory == null) {
        if (!"http".equalsIgnoreCase(scheme)) {
            throw new IllegalArgumentException(LocalizationMessages.WRONG_SCHEME_WHEN_USING_HTTP());
        }
    } else {
        if (!"https".equalsIgnoreCase(scheme)) {
            throw new IllegalArgumentException(LocalizationMessages.WRONG_SCHEME_WHEN_USING_HTTPS());
        }
        defaultPort = Container.DEFAULT_HTTPS_PORT;
    }
    final int port = (uri.getPort() == -1) ? defaultPort : uri.getPort();
    final Server server = new Server(new JettyConnectorThreadPool());
    final HttpConfiguration config = new HttpConfiguration();
    if (sslContextFactory != null) {
        config.setSecureScheme("https");
        config.setSecurePort(port);
        config.addCustomizer(new SecureRequestCustomizer());
        final ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(config));
        https.setPort(port);
        server.setConnectors(new Connector[] { https });
    } else {
        final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(config));
        http.setPort(port);
        server.setConnectors(new Connector[] { http });
    }
    if (handler != null) {
        server.setHandler(handler);
    }
    if (start) {
        try {
            // Start the server.
            server.start();
        } catch (final Exception e) {
            throw new ProcessingException(LocalizationMessages.ERROR_WHEN_CREATING_SERVER(), e);
        }
    }
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) 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) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

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