svn commit: r1570810 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/content/ framework/base/src/org/ofbiz/base/util/ framework/webapp/src/org/ofbiz/webapp/control/ framework/webapp/src/org/ofbiz/webapp/stats/ specialpurpose/ecommerce/web...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1570810 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/content/ framework/base/src/org/ofbiz/base/util/ framework/webapp/src/org/ofbiz/webapp/control/ framework/webapp/src/org/ofbiz/webapp/stats/ specialpurpose/ecommerce/web...

jacopoc
Author: jacopoc
Date: Sat Feb 22 08:32:28 2014
New Revision: 1570810

URL: http://svn.apache.org/r1570810
Log:
Performance optimization for UtilHttp.getFullRequestUrl method: instead of returning a StringBuffer object (synchronized) it now returns a String (immutable); internally it uses a StringBuilder (lighter because not synchronized) within a private context.

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java
    ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/newmsg.ftl

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java?rev=1570810&r1=1570809&r2=1570810&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java Sat Feb 22 08:32:28 2014
@@ -67,8 +67,7 @@ public class ContentUrlFilter extends Co
         //Set request attribute and session
         UrlServletHelper.setRequestAttributes(request, delegator, servletContext);
         String urlContentId = null;
-        StringBuffer pathInfoBuffer = UtilHttp.getFullRequestUrl(httpRequest);
-        String pathInfo = pathInfoBuffer.toString();
+        String pathInfo = UtilHttp.getFullRequestUrl(httpRequest);
         if (UtilValidate.isNotEmpty(pathInfo)) {
             String alternativeUrl = pathInfo.substring(pathInfo.lastIndexOf("/"));
             if (alternativeUrl.endsWith("-content")) {

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java?rev=1570810&r1=1570809&r2=1570810&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilHttp.java Sat Feb 22 08:32:28 2014
@@ -553,11 +553,11 @@ public class UtilHttp {
             return;
         }
 
-        StringBuffer fullRequestUrl = getFullRequestUrl(request);
+        String fullRequestUrl = getFullRequestUrl(request);
 
         session.setAttribute("_WEBAPP_NAME_", getApplicationName(request));
         session.setAttribute("_CLIENT_LOCALE_", request.getLocale());
-        session.setAttribute("_CLIENT_REQUEST_", fullRequestUrl.toString());
+        session.setAttribute("_CLIENT_REQUEST_", fullRequestUrl);
         session.setAttribute("_CLIENT_USER_AGENT_", request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "");
         session.setAttribute("_CLIENT_REFERER_", request.getHeader("Referer") != null ? request.getHeader("Referer") : "");
 
@@ -579,8 +579,9 @@ public class UtilHttp {
         }
     }
 
-    public static StringBuffer getServerRootUrl(HttpServletRequest request) {
-        StringBuffer requestUrl = new StringBuffer();
+
+    private static StringBuilder prepareServerRootUrl(HttpServletRequest request) {
+        StringBuilder requestUrl = new StringBuilder();
         requestUrl.append(request.getScheme());
         requestUrl.append("://" + request.getServerName());
         if (request.getServerPort() != 80 && request.getServerPort() != 443)
@@ -588,13 +589,17 @@ public class UtilHttp {
         return requestUrl;
     }
 
-    public static StringBuffer getFullRequestUrl(HttpServletRequest request) {
-        StringBuffer requestUrl = getServerRootUrl(request);
+    public static String getServerRootUrl(HttpServletRequest request) {
+        return prepareServerRootUrl(request).toString();
+    }
+
+    public static String getFullRequestUrl(HttpServletRequest request) {
+        StringBuilder requestUrl = prepareServerRootUrl(request);
         requestUrl.append(request.getRequestURI());
         if (request.getQueryString() != null) {
             requestUrl.append("?" + request.getQueryString());
         }
-        return requestUrl;
+        return requestUrl.toString();
     }
 
     public static Locale getLocale(HttpServletRequest request, HttpSession session, Object appDefaultLocale) {

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java?rev=1570810&r1=1570809&r2=1570810&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java Sat Feb 22 08:32:28 2014
@@ -129,8 +129,7 @@ public class ContextFilter implements Fi
         httpRequest.setAttribute("_CONTEXT_ROOT_", config.getServletContext().getRealPath("/"));
 
         // set the server root url
-        StringBuffer serverRootUrl = UtilHttp.getServerRootUrl(httpRequest);
-        httpRequest.setAttribute("_SERVER_ROOT_URL_", serverRootUrl.toString());
+        httpRequest.setAttribute("_SERVER_ROOT_URL_", UtilHttp.getServerRootUrl(httpRequest));
 
         // request attributes from redirect call
         String reqAttrMapHex = (String) httpRequest.getSession().getAttribute("_REQ_ATTR_MAP_");

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java?rev=1570810&r1=1570809&r2=1570810&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java Sat Feb 22 08:32:28 2014
@@ -671,7 +671,7 @@ public class ServerHitBin {
             serverHit.set("contentId", this.id);
             serverHit.set("runningTimeMillis", Long.valueOf(runningTime));
 
-            String fullRequestUrl = UtilHttp.getFullRequestUrl(request).toString();
+            String fullRequestUrl = UtilHttp.getFullRequestUrl(request);
 
             serverHit.set("requestUrl", fullRequestUrl.length() > 250 ? fullRequestUrl.substring(0, 250) : fullRequestUrl);
             String referrerUrl = request.getHeader("Referer") != null ? request.getHeader("Referer") : "";

Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/newmsg.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/newmsg.ftl?rev=1570810&r1=1570809&r2=1570810&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/newmsg.ftl (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/newmsg.ftl Sat Feb 22 08:32:28 2014
@@ -34,7 +34,7 @@ under the License.
         <#if productStore?has_content>
           <input type="hidden" name="partyIdTo" value="${productStore.payToPartyId?if_exists}"/>
         </#if>
-        <input type="hidden" name="note" value="${Static["org.ofbiz.base.util.UtilHttp"].getFullRequestUrl(request).toString()}"/>
+        <input type="hidden" name="note" value="${Static["org.ofbiz.base.util.UtilHttp"].getFullRequestUrl(request)}"/>
         <#if message?has_content>
           <input type="hidden" name="parentCommEventId" value="${communicationEvent.communicationEventId}"/>
           <#if (communicationEvent.origCommEventId?exists && communicationEvent.origCommEventId?length > 0)>