From c4e1db57eec8aec8a7f771aed207c3485988293e Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 23 Nov 2022 13:47:29 +1100 Subject: [PATCH] Issue #8460 simplify DefaultSessionIdManager start (#8464) * Issue #8460 check DefaultSessionIdManager is started --- .../jetty/session/DefaultSessionIdManager.java | 12 ++++++------ .../src/main/java/org/example/SessionDump.java | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DefaultSessionIdManager.java b/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DefaultSessionIdManager.java index bb45341d83e2..df1cc7c1addf 100644 --- a/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DefaultSessionIdManager.java +++ b/jetty-core/jetty-session/src/main/java/org/eclipse/jetty/session/DefaultSessionIdManager.java @@ -16,6 +16,7 @@ import java.security.SecureRandom; import java.util.Collection; import java.util.HashSet; +import java.util.Objects; import java.util.Random; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; @@ -66,7 +67,8 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi */ public DefaultSessionIdManager(Server server) { - _server = server; + _server = Objects.requireNonNull(server); + _server.setSessionIdManager(this); } /** @@ -84,7 +86,8 @@ public DefaultSessionIdManager(Server server, Random random) */ public void setServer(Server server) { - _server = server; + _server = Objects.requireNonNull(server); + _server.setSessionIdManager(this); } /** @@ -263,7 +266,7 @@ public String newSessionId(long seedTerm) } return id; } - + @Override public boolean isIdInUse(String id) { @@ -301,9 +304,6 @@ public boolean isIdInUse(String id) @Override protected void doStart() throws Exception { - if (_server == null) - throw new IllegalStateException("No Server for SessionIdManager"); - initRandom(); if (_workerName == null) diff --git a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/SessionDump.java b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/SessionDump.java index e6ab93231a73..25f289dd979f 100644 --- a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/SessionDump.java +++ b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/SessionDump.java @@ -17,6 +17,7 @@ import java.io.PrintWriter; import java.util.Date; import java.util.Enumeration; +import java.util.UUID; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletConfig; @@ -75,6 +76,8 @@ protected void handleForm(HttpServletRequest request) session.setAttribute("test", "value"); session.setAttribute("obj", new ObjectAttributeValue(System.currentTimeMillis())); session.setAttribute("WEBCL", new MultiMap<>()); + UUID uuid = UUID.randomUUID(); + session.setAttribute("uuid", uuid); } else if (session != null) {