You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/09/12 00:09:40 UTC

svn commit: r574709 - in /ofbiz/trunk/framework/webapp: dtd/site-conf.xsd src/org/ofbiz/webapp/control/ConfigXMLReader.java src/org/ofbiz/webapp/control/ControlServlet.java src/org/ofbiz/webapp/control/RequestHandler.java

Author: jaz
Date: Tue Sep 11 15:09:40 2007
New Revision: 574709

URL: http://svn.apache.org/viewvc?rev=574709&view=rev
Log:
added code to disable ServiceHit and Visit tracking for defined requests (use new track-stats and track-visit attributes on the request URI); also supports disabling tracking per webapp (use init param track-stats and track-visit)

Modified:
    ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java

Modified: ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd?rev=574709&r1=574708&r2=574709&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/dtd/site-conf.xsd (original)
+++ ofbiz/trunk/framework/webapp/dtd/site-conf.xsd Tue Sep 11 15:09:40 2007
@@ -138,6 +138,22 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+        <xs:attribute name="track-visit" default="true">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
+        <xs:attribute name="track-stats" default="true">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
     </xs:attributeGroup>
     <xs:element name="security">
         <xs:complexType>

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?rev=574709&r1=574708&r2=574709&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java Tue Sep 11 15:09:40 2007
@@ -99,6 +99,8 @@
     public static final String REQUEST_MAPPING = "request-map";
     public static final String REQUEST_URI = "uri";
     public static final String REQUEST_EDIT = "edit";
+    public static final String REQUEST_TRACK_STATS = "track-stats";
+    public static final String REQUEST_TRACK_VISIT = "track-visit";
 
     public static final String REQUEST_DESCRIPTION = "description";
     public static final String ERROR_PAGE = "error";
@@ -195,12 +197,16 @@
             // Get the URI info.
             String uri = requestMapElement.getAttribute(REQUEST_URI);
             String edit = requestMapElement.getAttribute(REQUEST_EDIT);
+            String stats = requestMapElement.getAttribute(REQUEST_TRACK_STATS);
+            String visit = requestMapElement.getAttribute(REQUEST_TRACK_VISIT);
 
             if (edit == null || edit.equals(""))
                 edit = "true";
             if (uri != null) {
                 uriMap.put(REQUEST_URI, uri);
                 uriMap.put(REQUEST_EDIT, edit);
+                uriMap.put(REQUEST_TRACK_STATS, stats);
+                uriMap.put(REQUEST_TRACK_VISIT, visit);
             }
 
             // Check for security.

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java?rev=574709&r1=574708&r2=574709&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java Tue Sep 11 15:09:40 2007
@@ -281,7 +281,11 @@
             try {
                 UtilHttp.setInitialRequestInfo(request);
                 VisitHandler.getVisitor(request, response);
-                ServerHitBin.countRequest(webappName + "." + rname, request, requestStartTime, System.currentTimeMillis() - requestStartTime, userLogin, delegator);
+                if (requestHandler.trackStats(request)) {
+                    ServerHitBin.countRequest(webappName + "." + rname, request, requestStartTime, System.currentTimeMillis() - requestStartTime, userLogin, delegator);
+                } else {
+                    Debug.log("Track status is disabled for this request");
+                }
             } catch (Throwable t) {
                 Debug.logError(t, "Error in ControlServlet saving ServerHit/Bin information; the output was successful, but can't save this tracking information. The error was: " + t.toString(), module);
             }

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=574709&r1=574708&r2=574709&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Tue Sep 11 15:09:40 2007
@@ -176,13 +176,13 @@
             }
 
             // If its the first visit run the first visit events.
-            if (session.getAttribute("visit") == null) {
+            if (this.trackVisit(request) && session.getAttribute("visit") == null) {
                 Debug.logInfo("This is the first request in this visit." + " sessionId=" + UtilHttp.getSessionId(request), module);
                 // This isn't an event because it is required to run. We do not want to make it optional.
-                VisitHandler.getVisit(session);
+                GenericValue visit = VisitHandler.getVisit(session);
                 Collection events = requestManager.getFirstVisitEvents();
 
-                if (events != null) {
+                if (visit != null && events != null) {
                     Iterator i = events.iterator();
 
                     while (i.hasNext()) {
@@ -203,6 +203,8 @@
                         }
                     }
                 }
+            } else {
+                Debug.log("Track visit is disabled for this request");
             }
 
             // Invoke the pre-processor (but NOT in a chain)
@@ -277,8 +279,9 @@
                     eventReturnString = this.runEvent(request, response, eventType, eventPath, eventMethod);
 
                     // save the server hit
-                    ServerHitBin.countEvent(cname + "." + eventMethod, request, eventStartTime,
-                            System.currentTimeMillis() - eventStartTime, userLogin, delegator);
+                    if (this.trackStats(request))
+                        ServerHitBin.countEvent(cname + "." + eventMethod, request, eventStartTime,
+                                System.currentTimeMillis() - eventStartTime, userLogin, delegator);
 
                     // set the default event return
                     if (eventReturnString == null) {
@@ -352,7 +355,6 @@
             // special case to avoid login/logout looping: if request was "logout" before the login, change to null for default success view; do the same for "login" to avoid going back to the same page
             if ("logout".equals(previousRequest) || "/logout".equals(previousRequest) || "login".equals(previousRequest) || "/login".equals(previousRequest) || "checkLogin".equals(previousRequest) || "/checkLogin".equals(previousRequest)) {
                 Debug.logWarning("Found special _PREVIOUS_REQUEST_ of [" + previousRequest + "], setting to null to avoid problems, not running request again", module);
-                previousRequest = null;
             } else {
                 if (Debug.infoOn()) Debug.logInfo("[Doing Previous Request]: " + previousRequest + " sessionId=" + UtilHttp.getSessionId(request), module);
                 doRequest(request, response, previousRequest, userLogin, delegator);
@@ -654,7 +656,7 @@
 
         String vname = (String) req.getAttribute("_CURRENT_VIEW_");
 
-        if (vname != null) {
+        if (this.trackStats(req) && vname != null) {
             ServerHitBin.countView(cname + "." + vname, req, viewStartTime,
                 System.currentTimeMillis() - viewStartTime, userLogin, delegator);
         }
@@ -748,7 +750,7 @@
             httpServer = UtilProperties.getPropertyValue("url.properties", "force.http.host");
         }
         if (enableHttps == null) {
-            enableHttps = Boolean.valueOf(UtilProperties.propertyValueEqualsIgnoreCase("url.properties", "port.https.enabled", "Y"));
+            enableHttps = UtilProperties.propertyValueEqualsIgnoreCase("url.properties", "port.https.enabled", "Y");
         }
 
         // create the path the the control servlet
@@ -757,11 +759,10 @@
         String requestUri = RequestHandler.getRequestUri(url);
         StringBuffer newURL = new StringBuffer();
 
-        boolean useHttps = enableHttps.booleanValue();
         boolean didFullSecure = false;
         boolean didFullStandard = false;
-        if (useHttps || fullPath || secure) {
-            if (secure || (useHttps && requestManager.requiresHttps(requestUri) && !request.isSecure())) {
+        if (enableHttps || fullPath || secure) {
+            if (secure || (enableHttps && requestManager.requiresHttps(requestUri) && !request.isSecure())) {
                 String server = httpsServer;
                 if (server == null || server.length() == 0) {
                     server = request.getServerName();
@@ -774,7 +775,7 @@
                 }
 
                 didFullSecure = true;
-            } else if (fullPath || (useHttps && !requestManager.requiresHttps(requestUri) && request.isSecure())) {
+            } else if (fullPath || (enableHttps && !requestManager.requiresHttps(requestUri) && request.isSecure())) {
                 String server = httpServer;
                 if (server == null || server.length() == 0) {
                     server = request.getServerName();
@@ -895,6 +896,26 @@
                     Debug.logError(e, module);
                 }
             }
+        }
+    }
+
+    public boolean trackStats(HttpServletRequest request) {
+        String appStats = context.getInitParameter("track-stats");
+        if (appStats != null && !"false".equalsIgnoreCase(appStats)) {
+            String uriString =  RequestHandler.getRequestUri(request.getPathInfo());
+            return !"false".equalsIgnoreCase(requestManager.getRequestAttribute(uriString, ConfigXMLReader.REQUEST_TRACK_STATS));
+        } else {
+            return false;
+        }
+    }
+
+    public boolean trackVisit(HttpServletRequest request) {
+        String appVisit = context.getInitParameter("track-visit");
+        if (appVisit != null && !"false".equalsIgnoreCase(appVisit)) {
+            String uriString =  RequestHandler.getRequestUri(request.getPathInfo());
+            return !"false".equalsIgnoreCase(requestManager.getRequestAttribute(uriString, ConfigXMLReader.REQUEST_TRACK_VISIT));
+        } else {
+            return false;
         }
     }
 }