From 04a277760334e202d4b3d418f08e0a00c5a01ef6 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Sat, 7 Jan 2017 15:54:44 +1100 Subject: [PATCH] Issue #1223 --- .../session/DefaultSessionIdManager.java | 18 ++++++++++++------ .../org/eclipse/jetty/server/ResponseTest.java | 8 ++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java index 96fb1fe6f52..6503a2ef299 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.SessionIdManager; import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -157,9 +158,14 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi { if (isRunning()) throw new IllegalStateException(getState()); - if (workerName.contains(".")) - throw new IllegalArgumentException("Name cannot contain '.'"); - _workerName=workerName; + if (workerName == null) + _workerName = ""; + else + { + if (workerName.contains(".")) + throw new IllegalArgumentException("Name cannot contain '.'"); + _workerName=workerName; + } } /* ------------------------------------------------------------ */ @@ -281,7 +287,7 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi //add in the id of the node to ensure unique id across cluster //NOTE this is different to the node suffix which denotes which node the request was received on - if (_workerName!=null) + if (!StringUtil.isBlank(_workerName)) id=_workerName + id; id = id+Long.toString(COUNTER.getAndIncrement()); @@ -417,7 +423,7 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi @Override public String getExtendedId(String clusterId, HttpServletRequest request) { - if (_workerName!=null) + if (!StringUtil.isBlank(_workerName)) { if (_workerAttr==null) return clusterId+'.'+_workerName; @@ -472,7 +478,7 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi for (SessionHandler manager:getSessionHandlers()) { manager.invalidate(id); - } + } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index 763e29e2794..7fa3d1ee909 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -632,7 +632,9 @@ public class ResponseTest DefaultSessionCache ss = new DefaultSessionCache(handler); NullSessionDataStore ds = new NullSessionDataStore(); ss.setSessionDataStore(ds); - handler.setSessionIdManager(new DefaultSessionIdManager(_server)); + DefaultSessionIdManager idMgr = new DefaultSessionIdManager(_server); + idMgr.setWorkerName(null); + handler.setSessionIdManager(idMgr); request.setSessionHandler(handler); TestSession tsession = new TestSession(handler, "12345"); tsession.setExtendedId(handler.getSessionIdManager().getExtendedId("12345", null)); @@ -717,7 +719,9 @@ public class ResponseTest DefaultSessionCache ss = new DefaultSessionCache(handler); handler.setSessionCache(ss); ss.setSessionDataStore(ds); - handler.setSessionIdManager(new DefaultSessionIdManager(_server)); + DefaultSessionIdManager idMgr = new DefaultSessionIdManager(_server); + idMgr.setWorkerName(null); + handler.setSessionIdManager(idMgr); request.setSessionHandler(handler); request.setSession(new TestSession(handler, "12345")); handler.setCheckingRemoteSessionIdEncoding(false);