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();
}
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);
}
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);
}
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 };
}
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;
}
Aggregations