You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2013/10/23 21:35:17 UTC

svn commit: r1535129 - /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java

Author: adrianc
Date: Wed Oct 23 19:35:17 2013
New Revision: 1535129

URL: http://svn.apache.org/r1535129
Log:
The RequestHandler.makeLink method uses the new URL generation classes.

I tried to preserve the complicated boolean logic in the replaced block of code, but if I got something wrong, just leave a message on the dev mailing list.

Modified:
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java

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=1535129&r1=1535128&r2=1535129&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 Wed Oct 23 19:35:17 2013
@@ -20,6 +20,7 @@ package org.ofbiz.webapp.control;
 
 import static org.ofbiz.base.util.UtilGenerics.checkMap;
 
+import java.io.IOException;
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
@@ -49,6 +50,7 @@ import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.webapp.OfbizUrlBuilder;
 import org.ofbiz.webapp.event.EventFactory;
 import org.ofbiz.webapp.event.EventHandler;
 import org.ofbiz.webapp.event.EventHandlerException;
@@ -57,7 +59,6 @@ import org.ofbiz.webapp.view.ViewFactory
 import org.ofbiz.webapp.view.ViewHandler;
 import org.ofbiz.webapp.view.ViewHandlerException;
 import org.ofbiz.webapp.website.WebSiteWorker;
