Merge remote-tracking branch 'origin/jetty-11.0.x' into jetty-12.0.x

This commit is contained in:
Jan Bartel 2023-07-05 23:59:27 +02:00
commit 3e75b4fb1c
5 changed files with 53 additions and 6 deletions

View File

@ -2463,9 +2463,6 @@ public class ServletContextHandler extends ContextHandler
@Override
public int getSessionTimeout()
{
if (!isStarting())
throw new IllegalStateException();
int timeout = -1;
if (_sessionHandler != null)
{

View File

@ -783,6 +783,7 @@ public class ServletContextHandlerTest
int startMin = 7;
Integer timeout = Integer.valueOf(100);
ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS);
root.addServlet(new ServletHolder(TestSessionTimeoutServlet.class), "/");
contexts.addHandler(root);
root.getSessionHandler().setMaxInactiveInterval((int)TimeUnit.MINUTES.toSeconds(startMin));
root.addBean(new MySCIStarter(root.getContext(), new MySCI(true, timeout.intValue())), true);
@ -799,6 +800,17 @@ public class ServletContextHandlerTest
assertTrue((Boolean)root.getServletContext().getAttribute("MyContextListener.getSessionTimeout"));
//test can't set session timeout from ContextListener that is not from annotation or web.xml
assertTrue((Boolean)root.getServletContext().getAttribute("MyContextListener.setSessionTimeout"));
//test accessing timeout from a servlet
StringBuilder rawRequest = new StringBuilder();
rawRequest.append("GET / HTTP/1.1\r\n");
rawRequest.append("Host: local\r\n");
rawRequest.append("Connection: close\r\n");
rawRequest.append("\r\n");
String rawResponse = _connector.getResponse(rawRequest.toString());
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertEquals(200, response.getStatus(), "response status");
assertEquals("SessionTimeout = " + timeout, response.getContent(), "response content");
}
@Test
@ -2210,6 +2222,20 @@ public class ServletContextHandlerTest
}
}
public static class TestSessionTimeoutServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
int t = req.getServletContext().getSessionTimeout();
resp.setStatus(HttpServletResponse.SC_OK);
PrintWriter writer = resp.getWriter();
writer.write("SessionTimeout = " + t);
}
}
@Test
public void testProgrammaticListener() throws Exception
{

View File

@ -1401,8 +1401,6 @@ public class ServletContextHandler extends ContextHandler
@Override
public int getSessionTimeout()
{
if (!isStarting())
throw new IllegalStateException();
if (!_enabled)
throw new UnsupportedOperationException();

View File

@ -765,6 +765,7 @@ public class ServletContextHandlerTest
Integer timeout = Integer.valueOf(100);
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
root.getSessionHandler().setMaxInactiveInterval((int)TimeUnit.MINUTES.toSeconds(startMin));
root.addServlet(new ServletHolder(TestSessionTimeoutServlet.class), "/");
root.addBean(new MySCIStarter(root.getServletContext(), new MySCI(true, timeout.intValue())), true);
_server.start();
@ -779,6 +780,17 @@ public class ServletContextHandlerTest
assertTrue((Boolean)root.getServletContext().getAttribute("MyContextListener.getSessionTimeout"));
//test can't set session timeout from ContextListener that is not from annotation or web.xml
assertTrue((Boolean)root.getServletContext().getAttribute("MyContextListener.setSessionTimeout"));
//test accessing timeout from a servlet
StringBuilder rawRequest = new StringBuilder();
rawRequest.append("GET / HTTP/1.1\r\n");
rawRequest.append("Host: local\r\n");
rawRequest.append("Connection: close\r\n");
rawRequest.append("\r\n");
String rawResponse = _connector.getResponse(rawRequest.toString());
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertEquals(200, response.getStatus(), "response status");
assertEquals("SessionTimeout = " + timeout, response.getContent(), "response content");
}
@Test
@ -2015,6 +2027,20 @@ public class ServletContextHandlerTest
}
}
public static class TestSessionTimeoutServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
int t = req.getServletContext().getSessionTimeout();
resp.setStatus(HttpServletResponse.SC_OK);
PrintWriter writer = resp.getWriter();
writer.write("SessionTimeout = " + t);
}
}
public static class TestServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;

View File

@ -107,7 +107,7 @@
<mariadb.docker.version>10.3.6</mariadb.docker.version>
<maven.deps.version>3.8.7</maven.deps.version>
<maven-artifact-transfer.version>0.13.1</maven-artifact-transfer.version>
<maven.resolver.version>1.9.10</maven.resolver.version>
<maven.resolver.version>1.9.13</maven.resolver.version>
<maven.version>3.9.0</maven.version>
<mongodb.version>3.12.11</mongodb.version>
<openpojo.version>0.9.1</openpojo.version>