You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fs...@apache.org on 2018/03/15 20:46:17 UTC
svn commit: r1826867 -
/tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java
Author: fschumacher
Date: Thu Mar 15 20:46:16 2018
New Revision: 1826867
URL: http://svn.apache.org/viewvc?rev=1826867&view=rev
Log:
Refactor method swapIn in preparation to bug 62175.
Pull code into smaller methods to make intention of the method clearer and
shorter.
Modified:
tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java
Modified: tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java?rev=1826867&r1=1826866&r2=1826867&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java Thu Mar 15 20:46:16 2018
@@ -707,31 +707,7 @@ public abstract class PersistentManagerB
session = sessions.get(id);
if (session == null) {
- try {
- if (SecurityUtil.isPackageProtectionEnabled()){
- try {
- session = AccessController.doPrivileged(
- new PrivilegedStoreLoad(id));
- } catch (PrivilegedActionException ex) {
- Exception e = ex.getException();
- log.error(sm.getString(
- "persistentManager.swapInException", id),
- e);
- if (e instanceof IOException){
- throw (IOException)e;
- } else if (e instanceof ClassNotFoundException) {
- throw (ClassNotFoundException)e;
- }
- }
- } else {
- session = store.load(id);
- }
- } catch (ClassNotFoundException e) {
- String msg = sm.getString(
- "persistentManager.deserializeError", id);
- log.error(msg, e);
- throw new IllegalStateException(msg, e);
- }
+ session = loadSessionFromStore(id);
if (session != null && !session.isValid()) {
log.error(sm.getString(
@@ -742,19 +718,7 @@ public abstract class PersistentManagerB
}
if (session != null) {
- if(log.isDebugEnabled())
- log.debug(sm.getString("persistentManager.swapIn", id));
-
- session.setManager(this);
- // make sure the listeners know about it.
- ((StandardSession)session).tellNew();
- add(session);
- ((StandardSession)session).activate();
- // endAccess() to ensure timeouts happen correctly.
- // access() to keep access count correct or it will end up
- // negative
- session.access();
- session.endAccess();
+ reactivateLoadedSession(id, session);
}
}
}
@@ -768,6 +732,56 @@ public abstract class PersistentManagerB
}
+ private void reactivateLoadedSession(String id, Session session) {
+ if(log.isDebugEnabled())
+ log.debug(sm.getString("persistentManager.swapIn", id));
+
+ session.setManager(this);
+ // make sure the listeners know about it.
+ ((StandardSession)session).tellNew();
+ add(session);
+ ((StandardSession)session).activate();
+ // endAccess() to ensure timeouts happen correctly.
+ // access() to keep access count correct or it will end up
+ // negative
+ session.access();
+ session.endAccess();
+ }
+
+ private Session loadSessionFromStore(String id) throws IOException {
+ try {
+ if (SecurityUtil.isPackageProtectionEnabled()){
+ return securedStoreLoad(id);
+ } else {
+ return store.load(id);
+ }
+ } catch (ClassNotFoundException e) {
+ String msg = sm.getString(
+ "persistentManager.deserializeError", id);
+ log.error(msg, e);
+ throw new IllegalStateException(msg, e);
+ }
+ }
+
+
+ private Session securedStoreLoad(String id) throws IOException, ClassNotFoundException {
+ try {
+ return AccessController.doPrivileged(
+ new PrivilegedStoreLoad(id));
+ } catch (PrivilegedActionException ex) {
+ Exception e = ex.getException();
+ log.error(sm.getString(
+ "persistentManager.swapInException", id),
+ e);
+ if (e instanceof IOException){
+ throw (IOException)e;
+ } else if (e instanceof ClassNotFoundException) {
+ throw (ClassNotFoundException)e;
+ }
+ }
+ return null;
+ }
+
/**
* Remove the session from the Manager's list of active
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org