use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class ServerConnectorTimeoutTest method testIdleTimeoutAfterTimeout.
@Test(timeout = 60000)
public void testIdleTimeoutAfterTimeout() throws Exception {
SuspendHandler _handler = new SuspendHandler();
_server.stop();
SessionHandler session = new SessionHandler();
session.setHandler(_handler);
_server.setHandler(session);
_server.start();
_handler.setSuspendFor(50);
assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("TIMEOUT"));
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class StatisticsServletTest method getStats.
@Test
public void getStats() throws Exception {
StatisticsHandler statsHandler = new StatisticsHandler();
_server.setHandler(statsHandler);
ServletContextHandler statsContext = new ServletContextHandler(statsHandler, "/");
statsContext.addServlet(new ServletHolder(new TestServlet()), "/test1");
ServletHolder servletHolder = new ServletHolder(new StatisticsServlet());
servletHolder.setInitParameter("restrictToLocalhost", "false");
statsContext.addServlet(servletHolder, "/stats");
statsContext.setSessionHandler(new SessionHandler());
_server.start();
getResponse("/test1");
String response = getResponse("/stats?xml=true");
Stats stats = parseStats(response);
Assert.assertEquals(1, stats.responses2xx);
getResponse("/stats?statsReset=true");
response = getResponse("/stats?xml=true");
stats = parseStats(response);
Assert.assertEquals(1, stats.responses2xx);
getResponse("/test1");
getResponse("/nothing");
response = getResponse("/stats?xml=true");
stats = parseStats(response);
Assert.assertEquals(3, stats.responses2xx);
Assert.assertEquals(1, stats.responses4xx);
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class ServletContextHandlerTest method testGzipHandlerSet.
@Test
public void testGzipHandlerSet() throws Exception {
ServletContextHandler context = new ServletContextHandler();
context.setSessionHandler(new SessionHandler());
context.setGzipHandler(new GzipHandler());
GzipHandler gzip = context.getGzipHandler();
_server.start();
assertEquals(context.getSessionHandler(), context.getHandler());
assertEquals(gzip, context.getSessionHandler().getHandler());
assertEquals(context.getServletHandler(), gzip.getHandler());
}
use of org.eclipse.jetty.server.session.SessionHandler 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.session.SessionHandler in project jetty.project by eclipse.
the class Response method reset.
public void reset(boolean preserveCookies) {
resetForForward();
_status = 200;
_reason = null;
_contentLength = -1;
List<HttpField> cookies = preserveCookies ? _fields.stream().filter(f -> f.getHeader() == HttpHeader.SET_COOKIE).collect(Collectors.toList()) : null;
_fields.clear();
String connection = _channel.getRequest().getHeader(HttpHeader.CONNECTION.asString());
if (connection != null) {
for (String value : StringUtil.csvSplit(null, connection, 0, connection.length())) {
HttpHeaderValue cb = HttpHeaderValue.CACHE.get(value);
if (cb != null) {
switch(cb) {
case CLOSE:
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.toString());
break;
case KEEP_ALIVE:
if (HttpVersion.HTTP_1_0.is(_channel.getRequest().getProtocol()))
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.toString());
break;
case TE:
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.TE.toString());
break;
default:
}
}
}
}
if (preserveCookies)
cookies.forEach(f -> _fields.add(f));
else {
Request request = getHttpChannel().getRequest();
HttpSession session = request.getSession(false);
if (session != null && session.isNew()) {
SessionHandler sh = request.getSessionHandler();
if (sh != null) {
HttpCookie c = sh.getSessionCookie(session, request.getContextPath(), request.isSecure());
if (c != null)
addCookie(c);
}
}
}
}
Aggregations