tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1067747 - /tomcat/trunk/java/org/apache/catalina/valves/CrawlerSessionManagerValve.java
Date Sun, 06 Feb 2011 20:30:39 GMT
Author: markt
Date: Sun Feb  6 20:30:38 2011
New Revision: 1067747

URL: http://svn.apache.org/viewvc?rev=1067747&view=rev
Log:
It isn't working. Add some debug logging.

Modified:
    tomcat/trunk/java/org/apache/catalina/valves/CrawlerSessionManagerValve.java

Modified: tomcat/trunk/java/org/apache/catalina/valves/CrawlerSessionManagerValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/CrawlerSessionManagerValve.java?rev=1067747&r1=1067746&r2=1067747&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/CrawlerSessionManagerValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/CrawlerSessionManagerValve.java Sun Feb 
6 20:30:38 2011
@@ -31,6 +31,8 @@ import javax.servlet.http.HttpSession;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
 
 /**
  * Web crawlers can trigger the creation of many thousands of sessions as they
@@ -41,6 +43,9 @@ import org.apache.catalina.connector.Res
  */
 public class CrawlerSessionManagerValve extends ValveBase {
 
+    private static final Log log =
+        LogFactory.getLog(CrawlerSessionManagerValve.class);
+
     private Map<String,SessionInfo> uaIpSessionInfo =
         new ConcurrentHashMap<String, SessionInfo>();
 
@@ -110,6 +115,12 @@ public class CrawlerSessionManagerValve 
         SessionInfo sessionInfo = null;
         String clientIp = null;
 
+        if (log.isDebugEnabled()) {
+            log.debug(request.hashCode() + ": ClientIp=" +
+                    request.getRemoteAddr() + ", RequestedSessionId=" +
+                    request.getRequestedSessionId());
+        }
+
         // If the incoming request has a session ID, no action is required
         if (request.getRequestedSessionId() == null) {
 
@@ -117,10 +128,21 @@ public class CrawlerSessionManagerValve 
             Enumeration<String> uaHeaders = request.getHeaders("user-agent");
             while (!isBot && uaMatcher != null &&
                     uaHeaders.hasMoreElements()) {
+                
                 String uaHeader = uaHeaders.nextElement();
                 uaMatcher.reset(uaHeader);
+                
+                if (log.isDebugEnabled()) {
+                    log.debug(request.hashCode() + ": UserAgent=" + uaHeader);
+                }
+                
                 if (uaMatcher.matches()) {
                     isBot = true;
+                    
+                    if (log.isDebugEnabled()) {
+                        log.debug(request.hashCode() +
+                                ": Bot found. UserAgent=" + uaHeader);
+                    }
                 }
             }
             
@@ -130,6 +152,11 @@ public class CrawlerSessionManagerValve 
                 sessionInfo = uaIpSessionInfo.get(clientIp);
                 if (sessionInfo != null) {
                     request.setRequestedSessionId(sessionInfo.getSessionId());
+
+                    if (log.isDebugEnabled()) {
+                        log.debug(request.hashCode() +
+                                ": SessionID=" + sessionInfo.getSessionId());
+                    }
                 }
             }
         }
@@ -143,9 +170,20 @@ public class CrawlerSessionManagerValve 
                 if (s != null) {
                     uaIpSessionInfo.put(clientIp, new SessionInfo(s.getId()));
                     s.setMaxInactiveInterval(sessionInactiveInterval);
+
+                    if (log.isDebugEnabled()) {
+                        log.debug(request.hashCode() +
+                                ": New bot session. SessionID=" + s.getId());
+                    }
                 }
             } else {
                 sessionInfo.access();
+
+                if (log.isDebugEnabled()) {
+                    log.debug(request.hashCode() +
+                            ": Bot session accessed. SessionID=" +
+                            sessionInfo.getSessionId());
+                }
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message