Search in sources :

Example 6 with HTTP2CServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory in project jetty.project by eclipse.

the class ProxyProtocolTest method startServer.

public void startServer(Handler handler) throws Exception {
    server = new Server();
    HttpConfiguration configuration = new HttpConfiguration();
    connector = new ServerConnector(server, new ProxyConnectionFactory(), new HTTP2CServerConnectionFactory(configuration));
    server.addConnector(connector);
    server.setHandler(handler);
    client = new HTTP2Client();
    server.addBean(client, true);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ProxyConnectionFactory(org.eclipse.jetty.server.ProxyConnectionFactory)

Example 7 with HTTP2CServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory in project cia by Hack23.

the class CitizenIntelligenceAgencyServer method init.

/**
 * Inits the.
 *
 * @throws Exception
 *             the exception
 */
public final void init() throws Exception {
    initialised = true;
    server = new Server();
    Security.addProvider(new BouncyCastleProvider());
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    // Enable parsing of jndi-related parts of web.xml and jetty-env.xml
    final org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    final HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(28443);
    final HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreType("JKS");
    sslContextFactory.setKeyStorePath("target/keystore.jks");
    sslContextFactory.setTrustStorePath("target/keystore.jks");
    sslContextFactory.setKeyStorePassword("changeit");
    sslContextFactory.setTrustStorePassword("changeit");
    sslContextFactory.setKeyManagerPassword("changeit");
    sslContextFactory.setCertAlias("jetty");
    sslContextFactory.setIncludeCipherSuites("TLS_DHE_RSA.*", "TLS_ECDHE.*");
    sslContextFactory.setExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");
    sslContextFactory.setIncludeProtocols("TLSv1.2");
    final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config), new HTTP2CServerConnectionFactory(https_config));
    sslConnector.setPort(PORT);
    server.setConnectors(new ServerConnector[] { sslConnector });
    final WebAppContext handler = new WebAppContext("src/main/webapp", "/");
    handler.setExtraClasspath("target/classes");
    handler.setParentLoaderPriority(true);
    handler.setConfigurationDiscovered(true);
    handler.setClassLoader(Thread.currentThread().getContextClassLoader());
    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
    server.setHandler(handlers);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) 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) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 8 with HTTP2CServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory in project dropwizard by dropwizard.

the class Http2CConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
    // Prepare connection factories for HTTP/2c
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory http11 = buildHttpConnectionFactory(httpConfig);
    final HTTP2ServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(httpConfig);
    http2c.setMaxConcurrentStreams(maxConcurrentStreams);
    http2c.setInitialStreamRecvWindow(initialStreamRecvWindow);
    // new protocol.
    return buildConnector(server, new ScheduledExecutorScheduler(), buildBufferPool(), name, threadPool, new InstrumentedConnectionFactory(http11, metrics.timer(httpConnections())), http2c);
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 9 with HTTP2CServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory in project rest.li by linkedin.

the class HttpsH2JettyServer method getConnectors.

@Override
protected Connector[] getConnectors(Server server) {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(_keyStore);
    sslContextFactory.setKeyStorePassword(_keyStorePassword);
    sslContextFactory.setTrustStorePath(_keyStore);
    sslContextFactory.setTrustStorePassword(_keyStorePassword);
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
    sslContextFactory.setUseCipherSuitesOrder(true);
    HttpConfiguration https_config = new HttpConfiguration();
    https_config.setSecureScheme(HttpScheme.HTTPS.asString());
    https_config.setSecurePort(_sslPort);
    // HTTPS Configuration
    HttpConfiguration http2_config = new HttpConfiguration(https_config);
    http2_config.addCustomizer(new SecureRequestCustomizer());
    // HTTP/2 Connection Factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(http2_config) {

        /**
         * Required to override since we are using legacy versions in testing which would not be otherwise accepted
         */
        @Override
        public boolean isAcceptable(String protocol, String tlsProtocol, String tlsCipher) {
            return true;
        }
    };
    NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol("h2");
    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
    // Connector supporting HTTP/2, http1.1 and negotiation protocols
    ServerConnector h2Connector = new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(https_config, HttpCompliance.RFC2616));
    h2Connector.setPort(_sslPort);
    server.addConnector(h2Connector);
    HttpConfiguration configuration = new HttpConfiguration();
    ServerConnector h2cConnector = new ServerConnector(server, new HttpConnectionFactory(configuration, HttpCompliance.RFC2616), new HTTP2CServerConnectionFactory(configuration));
    h2cConnector.setPort(_port);
    return new ServerConnector[] { h2Connector, h2cConnector };
}
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) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 10 with HTTP2CServerConnectionFactory

