This commit is contained in:
Jan Bartel 2017-01-07 15:54:44 +11:00
parent 3d35484dc7
commit 04a2777603
2 changed files with 18 additions and 8 deletions

View File

@ -30,6 +30,7 @@ import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SessionIdManager; import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.server.handler.ContextHandler; 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.component.ContainerLifeCycle;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -157,10 +158,15 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi
{ {
if (isRunning()) if (isRunning())
throw new IllegalStateException(getState()); throw new IllegalStateException(getState());
if (workerName == null)
_workerName = "";
else
{
if (workerName.contains(".")) if (workerName.contains("."))
throw new IllegalArgumentException("Name cannot contain '.'"); throw new IllegalArgumentException("Name cannot contain '.'");
_workerName=workerName; _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 //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 //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=_workerName + id;
id = id+Long.toString(COUNTER.getAndIncrement()); id = id+Long.toString(COUNTER.getAndIncrement());
@ -417,7 +423,7 @@ public class DefaultSessionIdManager extends ContainerLifeCycle implements Sessi
@Override @Override
public String getExtendedId(String clusterId, HttpServletRequest request) public String getExtendedId(String clusterId, HttpServletRequest request)
{ {
if (_workerName!=null) if (!StringUtil.isBlank(_workerName))
{ {
if (_workerAttr==null) if (_workerAttr==null)
return clusterId+'.'+_workerName; return clusterId+'.'+_workerName;

View File

@ -632,7 +632,9 @@ public class ResponseTest
DefaultSessionCache ss = new DefaultSessionCache(handler); DefaultSessionCache ss = new DefaultSessionCache(handler);
NullSessionDataStore ds = new NullSessionDataStore(); NullSessionDataStore ds = new NullSessionDataStore();
ss.setSessionDataStore(ds); ss.setSessionDataStore(ds);
handler.setSessionIdManager(new DefaultSessionIdManager(_server)); DefaultSessionIdManager idMgr = new DefaultSessionIdManager(_server);
idMgr.setWorkerName(null);
handler.setSessionIdManager(idMgr);
request.setSessionHandler(handler); request.setSessionHandler(handler);
TestSession tsession = new TestSession(handler, "12345"); TestSession tsession = new TestSession(handler, "12345");
tsession.setExtendedId(handler.getSessionIdManager().getExtendedId("12345", null)); tsession.setExtendedId(handler.getSessionIdManager().getExtendedId("12345", null));
@ -717,7 +719,9 @@ public class ResponseTest
DefaultSessionCache ss = new DefaultSessionCache(handler); DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionCache(ss); handler.setSessionCache(ss);
ss.setSessionDataStore(ds); ss.setSessionDataStore(ds);
handler.setSessionIdManager(new DefaultSessionIdManager(_server)); DefaultSessionIdManager idMgr = new DefaultSessionIdManager(_server);
idMgr.setWorkerName(null);
handler.setSessionIdManager(idMgr);
request.setSessionHandler(handler); request.setSessionHandler(handler);
request.setSession(new TestSession(handler, "12345")); request.setSession(new TestSession(handler, "12345"));
handler.setCheckingRemoteSessionIdEncoding(false); handler.setCheckingRemoteSessionIdEncoding(false);