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 jetty.project by eclipse.
the class WebAppContextTest method testContextWhiteList.
/**
* tests that the servlet context white list works
*
* @throws Exception on test failure
*/
@Test
public void testContextWhiteList() throws Exception {
Server server = new Server(0);
HandlerList handlers = new HandlerList();
WebAppContext contextA = new WebAppContext(".", "/A");
contextA.addServlet(ServletA.class, "/s");
handlers.addHandler(contextA);
WebAppContext contextB = new WebAppContext(".", "/B");
contextB.addServlet(ServletB.class, "/s");
contextB.setContextWhiteList(new String[] { "/doesnotexist", "/B/s" });
handlers.addHandler(contextB);
server.setHandler(handlers);
server.start();
// context A should be able to get both A and B servlet contexts
Assert.assertNotNull(contextA.getServletHandler().getServletContext().getContext("/A/s"));
Assert.assertNotNull(contextA.getServletHandler().getServletContext().getContext("/B/s"));
// context B has a contextWhiteList set and should only be able to get ones that are approved
Assert.assertNull(contextB.getServletHandler().getServletContext().getContext("/A/s"));
Assert.assertNotNull(contextB.getServletHandler().getServletContext().getContext("/B/s"));
}
use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.
the class FastFileServer method main.
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { new FastFileHandler(new File(System.getProperty("user.dir"))), new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
}
use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.
the class AliasedConstraintTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
server = new Server();
connector = new LocalConnector(server);
server.setConnectors(new Connector[] { connector });
ContextHandler context = new ContextHandler();
SessionHandler session = new SessionHandler();
TestLoginService loginService = new TestLoginService(TEST_REALM);
loginService.putUser("user0", new Password("password"), new String[] {});
loginService.putUser("user", new Password("password"), new String[] { "user" });
loginService.putUser("user2", new Password("password"), new String[] { "user" });
loginService.putUser("admin", new Password("password"), new String[] { "user", "administrator" });
loginService.putUser("user3", new Password("password"), new String[] { "foo" });
context.setContextPath("/ctx");
context.setResourceBase(MavenTestingUtils.getTestResourceDir("docroot").getAbsolutePath());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
server.setHandler(handlers);
context.setHandler(session);
// context.addAliasCheck(new AllowSymLinkAliasChecker());
server.addBean(loginService);
security = new ConstraintSecurityHandler();
session.setHandler(security);
ResourceHandler handler = new ResourceHandler();
security.setHandler(handler);
List<ConstraintMapping> constraints = new ArrayList<>();
Constraint constraint0 = new Constraint();
constraint0.setAuthenticate(true);
constraint0.setName("forbid");
ConstraintMapping mapping0 = new ConstraintMapping();
mapping0.setPathSpec("/forbid/*");
mapping0.setConstraint(constraint0);
constraints.add(mapping0);
Set<String> knownRoles = new HashSet<>();
knownRoles.add("user");
knownRoles.add("administrator");
security.setConstraintMappings(constraints, knownRoles);
server.start();
}
use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.
the class AsyncContextDispatchWithQueryStrings method setUp.
@Before
public void setUp() throws Exception {
_connector.setIdleTimeout(30000);
_server.setConnectors(new Connector[] { _connector });
_contextHandler.setContextPath("/");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/initialCall");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/firstDispatchWithNewQueryString");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/secondDispatchNewValueForExistingQueryString");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { _contextHandler, new DefaultHandler() });
_server.setHandler(handlers);
_server.start();
}
Aggregations