use of org.eclipse.jetty.server.handler.HandlerList in project killbill by killbill.
the class HttpServer method configure.
public void configure(final HttpServerConfig config, final Iterable<EventListener> eventListeners, final Map<FilterHolder, String> filterHolders) {
server.setStopAtShutdown(true);
// Setup JMX
configureJMX(ManagementFactory.getPlatformMBeanServer());
// HTTP Configuration
final HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setSecurePort(config.getServerSslPort());
// Configure main connector
final ServerConnector http = configureMainConnector(httpConfiguration, config.isJettyStatsOn(), config.getServerHost(), config.getServerPort());
// Configure SSL, if enabled
final ServerConnector https;
if (config.isSSLEnabled()) {
https = configureSslConnector(httpConfiguration, config.isJettyStatsOn(), config.getServerSslPort(), config.getSSLkeystoreLocation(), config.getSSLkeystorePassword());
server.setConnectors(new Connector[] { http, https });
} else {
server.setConnectors(new Connector[] { http });
}
// Configure the thread pool
configureThreadPool(config);
// Configure handlers
final HandlerCollection handlers = new HandlerCollection();
final ServletContextHandler servletContextHandler = createServletContextHandler(config.getResourceBase(), eventListeners, filterHolders);
handlers.addHandler(servletContextHandler);
final RequestLogHandler logHandler = createLogHandler(config);
handlers.addHandler(logHandler);
final HandlerList rootHandlers = new HandlerList();
rootHandlers.addHandler(handlers);
server.setHandler(rootHandlers);
}
use of org.eclipse.jetty.server.handler.HandlerList in project neo4j by neo4j.
the class Jetty9WebServer method start.
@Override
public void start() throws Exception {
if (jetty == null) {
JettyThreadCalculator jettyThreadCalculator = new JettyThreadCalculator(jettyMaxThreads);
jetty = new Server(createQueuedThreadPool(jettyThreadCalculator));
jetty.addConnector(connectorFactory.createConnector(jetty, jettyAddress, jettyThreadCalculator));
jettyHttpsAddress.ifPresent((address) -> {
if (httpsCertificateInformation == null) {
throw new RuntimeException("HTTPS set to enabled, but no HTTPS configuration provided");
}
jetty.addConnector(sslSocketFactory.createConnector(jetty, httpsCertificateInformation, address, jettyThreadCalculator));
});
if (jettyCreatedCallback != null) {
jettyCreatedCallback.accept(jetty);
}
}
handlers = new HandlerList();
jetty.setHandler(handlers);
handlers.addHandler(new MovedContextHandler());
loadAllMounts();
if (requestLog != null) {
loadRequestLogging();
}
startJetty();
}
use of org.eclipse.jetty.server.handler.HandlerList in project EventHub by Codecademy.
the class EventHubHandler method main.
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.load(EventHub.class.getClassLoader().getResourceAsStream("hub.properties"));
properties.load(EventHubHandler.class.getClassLoader().getResourceAsStream("web.properties"));
properties.putAll(System.getProperties());
Injector injector = Guice.createInjector(Modules.override(new DmaIdListModule(), new DatedEventIndexModule(), new ShardedEventIndexModule(), new PropertiesIndexModule(), new UserEventIndexModule(), new EventStorageModule(), new UserStorageModule(), new EventHubModule(properties)).with(new Module()));
final EventHubHandler eventHubHandler = injector.getInstance(EventHubHandler.class);
int port = injector.getInstance(Key.get(Integer.class, Names.named("eventhubhandler.port")));
final Server server = new Server(port);
@SuppressWarnings("ConstantConditions") String webDir = EventHubHandler.class.getClassLoader().getResource("frontend").toExternalForm();
HashLoginService loginService = new HashLoginService();
loginService.putUser(properties.getProperty("eventhubhandler.username"), new Password(properties.getProperty("eventhubhandler.password")), new String[] { "user" });
server.addBean(loginService);
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
Constraint constraint = new Constraint();
constraint.setName("auth");
constraint.setAuthenticate(true);
constraint.setRoles(new String[] { "user", "admin" });
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/*");
mapping.setConstraint(constraint);
securityHandler.setConstraintMappings(Collections.singletonList(mapping));
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.setLoginService(loginService);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(false);
resourceHandler.setWelcomeFiles(new String[] { "main.html" });
resourceHandler.setResourceBase(webDir);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { new JsonpCallbackHandler(eventHubHandler), securityHandler });
server.setHandler(handlers);
securityHandler.setHandler(resourceHandler);
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if (server.isStarted()) {
try {
server.stop();
eventHubHandler.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, "Stop Jetty Hook"));
server.join();
}
use of org.eclipse.jetty.server.handler.HandlerList in project alluxio by Alluxio.
the class WebServer method addHandler.
/**
* Adds a handler.
*
* @param handler the handler to add
*/
public void addHandler(AbstractHandler handler) {
HandlerList handlers = new HandlerList();
handlers.addHandler(handler);
for (Handler h : mServer.getHandlers()) {
handlers.addHandler(h);
}
mServer.setHandler(handlers);
}
use of org.eclipse.jetty.server.handler.HandlerList in project Anserini by castorini.
the class TweetSearcher method main.
public static void main(String[] args) throws IOException, InterruptedException, ParseException {
Options options = new Options();
options.addOption(INDEX_OPTION, true, "index path");
options.addOption(PORT_OPTION, true, "port");
CommandLine cmdline = null;
CommandLineParser parser = new GnuParser();
try {
cmdline = parser.parse(options, args);
} catch (org.apache.commons.cli.ParseException e) {
System.err.println("Error parsing command line: " + e.getMessage());
System.exit(-1);
}
if (!cmdline.hasOption(INDEX_OPTION)) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(TweetSearcher.class.getName(), options);
System.exit(-1);
}
int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)) : 8080;
TweetSearcher nrtsearch = new TweetSearcher(cmdline.getOptionValue(INDEX_OPTION));
TweetStreamIndexer its = new TweetStreamIndexer();
Thread itsThread = new Thread(its);
itsThread.start();
LOG.info("Starting HTTP server on port " + port);
HandlerList mainHandler = new HandlerList();
Server server = new Server(port);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("src/main/java/io/anserini/nrts/public");
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.setContextPath("/");
ServletHolder jerseyServlet = new ServletHolder(ServletContainer.class);
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", TweetSearcherAPI.class.getCanonicalName());
handler.addServlet(jerseyServlet, "/*");
mainHandler.addHandler(resource_handler);
mainHandler.addHandler(handler);
server.setHandler(mainHandler);
try {
server.start();
LOG.info("Accepting connections on port " + port);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
server.join();
itsThread.join();
nrtsearch.close();
}
Aggregations