use of org.eclipse.jetty.server.HttpConnectionFactory in project killbill by killbill.
the class HttpServer method configureSslConnector.
private ServerConnector configureSslConnector(final HttpConfiguration httpConfiguration, final boolean isStatsOn, final int localSslPort, final String sslKeyStorePath, final String sslKeyStorePassword) {
// SSL Context Factory for HTTPS
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(sslKeyStorePath);
sslContextFactory.setKeyStorePassword(sslKeyStorePassword);
// HTTPS Configuration
final HttpConfiguration httpsConfig = new HttpConfiguration(httpConfiguration);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// HTTPS connector
final ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
https.setPort(localSslPort);
if (isStatsOn) {
final ConnectorStatistics stats = new ConnectorStatistics();
https.addBean(stats);
}
return https;
}
use of org.eclipse.jetty.server.HttpConnectionFactory in project ninja by ninjaframework.
the class NinjaJetty method doConfigure.
@Override
protected void doConfigure() throws Exception {
// current value or system property or conf/application.conf or default value
jettyConfiguration(overlayedNinjaProperties.get(KEY_NINJA_JETTY_CONFIGURATION, this.jettyConfiguration, DEFAULT_JETTY_CONFIGURATION));
// build jetty server, context, and servlet
if (this.jettyConfiguration != null) {
String[] configs = this.jettyConfiguration.split(",");
for (String config : configs) {
jetty = buildServerOrApplyConfiguration(config, jetty);
}
// since we don't know host and port, try to get it from jetty
tryToSetHostAndPortFromJetty();
} else {
// create very simple jetty configuration
jetty = new Server();
if (port > -1) {
// build http cleartext connector
ServerConnector http = new ServerConnector(jetty);
http.setPort(port);
http.setIdleTimeout(idleTimeout);
if (host != null) {
http.setHost(host);
}
jetty.addConnector(http);
}
if (sslPort > -1) {
// build https secure connector
// http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(sslPort);
httpConfig.setOutputBufferSize(32768);
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// unfortunately jetty seems to only work when we pass a keystore
// and truststore (as opposed to our own prepared SSLContext)
// call createSSLContext() to simply verify configuration is correct
this.createSSLContext();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStore(StandaloneHelper.loadKeyStore(this.sslKeystoreUri, this.sslKeystorePassword.toCharArray()));
sslContextFactory.setKeyManagerPassword(this.sslKeystorePassword);
sslContextFactory.setTrustStore(StandaloneHelper.loadKeyStore(this.sslTruststoreUri, this.sslTruststorePassword.toCharArray()));
ServerConnector https = new ServerConnector(jetty, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
https.setPort(sslPort);
https.setIdleTimeout(idleTimeout);
jetty.addConnector(https);
}
}
this.ninjaServletListener.setNinjaProperties(ninjaProperties);
this.contextHandler = new ServletContextHandler(jetty, getContextPath());
this.contextHandler.addEventListener(ninjaServletListener);
this.contextHandler.addFilter(GuiceFilter.class, "/*", null);
this.contextHandler.addServlet(DefaultServlet.class, "/");
// disable directory browsing
this.contextHandler.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
// Add an error handler that does not print stack traces in case
// something happens that is not under control of Ninja
this.contextHandler.setErrorHandler(new SilentErrorHandler());
}
use of org.eclipse.jetty.server.HttpConnectionFactory in project camel by apache.
the class WebsocketComponent method createStaticResourcesServer.
protected Server createStaticResourcesServer(ServletContextHandler context, String host, int port, String home) throws Exception {
Server server = new Server();
HttpConfiguration httpConfig = new HttpConfiguration();
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
connector.setHost(host);
connector.setPort(port);
server.addConnector(connector);
return createStaticResourcesServer(server, context, home);
}
use of org.eclipse.jetty.server.HttpConnectionFactory in project rest.li by linkedin.
the class HttpServerBuilder method build.
public Server build() {
Server server = new Server();
// HTTP Configuration
HttpConfiguration configuration = new HttpConfiguration();
configuration.setSendXPoweredBy(true);
configuration.setSendServerVersion(true);
configuration.setSendXPoweredBy(false);
configuration.setSendServerVersion(false);
configuration.setSendDateHeader(false);
// HTTP Connector
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(configuration), new HTTP2CServerConnectionFactory(configuration));
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 doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
awaitLatch();
readEntity(req.getReader());
addStatus(resp);
addHeader(resp);
addContent(resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
awaitLatch();
readEntity(req.getReader());
addStatus(resp);
addHeader(resp);
addContent(resp);
}
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
awaitLatch();
readEntity(req.getReader());
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;
}
char[] content = new char[_responseSize];
Arrays.fill(content, 'a');
resp.getWriter().write(content);
}
private void awaitLatch() {
if (_responseLatch != null) {
try {
_responseLatch.await(RESPONSE_LATCH_TIMEOUT, RESPONSE_LATCH_TIMEUNIT);
} catch (InterruptedException e) {
}
}
}
private void readEntity(BufferedReader reader) throws IOException {
while (true) {
char[] bytes = new char[8192];
int read = reader.read(bytes);
if (read < 0) {
break;
}
}
}
}), "/*");
return server;
}
use of org.eclipse.jetty.server.HttpConnectionFactory in project rest.li by linkedin.
the class HttpsJettyServer method getConnectors.
@Override
protected Connector[] getConnectors(Server server) {
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(_keyStore);
sslContextFactory.setKeyStorePassword(_keyStorePassword);
sslContextFactory.setTrustStorePath(_keyStore);
sslContextFactory.setTrustStorePassword(_keyStorePassword);
HttpConfiguration configuration = new HttpConfiguration();
configuration.addCustomizer(new SecureRequestCustomizer());
ServerConnector sslConnector = new ServerConnector(server, sslContextFactory, new HttpConnectionFactory(configuration, HttpCompliance.RFC2616));
sslConnector.setPort(_sslPort);
Connector[] httpConnectors = super.getConnectors(server);
Connector[] connectors = new Connector[httpConnectors.length + 1];
int i = 0;
for (Connector c : httpConnectors) {
connectors[i++] = c;
}
connectors[i++] = sslConnector;
return connectors;
}
Aggregations