use of org.eclipse.jetty.server.handler.DefaultHandler 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.DefaultHandler 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();
}
use of org.eclipse.jetty.server.handler.DefaultHandler in project jetty.project by eclipse.
the class AsyncContextTest method setUp.
@Before
public void setUp() throws Exception {
_server = new Server();
_connector = new LocalConnector(_server);
_connector.setIdleTimeout(5000);
_connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setSendDateHeader(false);
_server.addConnector(_connector);
_contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
_contextHandler.setContextPath("/ctx");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/path with spaces/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet2()), "/servletPath2");
_contextHandler.addServlet(new ServletHolder(new TestStartThrowServlet()), "/startthrow/*");
_contextHandler.addServlet(new ServletHolder(new ForwardingServlet()), "/forward");
_contextHandler.addServlet(new ServletHolder(new AsyncDispatchingServlet()), "/dispatchingServlet");
_contextHandler.addServlet(new ServletHolder(new ExpireServlet()), "/expire/*");
_contextHandler.addServlet(new ServletHolder(new BadExpireServlet()), "/badexpire/*");
_contextHandler.addServlet(new ServletHolder(new ErrorServlet()), "/error/*");
ErrorPageErrorHandler error_handler = new ErrorPageErrorHandler();
_contextHandler.setErrorHandler(error_handler);
error_handler.addErrorPage(500, "/error/500");
error_handler.addErrorPage(IOException.class.getName(), "/error/IOE");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { _contextHandler, new DefaultHandler() });
_server.setHandler(handlers);
_server.start();
}
use of org.eclipse.jetty.server.handler.DefaultHandler in project metrics by dropwizard.
the class InstrumentedHandlerTest method setUp.
@Before
public void setUp() throws Exception {
handler.setName("handler");
handler.setHandler(new DefaultHandler());
server.addConnector(connector);
server.setHandler(handler);
server.start();
client.start();
}
use of org.eclipse.jetty.server.handler.DefaultHandler in project blade by biezhi.
the class EmbedJettyServer method startup.
@Override
public void startup(int port, String contextPath, String webRoot) throws EmbedServerException {
this.port = port;
Config config = Blade.$().config();
int minThreads = config.getInt("server.jetty.min-threads", 8);
int maxThreads = config.getInt("server.jetty.max-threads", 200);
String poolName = config.get("server.jetty.pool-name", "blade-pool");
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(minThreads);
threadPool.setMaxThreads(maxThreads);
threadPool.setName(poolName);
this.server = new org.eclipse.jetty.server.Server(threadPool);
this.webAppContext = new WebAppContext();
this.webAppContext.setContextPath(contextPath);
this.webAppContext.setResourceBase("");
int securePort = config.getInt("server.jetty.http.secure-port", 9443);
int outputBufferSize = config.getInt("server.jetty.http.output-buffersize", 32 * 1024);
int requestHeaderSize = config.getInt("server.jetty.http.request-headersize", 8 * 1024);
int responseHeaderSize = config.getInt("server.jetty.http.response-headersize", 8 * 1024);
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecurePort(securePort);
http_config.setOutputBufferSize(outputBufferSize);
http_config.setRequestHeaderSize(requestHeaderSize);
http_config.setResponseHeaderSize(responseHeaderSize);
long idleTimeout = config.getLong("server.jetty.http.idle-timeout", 30000L);
String host = config.get("server.host", "0.0.0.0");
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(http_config));
serverConnector.setHost(host);
serverConnector.setPort(this.port);
serverConnector.setIdleTimeout(idleTimeout);
server.setConnectors(new Connector[] { serverConnector });
boolean isAsync = config.getBoolean("server.async", false);
Class<? extends Servlet> servlet = isAsync ? AsyncDispatcherServlet.class : DispatcherServlet.class;
ServletHolder servletHolder = new ServletHolder(servlet);
servletHolder.setAsyncSupported(isAsync);
servletHolder.setInitOrder(1);
webAppContext.addEventListener(new BladeInitListener());
Set<String> statics = Blade.$().bConfig().getStatics();
defaultHolder = new ServletHolder(DefaultServlet.class);
defaultHolder.setInitOrder(0);
if (StringKit.isNotBlank(classPath)) {
LOGGER.info("add classpath : {}", classPath);
defaultHolder.setInitParameter("resourceBase", classPath);
}
statics.forEach(s -> {
if (s.indexOf(".") != -1) {
webAppContext.addServlet(defaultHolder, s);
} else {
s = s.endsWith("/") ? s + '*' : s + "/*";
webAppContext.addServlet(defaultHolder, s);
}
});
webAppContext.addServlet(defaultHolder, "/favicon.ico");
webAppContext.addServlet(servletHolder, "/");
try {
this.loadServlets(webAppContext);
this.loadFilters(webAppContext);
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { webAppContext, new DefaultHandler() });
server.setHandler(handlerList);
server.setStopAtShutdown(true);
server.start();
LOGGER.info("Blade Server Listen on {}:{}", host, this.port);
server.join();
} catch (Exception e) {
throw new EmbedServerException(e);
}
}
Aggregations