Author: markt
Date: Wed Jan 20 16:48:49 2016
New Revision: 1725753
URL: http://svn.apache.org/viewvc?rev=1725753&view=rev
Log:
Revert r1725706. Saving the session may trigger loging within application
classes so TCCL needs to be set.
Modified:
tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java
Modified: tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java?rev=1725753&r1=1725752&r2=1725753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/PersistentValve.java Wed Jan
20 16:48:49 2016
@@ -21,7 +21,11 @@ import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
+import org.apache.catalina.Container;
import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Globals;
+import org.apache.catalina.Host;
import org.apache.catalina.Manager;
import org.apache.catalina.Session;
import org.apache.catalina.Store;
@@ -42,6 +46,14 @@ import org.apache.catalina.connector.Res
*/
public class PersistentValve extends ValveBase {
+ // Saves a couple of calls to getClassLoader() on every request. Under high
+ // load these calls took just long enough to appear as a hot spot (although
+ // a very minor one) in a profiler.
+ private static final ClassLoader MY_CLASSLOADER =
PersistentValve.class.getClassLoader();
+
+ private volatile boolean clBindRequired;
+
+
//------------------------------------------------------ Constructor
public PersistentValve() {
@@ -51,6 +63,17 @@ public class PersistentValve extends Val
// --------------------------------------------------------- Public Methods
+ @Override
+ public void setContainer(Container container) {
+ super.setContainer(container);
+ if (container instanceof Engine || container instanceof Host) {
+ clBindRequired = true;
+ } else {
+ clBindRequired = false;
+ }
+ }
+
+
/**
* Select the appropriate child Context to process this request,
* based on the specified request URI. If no matching Context can
@@ -85,6 +108,7 @@ public class PersistentValve extends Val
session = store.load(sessionId);
} catch (Exception e) {
container.getLogger().error("deserializeError");
+ } finally {
}
if (session != null) {
if (!session.isValid() ||
@@ -131,31 +155,38 @@ public class PersistentValve extends Val
container.getLogger().debug("newsessionId: " + newsessionId);
}
if (newsessionId!=null) {
- /* store the session and remove it from the manager */
- if (manager instanceof StoreManager) {
- Session session = manager.findSession(newsessionId);
- Store store = ((StoreManager) manager).getStore();
- if (store != null && session != null && session.isValid()
&&
- !isSessionStale(session,
System.currentTimeMillis())) {
- store.save(session);
- ((StoreManager) manager).removeSuper(session);
- session.recycle();
+ try {
+ bind(context);
+
+ /* store the session and remove it from the manager */
+ if (manager instanceof StoreManager) {
+ Session session = manager.findSession(newsessionId);
+ Store store = ((StoreManager) manager).getStore();
+ if (store != null && session != null &&
session.isValid() &&
+ !isSessionStale(session,
System.currentTimeMillis())) {
+ store.save(session);
+ ((StoreManager) manager).removeSuper(session);
+ session.recycle();
+ } else {
+ if (container.getLogger().isDebugEnabled()) {
+ container.getLogger().debug("newsessionId
store: " +
+ store + " session: " + session +
+ " valid: " +
+ (session == null ? "N/A" :
Boolean.toString(
+ session.isValid())) +
+ " stale: " + isSessionStale(session,
+ System.currentTimeMillis()));
+ }
+
+ }
} else {
if (container.getLogger().isDebugEnabled()) {
- container.getLogger().debug("newsessionId store: "
+
- store + " session: " + session +
- " valid: " +
- (session == null ? "N/A" :
Boolean.toString(
- session.isValid())) +
- " stale: " + isSessionStale(session,
- System.currentTimeMillis()));
+ container.getLogger().debug("newsessionId Manager:
" +
+ manager);
}
}
- } else {
- if (container.getLogger().isDebugEnabled()) {
- container.getLogger().debug("newsessionId Manager: " +
- manager);
- }
+ } finally {
+ unbind(context);
}
}
}
@@ -186,4 +217,18 @@ public class PersistentValve extends Val
return false;
}
+
+
+ private void bind(Context context) {
+ if (clBindRequired) {
+ context.bind(Globals.IS_SECURITY_ENABLED, MY_CLASSLOADER);
+ }
+ }
+
+
+ private void unbind(Context context) {
+ if (clBindRequired) {
+ context.unbind(Globals.IS_SECURITY_ENABLED, MY_CLASSLOADER);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]