This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 4324eb3acc9aa1cda1ae66eab184905c7421044b Author: Juan Cabrerizo <[email protected]> AuthorDate: Thu Dec 5 11:04:44 2019 +0000 Reseting expiration on each session request --- .../rest/util/MultiSessionAttributeAdapter.java | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java index 9d5556c..848e222 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/MultiSessionAttributeAdapter.java @@ -80,7 +80,7 @@ public class MultiSessionAttributeAdapter { private static final String KEY_PREFERRED_SESSION_HANDLER_INSTANCE = "org.apache.brooklyn.server.PreferredSessionHandlerInstance"; private static final String KEY_IS_PREFERRED = "org.apache.brooklyn.server.IsPreferred"; - private static final int MAX_INACTIVE_INTERVAL = 3601; + private static final int MAX_INACTIVE_INTERVAL = 600; private static final Object PREFERRED_SYMBOLIC_NAME = "org.apache.cxf.cxf-rt-transports-http"; @@ -99,6 +99,7 @@ public class MultiSessionAttributeAdapter { protected MultiSessionAttributeAdapter(HttpSession preferredSession, HttpSession localSession) { this.preferredSession = preferredSession; this.localSession = localSession; + resetExpiration(); } public static MultiSessionAttributeAdapter of(HttpServletRequest r) { @@ -137,7 +138,6 @@ public class MultiSessionAttributeAdapter { (preferredSession!=null ? info(preferredSession) : "none, willl make new session in "+info(preferredHandler))); } if (preferredSession!=null) { - preferredSession.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL); return preferredSession; } if (preferredHandler!=null) { @@ -145,7 +145,6 @@ public class MultiSessionAttributeAdapter { HttpSession result = preferredHandler.newHttpSession(optionalRequest); // bigger than HouseKeeper.sessionScavengeInterval: 3600 // https://www.eclipse.org/jetty/documentation/9.4.x/session-configuration-housekeeper.html - result.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL); if (log.isTraceEnabled()) { log.trace("Creating new session "+info(result)+" to be preferred for " + info(optionalRequest, localSession)); } @@ -154,7 +153,6 @@ public class MultiSessionAttributeAdapter { // the server has a preferred handler, but no session yet; fall back to marking on the session log.warn("No request so cannot create preferred session at preferred handler "+info(preferredHandler)+" for "+info(optionalRequest, localSession)+"; will exceptionally mark the calling session as the preferred one"); markSessionAsPreferred(localSession, " (request came in for "+info(optionalRequest, localSession)+")"); - localSession.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL); return localSession; } else { // shouldn't come here; at minimum it should have returned the local session's handler @@ -408,8 +406,8 @@ public class MultiSessionAttributeAdapter { if (ss!=null) { ss.setAttribute(name, value); } - return; } + return; } else { if (!setLocalValuesAlso) { // can't do all, but at least to local @@ -432,8 +430,8 @@ public class MultiSessionAttributeAdapter { if (ss!=null) { ss.removeAttribute(name); } - return; } + return; } else { if (!setLocalValuesAlso) { // can't do all, but at least to local @@ -481,4 +479,19 @@ public class MultiSessionAttributeAdapter { return getPreferredSession().getId(); } + public MultiSessionAttributeAdapter resetExpiration() { + // force all sessions with this ID to be marked used so they are not expired + // (if _any_ session with this ID is expired, then they all are, even if another + // with the same ID is in use or has a later expiry) + Handler[] hh = getSessionHandlers(); + if (hh!=null) { + for (Handler h: hh) { + Session ss = ((SessionHandler)h).getSession(getId()); + if (ss!=null) { + ss.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL); + } + } + } + return this; + } }
