我想在我的测试用例中使用嵌入的 Jetty 9 (v9.2.12.v20150709)。但我无法以编程方式更改 HTTP-Session-Timeout。
这个电话webapp.getSessionHandler().getSessionManager().setMaxInactiveInterval(timeoutInSeconds);好像打不通。
这是减少的代码段,它显示了我所做的:
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
@SuppressWarnings("javadoc")
public class EmbeddedJetty
{
@SuppressWarnings("serial")
public static class TimeoutServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException
{
// return the value of the currently used HTTP-Session Timeout
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("<h1>Timeout: " + request.getSession()
.getMaxInactiveInterval() + "</h1>");
}
}
public static void main(String[] args) throws Exception
{
// the custom …Run Code Online (Sandbox Code Playgroud)