You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Skip Dever (JIRA)" <ji...@apache.org> on 2013/06/12 00:46:20 UTC

[jira] [Updated] (OFBIZ-5220) request-redirect does not pass all parameters if none are specified with response-parameter

     [ https://issues.apache.org/jira/browse/OFBIZ-5220?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Skip Dever updated OFBIZ-5220:
------------------------------

    Description: 
The xsd documentation says "Automatically redirect all current request parameters to the new request or only redirected ..."

This is broken.  If you specify a request-redirect from a form (where the parameters are not in the url), these parameters are not passed on to the redirected url. 

Included here is a re-written function in RequestHandler.java is a solution that fixes things (Note that I did not modify the javadoc which describes how this new function actually works).  I commented out the old code and added there new stuff under the comment:

    /**
     * Creates a query string based on the redirect parameters for a request response, if specified, or for all request parameters if no redirect parameters are specified.
     *
     * @param request the Http request
     * @param requestResponse the RequestResponse Object
     * @return return the query string
     */
    public String makeQueryString(HttpServletRequest request, ConfigXMLReader.RequestResponse requestResponse) {
        if (requestResponse == null ||
                (requestResponse.redirectParameterMap.size() == 0 && requestResponse.redirectParameterValueMap.size() == 0)) {
			/* Modified by skipd to include all parameters if non are specified with redirect-parameter
            Map<String, Object> urlParams = UtilHttp.getUrlOnlyParameterMap(request);
            String queryString = UtilHttp.urlEncodeArgs(urlParams, false);
            if(UtilValidate.isEmpty(queryString)) {
                return queryString;
            }
			*/
            StringBuilder queryString = new StringBuilder();
            Map<String, Object> parameters = UtilHttp.getParameterMap(request);
            for (String parameterName: parameters.keySet()) {
                Object value = parameters.get(parameterName);

                addNameValuePairToQueryString(queryString, parameterName, (String) value);
            }
            return "?" + queryString;
        } else {
            StringBuilder queryString = new StringBuilder();
            queryString.append("?");
			//Added by skipd
            Map<String, Object> parameters = UtilHttp.getParameterMap(request);
            for (Map.Entry<String, String> entry: requestResponse.redirectParameterMap.entrySet()) {
                String name = entry.getKey();
                String from = entry.getValue();

                Object value = request.getAttribute(from);
                if (value == null) {
                	//Modified by skipd
                    value = parameters.get(from);
                    //value = request.getParameter(from);
                }

                addNameValuePairToQueryString(queryString, name, (String) value);
            }
            for (Map.Entry<String, String> entry: requestResponse.redirectParameterValueMap.entrySet()) {
                String name = entry.getKey();
                String value = entry.getValue();

                addNameValuePairToQueryString(queryString, name, (String) value);
            }
            return queryString.toString();
        }
    }


  was:
The xsd documentation says "Automatically redirect all current request parameters to the new request or only redirected ..."

This is broken.  If you specify a request-redirect from a form (where the parameters are not in the url), these parameters are not passed on to the redirected url. 

Included here is a re-written function in RequestHandler.java is a solution that fixes things (Note that I did not modify the javadoc which describes how this new function actually works).  I commented out the old code and added there new stuff under the comment:

    /**
     * Creates a query string based on the redirect parameters for a request response, if specified, or for all request parameters if no redirect parameters are specified.
     *
     * @param request the Http request
     * @param requestResponse the RequestResponse Object
     * @return return the query string
     */
    public String makeQueryString(HttpServletRequest request, ConfigXMLReader.RequestResponse requestResponse) {
        if (requestResponse == null ||
                (requestResponse.redirectParameterMap.size() == 0 && requestResponse.redirectParameterValueMap.size() == 0)) {
			/* Modified by skipd to include all parameters if none are specified with redirect-parameter
            Map<String, Object> urlParams = UtilHttp.getUrlOnlyParameterMap(request);
            String queryString = UtilHttp.urlEncodeArgs(urlParams, false);
            if(UtilValidate.isEmpty(queryString)) {
                return queryString;
            }
			*/
            StringBuilder queryString = new StringBuilder();
            Map<String, Object> parameters = UtilHttp.getParameterMap(request);
            for (String parameterName: parameters.keySet()) {
                Object value = parameters.get(parameterName);

                addNameValuePairToQueryString(queryString, parameterName, (String) value);
            }
            return "?" + queryString;
        } else {
            StringBuilder queryString = new StringBuilder();
            queryString.append("?");
            for (Map.Entry<String, String> entry: requestResponse.redirectParameterValueMap.entrySet()) {
                String name = entry.getKey();
                String value = entry.getValue();

                addNameValuePairToQueryString(queryString, name, (String) value);
            }
            return queryString.toString();
        }
    }



Added back in the code added in 12.04 with a patch to get the parameter from the parameter map instead of the request
                
> request-redirect does not pass all parameters if none are specified with response-parameter
> -------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-5220
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-5220
>             Project: OFBiz
>          Issue Type: Bug
>          Components: ALL APPLICATIONS
>    Affects Versions: Release Branch 12.04
>         Environment: All
>            Reporter: Skip Dever
>              Labels: patch
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> The xsd documentation says "Automatically redirect all current request parameters to the new request or only redirected ..."
> This is broken.  If you specify a request-redirect from a form (where the parameters are not in the url), these parameters are not passed on to the redirected url. 
> Included here is a re-written function in RequestHandler.java is a solution that fixes things (Note that I did not modify the javadoc which describes how this new function actually works).  I commented out the old code and added there new stuff under the comment:
>     /**
>      * Creates a query string based on the redirect parameters for a request response, if specified, or for all request parameters if no redirect parameters are specified.
>      *
>      * @param request the Http request
>      * @param requestResponse the RequestResponse Object
>      * @return return the query string
>      */
>     public String makeQueryString(HttpServletRequest request, ConfigXMLReader.RequestResponse requestResponse) {
>         if (requestResponse == null ||
>                 (requestResponse.redirectParameterMap.size() == 0 && requestResponse.redirectParameterValueMap.size() == 0)) {
> 			/* Modified by skipd to include all parameters if non are specified with redirect-parameter
>             Map<String, Object> urlParams = UtilHttp.getUrlOnlyParameterMap(request);
>             String queryString = UtilHttp.urlEncodeArgs(urlParams, false);
>             if(UtilValidate.isEmpty(queryString)) {
>                 return queryString;
>             }
> 			*/
>             StringBuilder queryString = new StringBuilder();
>             Map<String, Object> parameters = UtilHttp.getParameterMap(request);
>             for (String parameterName: parameters.keySet()) {
>                 Object value = parameters.get(parameterName);
>                 addNameValuePairToQueryString(queryString, parameterName, (String) value);
>             }
>             return "?" + queryString;
>         } else {
>             StringBuilder queryString = new StringBuilder();
>             queryString.append("?");
> 			//Added by skipd
>             Map<String, Object> parameters = UtilHttp.getParameterMap(request);
>             for (Map.Entry<String, String> entry: requestResponse.redirectParameterMap.entrySet()) {
>                 String name = entry.getKey();
>                 String from = entry.getValue();
>                 Object value = request.getAttribute(from);
>                 if (value == null) {
>                 	//Modified by skipd
>                     value = parameters.get(from);
>                     //value = request.getParameter(from);
>                 }
>                 addNameValuePairToQueryString(queryString, name, (String) value);
>             }
>             for (Map.Entry<String, String> entry: requestResponse.redirectParameterValueMap.entrySet()) {
>                 String name = entry.getKey();
>                 String value = entry.getValue();
>                 addNameValuePairToQueryString(queryString, name, (String) value);
>             }
>             return queryString.toString();
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira