* Issue #4707 wrong value for ServletContext.setSessionTimeout Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
parent
528d608860
commit
0a4879e521
|
@ -27,6 +27,7 @@ import java.util.EventListener;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.servlet.DispatcherType;
|
||||
|
@ -167,6 +168,7 @@ public class ServletContextHandlerTest
|
|||
{
|
||||
try
|
||||
{
|
||||
ctx.setAttribute("MYSCI.startSessionTimeout", Integer.valueOf(ctx.getSessionTimeout()));
|
||||
ctx.setSessionTimeout(timeout);
|
||||
ctx.setAttribute("MYSCI.setSessionTimeout", Boolean.TRUE);
|
||||
ctx.setAttribute("MYSCI.getSessionTimeout", Integer.valueOf(ctx.getSessionTimeout()));
|
||||
|
@ -630,11 +632,15 @@ public class ServletContextHandlerTest
|
|||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
_server.setHandler(contexts);
|
||||
|
||||
int startMin = 7;
|
||||
Integer timeout = Integer.valueOf(100);
|
||||
ServletContextHandler root = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
|
||||
root.getSessionHandler().setMaxInactiveInterval((int)TimeUnit.MINUTES.toSeconds(startMin));
|
||||
root.addBean(new MySCIStarter(root.getServletContext(), new MySCI(true, timeout.intValue())), true);
|
||||
_server.start();
|
||||
|
||||
//test starting value of setSessionTimeout
|
||||
assertEquals(startMin, (Integer)root.getServletContext().getAttribute("MYSCI.startSessionTimeout"));
|
||||
//test can set session timeout from ServletContainerInitializer
|
||||
assertTrue((Boolean)root.getServletContext().getAttribute("MYSCI.setSessionTimeout"));
|
||||
//test can get session timeout from ServletContainerInitializer
|
||||
|
|
|
@ -659,11 +659,10 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
XmlParser.Node tNode = node.get("session-timeout");
|
||||
if (tNode != null)
|
||||
{
|
||||
long val = Long.parseLong(tNode.toString(false, true));
|
||||
val = TimeUnit.MINUTES.toSeconds(val);
|
||||
if (val > Integer.MAX_VALUE)
|
||||
long mins = Long.parseLong(tNode.toString(false, true));
|
||||
if (TimeUnit.MINUTES.toSeconds(mins) > Integer.MAX_VALUE)
|
||||
throw new IllegalStateException("Max session-timeout in minutes is " + TimeUnit.SECONDS.toMinutes(Integer.MAX_VALUE));
|
||||
context.getServletContext().setSessionTimeout((int)val);
|
||||
context.getServletContext().setSessionTimeout((int)mins);
|
||||
}
|
||||
|
||||
//Servlet Spec 3.0
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||
//
|
||||
// This program and the accompanying materials are made available under
|
||||
// the terms of the Eclipse Public License 2.0 which is available at
|
||||
// https://www.eclipse.org/legal/epl-2.0
|
||||
//
|
||||
// This Source Code may also be made available under the following
|
||||
// Secondary Licenses when the conditions for such availability set
|
||||
// forth in the Eclipse Public License, v. 2.0 are satisfied:
|
||||
// the Apache License v2.0 which is available at
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.webapp;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class StandardDescriptorProcessorTest
|
||||
{
|
||||
//TODO add tests for other methods
|
||||
|
||||
@Test
|
||||
public void testVisitSessionConfig() throws Exception
|
||||
{
|
||||
File webXml = MavenTestingUtils.getTestResourceFile("web-session-config.xml");
|
||||
Server server = new Server();
|
||||
WebAppContext wac = new WebAppContext();
|
||||
wac.setServer(server);
|
||||
wac.setResourceBase(MavenTestingUtils.getTargetTestingDir("testSessionConfig").getAbsolutePath());
|
||||
wac.setDescriptor(webXml.toURI().toURL().toString());
|
||||
wac.start();
|
||||
assertEquals(54, TimeUnit.SECONDS.toMinutes(wac.getSessionHandler().getMaxInactiveInterval()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
|
||||
<display-name>Test 4 WebApp</display-name>
|
||||
<session-config>
|
||||
<session-timeout>54</session-timeout>
|
||||
</session-config>
|
||||
|
||||
</web-app>
|
|
@ -129,6 +129,7 @@ public class TestListener implements HttpSessionListener, HttpSessionAttributeLi
|
|||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
|
||||
// System.err.println("contextInitialized "+sce);
|
||||
_called.put("contextInitialized", new Throwable());
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@
|
|||
</login-config>
|
||||
|
||||
<session-config>
|
||||
<session-timeout>5</session-timeout>
|
||||
<session-timeout>54</session-timeout>
|
||||
</session-config>
|
||||
|
||||
<security-role>
|
||||
|
|
Loading…
Reference in New Issue