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.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1570810 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacopo Cappellato
2014-02-22 08:32:28 +00:00
parent 0bf26e2829
commit 7d8d938a3b
5 changed files with 16 additions and 13 deletions
@@ -67,8 +67,7 @@ public class ContentUrlFilter extends ContextFilter {
//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")) {
@@ -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) {
@@ -129,8 +129,7 @@ public class ContextFilter implements Filter {
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_");
@@ -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") : "";
@@ -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)>