-import org.ofbiz.webapp.website.WebSiteProperties;
 import org.owasp.esapi.errors.EncodingException;
 
 /**
@@ -1112,55 +1113,40 @@ public class RequestHandler {
     }
 
     public String makeLink(HttpServletRequest request, HttpServletResponse response, String url, boolean fullPath, boolean secure, boolean encode) {
-        WebSiteProperties webSiteProps = (WebSiteProperties) request.getAttribute("_WEBSITE_PROPS_");
-        if (webSiteProps == null) {
+        OfbizUrlBuilder builder = (OfbizUrlBuilder) request.getAttribute("_OFBIZ_URL_BUILDER_");
+        if (builder == null) {
             try {
-                webSiteProps = WebSiteProperties.from(request);
-                request.setAttribute("_WEBSITE_PROPS_", webSiteProps);
+                builder = OfbizUrlBuilder.from(request);
+                request.setAttribute("_OFBIZ_URL_BUILDER_", builder);
             } catch (GenericEntityException e) {
                 // If the entity engine is throwing exceptions, then there is no point in continuing.
                 Debug.logError(e, "Exception thrown while getting web site properties: ", module);
                 return null;
-            }
-        }
-        String requestUri = RequestHandler.getRequestUri(url);
-        ConfigXMLReader.RequestMap requestMap = null;
-        if (requestUri != null) {
-            try {
-                requestMap = getControllerConfig().getRequestMapMap().get(requestUri);
             } catch (WebAppConfigurationException e) {
                 // If we can't read the controller.xml file, then there is no point in continuing.
                 Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
                 return null;
             }
         }
-        StringBuilder newURL = new StringBuilder();
         boolean didFullSecure = false;
         boolean didFullStandard = false;
-        if (requestMap != null && (webSiteProps.getEnableHttps() || fullPath || secure)) {
-            if (Debug.verboseOn()) Debug.logVerbose("In makeLink requestUri=" + requestUri, module);
-            if (secure || (webSiteProps.getEnableHttps() && requestMap.securityHttps && !request.isSecure())) {
-                String server = webSiteProps.getHttpsHost();
-                if (server.isEmpty()) {
-                    server = request.getServerName();
-                }
-                newURL.append("https://");
-                newURL.append(server);
-                if (!webSiteProps.getHttpsPort().isEmpty()) {
-                    newURL.append(":").append(webSiteProps.getHttpsPort());
-                }
-                didFullSecure = true;
-            } else if (fullPath || (webSiteProps.getEnableHttps() && !requestMap.securityHttps && request.isSecure())) {
-                String server = webSiteProps.getHttpHost();
-                if (server.isEmpty()) {
-                    server = request.getServerName();
-                }
-                newURL.append("http://");
-                newURL.append(server);
-                if (!webSiteProps.getHttpPort().isEmpty()) {
-                    newURL.append(":").append(webSiteProps.getHttpPort());
+        StringBuilder newURL = new StringBuilder(250);
+        if (fullPath) {
+            try {
+                boolean usesHttps = builder.buildHostPart(newURL, url, secure);
+                if (usesHttps) {
+                    didFullSecure = true;
+                } else {
+                    didFullStandard = true;
                 }
-                didFullStandard = true;
+            } catch (WebAppConfigurationException e) {
+                // If we can't read the controller.xml file, then there is no point in continuing.
+                Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
+                return null;
+            } catch (IOException e) {
+                // If we can't write to the buffer, then there is no point in continuing.
+                Debug.logError(e, "Exception thrown while appending to StringBuilder: ", module);
+                return null;
             }
         }
         // create the path to the control servlet



Re: svn commit: r1535129 - /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.j ava

Posted by Adrian Crum <ad...@sandglass-software.com>.
Thank you Jacques. I am looking into it now.

Adrian Crum
Sandglass Software
www.sandglass-software.com

On 10/24/2013 3:53 AM, Jacques Le Roux wrote:
> Hi Adrian,
>
> This introduced a bug in, at least, ecommerce login. The secured link is no longer generated and then you get an issue I reported here
> https://issues.apache.org/jira/browse/OFBIZ-5312?focusedCommentId=13804011
>
> I will have a look this afternoon (it's 1 PM here, lunch time ;o)
>
> Jacques
>
> adrianc@apache.org wrote:
>> Author: adrianc
>> Date: Wed Oct 23 19:35:17 2013
>> New Revision: 1535129
>>
>> URL: http://svn.apache.org/r1535129
>> Log:
>> The RequestHandler.makeLink method uses the new URL generation classes.
>>
>> I tried to preserve the complicated boolean logic in the replaced block of code, but if I got something wrong, just leave a
>> message on the dev mailing list.
>>
>> Modified:
>>     ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
>>
>> 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=1535129&r1=1535128&r2=1535129&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 Wed Oct 23 19:35:17 2013 @@ -20,6 +20,7 @@ package
>> org.ofbiz.webapp.control;
>>
>> import static org.ofbiz.base.util.UtilGenerics.checkMap;
>>
>> +import java.io.IOException;
>> import java.io.Serializable;
>> import java.io.UnsupportedEncodingException;
>> import java.net.URL;
>> @@ -49,6 +50,7 @@ import org.ofbiz.base.util.UtilValidate;
>> import org.ofbiz.entity.Delegator;
>> import org.ofbiz.entity.GenericEntityException;
>> import org.ofbiz.entity.GenericValue;
>> +import org.ofbiz.webapp.OfbizUrlBuilder;
>> import org.ofbiz.webapp.event.EventFactory;
>> import org.ofbiz.webapp.event.EventHandler;
>> import org.ofbiz.webapp.event.EventHandlerException;
>> @@ -57,7 +59,6 @@ import org.ofbiz.webapp.view.ViewFactory
>> import org.ofbiz.webapp.view.ViewHandler;
>> import org.ofbiz.webapp.view.ViewHandlerException;
>> import org.ofbiz.webapp.website.WebSiteWorker;
>> -import org.ofbiz.webapp.website.WebSiteProperties;
>> import org.owasp.esapi.errors.EncodingException;
>>
>> /**
>> @@ -1112,55 +1113,40 @@ public class RequestHandler {
>>      }
>>
>>      public String makeLink(HttpServletRequest request, HttpServletResponse response, String url, boolean fullPath, boolean
>> secure, boolean encode) {
>> -        WebSiteProperties webSiteProps = (WebSiteProperties) request.getAttribute("_WEBSITE_PROPS_");
>> -        if (webSiteProps == null) {
>> +        OfbizUrlBuilder builder = (OfbizUrlBuilder) request.getAttribute("_OFBIZ_URL_BUILDER_");
>> +        if (builder == null) {
>>              try {
>> -                webSiteProps = WebSiteProperties.from(request);
>> -                request.setAttribute("_WEBSITE_PROPS_", webSiteProps);
>> +                builder = OfbizUrlBuilder.from(request);
>> +                request.setAttribute("_OFBIZ_URL_BUILDER_", builder);
>>              } catch (GenericEntityException e) {
>>                  // If the entity engine is throwing exceptions, then there is no point in continuing.
>>                  Debug.logError(e, "Exception thrown while getting web site properties: ", module);
>>                  return null;
>> -            }
>> -        }
>> -        String requestUri = RequestHandler.getRequestUri(url);
>> -        ConfigXMLReader.RequestMap requestMap = null;
>> -        if (requestUri != null) {
>> -            try {
>> -                requestMap = getControllerConfig().getRequestMapMap().get(requestUri);
>>              } catch (WebAppConfigurationException e) {
>>                  // If we can't read the controller.xml file, then there is no point in continuing.
>>                  Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
>>                  return null;
>>              }
>>          }
>> -        StringBuilder newURL = new StringBuilder();
>>          boolean didFullSecure = false;
>>          boolean didFullStandard = false;
>> -        if (requestMap != null && (webSiteProps.getEnableHttps() || fullPath || secure)) {
>> -            if (Debug.verboseOn()) Debug.logVerbose("In makeLink requestUri=" + requestUri, module);
>> -            if (secure || (webSiteProps.getEnableHttps() && requestMap.securityHttps && !request.isSecure())) {
>> -                String server = webSiteProps.getHttpsHost();
>> -                if (server.isEmpty()) {
>> -                    server = request.getServerName();
>> -                }
>> -                newURL.append("https://");
>> -                newURL.append(server);
>> -                if (!webSiteProps.getHttpsPort().isEmpty()) {
>> -                    newURL.append(":").append(webSiteProps.getHttpsPort());
>> -                }
>> -                didFullSecure = true;
>> -            } else if (fullPath || (webSiteProps.getEnableHttps() && !requestMap.securityHttps && request.isSecure())) {
>> -                String server = webSiteProps.getHttpHost();
>> -                if (server.isEmpty()) {
>> -                    server = request.getServerName();
>> -                }
>> -                newURL.append("http://");
>> -                newURL.append(server);
>> -                if (!webSiteProps.getHttpPort().isEmpty()) {
>> -                    newURL.append(":").append(webSiteProps.getHttpPort());
>> +        StringBuilder newURL = new StringBuilder(250);
>> +        if (fullPath) {
>> +            try {
>> +                boolean usesHttps = builder.buildHostPart(newURL, url, secure);
>> +                if (usesHttps) {
>> +                    didFullSecure = true;
>> +                } else {
>> +                    didFullStandard = true;
>>                  }
>> -                didFullStandard = true;
>> +            } catch (WebAppConfigurationException e) {
>> +                // If we can't read the controller.xml file, then there is no point in continuing.
>> +                Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
>> +                return null;
>> +            } catch (IOException e) {
>> +                // If we can't write to the buffer, then there is no point in continuing.
>> +                Debug.logError(e, "Exception thrown while appending to StringBuilder: ", module);
>> +                return null;
>>              }
>>          }
>>          // create the path to the control servlet

Re: svn commit: r1535129 - /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.j ava

Posted by Jacques Le Roux <ja...@les7arts.com>.
Hi Adrian,

This introduced a bug in, at least, ecommerce login. The secured link is no longer generated and then you get an issue I reported here
https://issues.apache.org/jira/browse/OFBIZ-5312?focusedCommentId=13804011

I will have a look this afternoon (it's 1 PM here, lunch time ;o)

Jacques

adrianc@apache.org wrote:
> Author: adrianc
> Date: Wed Oct 23 19:35:17 2013
> New Revision: 1535129
> 
> URL: http://svn.apache.org/r1535129
> Log:
> The RequestHandler.makeLink method uses the new URL generation classes.
> 
> I tried to preserve the complicated boolean logic in the replaced block of code, but if I got something wrong, just leave a
> message on the dev mailing list. 
> 
> Modified:
>    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
> 
> 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=1535129&r1=1535128&r2=1535129&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 Wed Oct 23 19:35:17 2013 @@ -20,6 +20,7 @@ package
> org.ofbiz.webapp.control; 
> 
> import static org.ofbiz.base.util.UtilGenerics.checkMap;
> 
> +import java.io.IOException;
> import java.io.Serializable;
> import java.io.UnsupportedEncodingException;
> import java.net.URL;
> @@ -49,6 +50,7 @@ import org.ofbiz.base.util.UtilValidate;
> import org.ofbiz.entity.Delegator;
> import org.ofbiz.entity.GenericEntityException;
> import org.ofbiz.entity.GenericValue;
> +import org.ofbiz.webapp.OfbizUrlBuilder;
> import org.ofbiz.webapp.event.EventFactory;
> import org.ofbiz.webapp.event.EventHandler;
> import org.ofbiz.webapp.event.EventHandlerException;
> @@ -57,7 +59,6 @@ import org.ofbiz.webapp.view.ViewFactory
> import org.ofbiz.webapp.view.ViewHandler;
> import org.ofbiz.webapp.view.ViewHandlerException;
> import org.ofbiz.webapp.website.WebSiteWorker;
> -import org.ofbiz.webapp.website.WebSiteProperties;
> import org.owasp.esapi.errors.EncodingException;
> 
> /**
> @@ -1112,55 +1113,40 @@ public class RequestHandler {
>     }
> 
>     public String makeLink(HttpServletRequest request, HttpServletResponse response, String url, boolean fullPath, boolean
> secure, boolean encode) { 
> -        WebSiteProperties webSiteProps = (WebSiteProperties) request.getAttribute("_WEBSITE_PROPS_");
> -        if (webSiteProps == null) {
> +        OfbizUrlBuilder builder = (OfbizUrlBuilder) request.getAttribute("_OFBIZ_URL_BUILDER_");
> +        if (builder == null) {
>             try {
> -                webSiteProps = WebSiteProperties.from(request);
> -                request.setAttribute("_WEBSITE_PROPS_", webSiteProps);
> +                builder = OfbizUrlBuilder.from(request);
> +                request.setAttribute("_OFBIZ_URL_BUILDER_", builder);
>             } catch (GenericEntityException e) {
>                 // If the entity engine is throwing exceptions, then there is no point in continuing.
>                 Debug.logError(e, "Exception thrown while getting web site properties: ", module);
>                 return null;
> -            }
> -        }
> -        String requestUri = RequestHandler.getRequestUri(url);
> -        ConfigXMLReader.RequestMap requestMap = null;
> -        if (requestUri != null) {
> -            try {
> -                requestMap = getControllerConfig().getRequestMapMap().get(requestUri);
>             } catch (WebAppConfigurationException e) {
>                 // If we can't read the controller.xml file, then there is no point in continuing.
>                 Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
>                 return null;
>             }
>         }
> -        StringBuilder newURL = new StringBuilder();
>         boolean didFullSecure = false;
>         boolean didFullStandard = false;
> -        if (requestMap != null && (webSiteProps.getEnableHttps() || fullPath || secure)) {
> -            if (Debug.verboseOn()) Debug.logVerbose("In makeLink requestUri=" + requestUri, module);
> -            if (secure || (webSiteProps.getEnableHttps() && requestMap.securityHttps && !request.isSecure())) {
> -                String server = webSiteProps.getHttpsHost();
> -                if (server.isEmpty()) {
> -                    server = request.getServerName();
> -                }
> -                newURL.append("https://");
> -                newURL.append(server);
> -                if (!webSiteProps.getHttpsPort().isEmpty()) {
> -                    newURL.append(":").append(webSiteProps.getHttpsPort());
> -                }
> -                didFullSecure = true;
> -            } else if (fullPath || (webSiteProps.getEnableHttps() && !requestMap.securityHttps && request.isSecure())) {
> -                String server = webSiteProps.getHttpHost();
> -                if (server.isEmpty()) {
> -                    server = request.getServerName();
> -                }
> -                newURL.append("http://");
> -                newURL.append(server);
> -                if (!webSiteProps.getHttpPort().isEmpty()) {
> -                    newURL.append(":").append(webSiteProps.getHttpPort());
> +        StringBuilder newURL = new StringBuilder(250);
> +        if (fullPath) {
> +            try {
> +                boolean usesHttps = builder.buildHostPart(newURL, url, secure);
> +                if (usesHttps) {
> +                    didFullSecure = true;
> +                } else {
> +                    didFullStandard = true;
>                 }
> -                didFullStandard = true;
> +            } catch (WebAppConfigurationException e) {
> +                // If we can't read the controller.xml file, then there is no point in continuing.
> +                Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
> +                return null;
> +            } catch (IOException e) {
> +                // If we can't write to the buffer, then there is no point in continuing.
> +                Debug.logError(e, "Exception thrown while appending to StringBuilder: ", module);
> +                return null;
>             }
>         }
>         // create the path to the control servlet