use of org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory in project rest.li by linkedin.

the class HttpServerBuilder method build.

public Server build() {
    Server server = new Server(new QueuedThreadPool(_maxThreads, _minThreads));
    server.setStopTimeout(_stopTimeout);
    // HTTP Configuration
    HttpConfiguration configuration = new HttpConfiguration();
    configuration.setSendXPoweredBy(true);
    configuration.setSendServerVersion(true);
    configuration.setSendXPoweredBy(false);
    configuration.setSendServerVersion(false);
    configuration.setSendDateHeader(false);
    configuration.setBlockingTimeout(_blockingTimeout);
    // HTTP connection factory
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(configuration);
    // HTTP/2 clear text connection factory
    HTTP2CServerConnectionFactory h2cConnectionFactory = new HTTP2CServerConnectionFactory(configuration);
    h2cConnectionFactory.setMaxConcurrentStreams(_maxConcurrentStreams);
    h2cConnectionFactory.setInitialStreamRecvWindow(_initialStreamRecvWindow);
    h2cConnectionFactory.setInitialSessionRecvWindow(_initialSessionRecvWindow);
    // HTTP Connector
    ServerConnector http = new ServerConnector(server, httpConnectionFactory, h2cConnectionFactory);
    http.setIdleTimeout(_idleTimeout);
    http.setPort(HTTP_PORT);
    server.addConnector(http);
    ServletContextHandler handler = new ServletContextHandler(server, "");
    handler.addServlet(new ServletHolder(new HttpServlet() {

        private static final long serialVersionUID = 0;

        @Override
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            try {
                _serverStatsProvider.processRequest(req);
                awaitLatch();
                consumeRequest(req);
                prepareResponse(resp);
            } catch (Exception e) {
                if (_exceptionListener != null) {
                    _exceptionListener.accept(e);
                }
                throw e;
            }
        }

        private void prepareResponse(HttpServletResponse resp) throws IOException {
            addStatus(resp);
            addHeader(resp);
            addContent(resp);
        }

        private void addStatus(HttpServletResponse resp) throws IOException {
            resp.setStatus(_status);
        }

        private void addHeader(HttpServletResponse resp) throws IOException {
            if (_headerSize <= 0) {
                return;
            }
            int valueSize = _headerSize - HEADER_NAME.length();
            char[] headerValue = new char[valueSize];
            Arrays.fill(headerValue, 'a');
            resp.addHeader(HEADER_NAME, new String(headerValue));
        }

        private void addContent(HttpServletResponse resp) throws IOException {
            if (_responseSize <= 0) {
                return;
            }
            byte[] content = new byte[_responseSize];
            Arrays.fill(content, (byte) 0xff);
            resp.getOutputStream().write(content);
        }

        private void awaitLatch() {
            if (_responseLatch != null) {
                try {
                    _responseLatch.await(RESPONSE_LATCH_TIMEOUT, RESPONSE_LATCH_TIMEUNIT);
                } catch (InterruptedException e) {
                }
            }
        }

        private void consumeRequest(HttpServletRequest req) throws IOException {
            while (true) {
                byte[] bytes = new byte[INPUT_BUFFER_SIZE];
                int read = req.getInputStream().read(bytes);
                if (read < 0) {
                    break;
                }
            }
        }
    }), "/*");
    return server;
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)13 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)13 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)12 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 Server (org.eclipse.jetty.server.Server)6 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)5 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)4 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)4 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)4 ArrayList (java.util.ArrayList)3 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)3 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 HttpServlet (javax.servlet.http.HttpServlet)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)2