use of org.eclipse.jetty.server.handler.HandlerCollection in project saga by timurstrekalov.
the class InstrumentingProxyServer method start.
public int start() {
final SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(0);
server.addConnector(connector);
final HandlerCollection handlers = new HandlerCollection();
// Setup proxy servlet
final ServletContextHandler context = new ServletContextHandler(handlers, "/");
context.setAttribute(InstrumentingProxyServlet.INSTRUMENTER, instrumenter);
context.addServlet(new ServletHolder(InstrumentingProxyServlet.class), "/*");
// Setup proxy handler to handle CONNECT methods
final ConnectHandler connectProxy = new ConnectHandler();
handlers.addHandler(connectProxy);
server.setHandler(handlers);
try {
server.start();
logger.info("Proxy server started on port {}", connector.getLocalPort());
} catch (final Exception e) {
throw new RuntimeException(e);
}
return connector.getLocalPort();
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project saga by timurstrekalov.
the class FileServer method start.
public int start() {
final SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(0);
server.addConnector(connector);
final HandlerCollection handlers = new HandlerCollection();
final ResourceHandler resourceHandler = new ResourceHandler() {
@Override
protected void doResponseHeaders(final HttpServletResponse response, final Resource resource, final String mimeType) {
response.addDateHeader("Expires", 0L);
}
};
resourceHandler.setDirectoriesListed(true);
resourceHandler.setResourceBase(resourceBase);
handlers.addHandler(resourceHandler);
server.setHandler(handlers);
try {
server.start();
logger.info("File server started on port {}", connector.getLocalPort());
} catch (final Exception e) {
throw new RuntimeException(e);
}
return connector.getLocalPort();
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project pulsar by yahoo.
the class WebService method start.
public void start() throws PulsarServerException {
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(WebService.HANDLER_REQUEST_LOG_TZ);
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
log.info("Web Service started at {}", pulsar.getWebServiceAddress());
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project geode by apache.
the class JettyHelper method initJetty.
public static Server initJetty(final String bindAddress, final int port, SSLConfig sslConfig) {
final Server jettyServer = new Server();
// Add a handler collection here, so that each new context adds itself
// to this collection.
jettyServer.setHandler(new HandlerCollection());
ServerConnector connector = null;
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme(HTTPS);
httpConfig.setSecurePort(port);
if (sslConfig.isEnabled()) {
SslContextFactory sslContextFactory = new SslContextFactory();
if (StringUtils.isNotBlank(sslConfig.getAlias())) {
sslContextFactory.setCertAlias(sslConfig.getAlias());
}
sslContextFactory.setNeedClientAuth(sslConfig.isRequireAuth());
if (StringUtils.isNotBlank(sslConfig.getCiphers()) && !"any".equalsIgnoreCase(sslConfig.getCiphers())) {
// If use has mentioned "any" let the SSL layer decide on the ciphers
sslContextFactory.setIncludeCipherSuites(SSLUtil.readArray(sslConfig.getCiphers()));
}
String protocol = SSLUtil.getSSLAlgo(SSLUtil.readArray(sslConfig.getProtocols()));
if (protocol != null) {
sslContextFactory.setProtocol(protocol);
} else {
logger.warn(ManagementStrings.SSL_PROTOCOAL_COULD_NOT_BE_DETERMINED);
}
if (StringUtils.isBlank(sslConfig.getKeystore())) {
throw new GemFireConfigException("Key store can't be empty if SSL is enabled for HttpService");
}
sslContextFactory.setKeyStorePath(sslConfig.getKeystore());
if (StringUtils.isNotBlank(sslConfig.getKeystoreType())) {
sslContextFactory.setKeyStoreType(sslConfig.getKeystoreType());
}
if (StringUtils.isNotBlank(sslConfig.getKeystorePassword())) {
sslContextFactory.setKeyStorePassword(sslConfig.getKeystorePassword());
}
if (StringUtils.isNotBlank(sslConfig.getTruststore())) {
sslContextFactory.setTrustStorePath(sslConfig.getTruststore());
}
if (StringUtils.isNotBlank(sslConfig.getTruststorePassword())) {
sslContextFactory.setTrustStorePassword(sslConfig.getTruststorePassword());
}
httpConfig.addCustomizer(new SecureRequestCustomizer());
// Somehow With HTTP_2.0 Jetty throwing NPE. Need to investigate further whether all GemFire
// web application(Pulse, REST) can do with HTTP_1.1
connector = new ServerConnector(jettyServer, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpConfig));
connector.setPort(port);
} else {
connector = new ServerConnector(jettyServer, new HttpConnectionFactory(httpConfig));
connector.setPort(port);
}
jettyServer.setConnectors(new Connector[] { connector });
if (StringUtils.isNotBlank(bindAddress)) {
connector.setHost(bindAddress);
}
if (bindAddress != null && !bindAddress.isEmpty()) {
JettyHelper.bindAddress = bindAddress;
}
JettyHelper.port = port;
return jettyServer;
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project geode by apache.
the class JettyHelper method addWebApplication.
public static Server addWebApplication(final Server jetty, final String webAppContext, final String warFilePath) {
WebAppContext webapp = new WebAppContext();
webapp.setContextPath(webAppContext);
webapp.setWar(warFilePath);
webapp.setParentLoaderPriority(false);
webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
File tmpPath = new File(getWebAppBaseDirectory(webAppContext));
tmpPath.mkdirs();
webapp.setTempDirectory(tmpPath);
((HandlerCollection) jetty.getHandler()).addHandler(webapp);
return jetty;
}
Aggregations