Search in sources :

Example 26 with SessionHandler

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"));
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Test(org.junit.Test)

Example 27 with SessionHandler

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);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) Test(org.junit.Test)

Example 28 with SessionHandler

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());
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) Test(org.junit.Test)

Example 29 with SessionHandler

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();
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) Constraint(org.eclipse.jetty.util.security.Constraint) LocalConnector(org.eclipse.jetty.server.LocalConnector) ArrayList(java.util.ArrayList) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) Matchers.containsString(org.hamcrest.Matchers.containsString) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Password(org.eclipse.jetty.util.security.Password) HashSet(java.util.HashSet) BeforeClass(org.junit.BeforeClass)

Example 30 with SessionHandler

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);
            }
        }
    }
}
Also used : HttpScheme(org.eclipse.jetty.http.HttpScheme) HttpVersion(org.eclipse.jetty.http.HttpVersion) CookieCompliance(org.eclipse.jetty.http.CookieCompliance) StringUtil(org.eclipse.jetty.util.StringUtil) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpURI(org.eclipse.jetty.http.HttpURI) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServletOutputStream(javax.servlet.ServletOutputStream) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData) IllegalSelectorException(java.nio.channels.IllegalSelectorException) HttpStatus(org.eclipse.jetty.http.HttpStatus) Cookie(javax.servlet.http.Cookie) RuntimeIOException(org.eclipse.jetty.io.RuntimeIOException) HttpFields(org.eclipse.jetty.http.HttpFields) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) HttpSession(javax.servlet.http.HttpSession) HttpContent(org.eclipse.jetty.http.HttpContent) HttpHeaderValue(org.eclipse.jetty.http.HttpHeaderValue) QuotedStringTokenizer(org.eclipse.jetty.util.QuotedStringTokenizer) Collection(java.util.Collection) RequestDispatcher(javax.servlet.RequestDispatcher) HttpCookie(org.eclipse.jetty.http.HttpCookie) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Collectors(java.util.stream.Collectors) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) List(java.util.List) Syntax(org.eclipse.jetty.http.Syntax) HttpField(org.eclipse.jetty.http.HttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField) Log(org.eclipse.jetty.util.log.Log) HttpGenerator(org.eclipse.jetty.http.HttpGenerator) URIUtil(org.eclipse.jetty.util.URIUtil) Logger(org.eclipse.jetty.util.log.Logger) DateGenerator(org.eclipse.jetty.http.DateGenerator) Collections(java.util.Collections) MimeTypes(org.eclipse.jetty.http.MimeTypes) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HttpField(org.eclipse.jetty.http.HttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField) HttpSession(javax.servlet.http.HttpSession) HttpCookie(org.eclipse.jetty.http.HttpCookie) HttpHeaderValue(org.eclipse.jetty.http.HttpHeaderValue)

Aggregations

SessionHandler (org.eclipse.jetty.server.session.SessionHandler)43 Server (org.eclipse.jetty.server.Server)13 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)10 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 IOException (java.io.IOException)8 ServletException (javax.servlet.ServletException)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 HashSessionManager (org.eclipse.jetty.server.session.HashSessionManager)5 File (java.io.File)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpSession (javax.servlet.http.HttpSession)4 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)4 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 BeforeClass (org.junit.BeforeClass)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)3 LocalConnector (org.eclipse.jetty.server.LocalConnector)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 SessionManager (org.eclipse.jetty.server.SessionManager)3