This is an automated email from the ASF dual-hosted git repository. nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 11cf350302015d1210b9f663cb9c68339701a3f8 Author: Nicolas Malin <[email protected]> AuthorDate: Tue Jan 28 17:52:19 2020 +0100 Improved: Change 'restMethod' by '_method' in request parameters (OFBIZ-11332) When we analyse a request method, we currently check the parameter "restMethod". Mathieu Lirzin propose [1] to use "_method" instead to use a parameter name more generic I create a new function UtilHttp.getRequestMethod() to centralize the request method resolution. [1] https://issues.apache.org/jira/browse/OFBIZ-11007?focusedCommentId=17012712&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17012712 --- .../src/main/java/org/apache/ofbiz/base/util/UtilHttp.java | 11 +++++++++++ .../java/org/apache/ofbiz/webapp/control/RequestHandler.java | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java index f4afecd..ed8babb 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java @@ -695,6 +695,17 @@ public final class UtilHttp { return requestUrl.toString(); } + /** Resolve the method send with the request. + * check first the parameter _method before return the request method + * @param request + * @return + */ + public static String getRequestMethod(HttpServletRequest request) { + return request.getParameter("_method") != null ? + request.getParameter("_method") : + request.getMethod(); + } + public static Locale getLocale(HttpServletRequest request, HttpSession session, Object appDefaultLocale) { // check session first, should override all if anything set there Object localeObject = session != null ? session.getAttribute("locale") : null; diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java index 9956de5..0e91bb1 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java @@ -260,8 +260,7 @@ public class RequestHandler { // The "overriddenView" attribute is set by resolveURI when necessary. String overrideViewUri = (String) request.getAttribute("overriddenView"); - String restMethod = request.getParameter("restMethod"); - String method = (restMethod != null) ? restMethod : request.getMethod(); + String method = UtilHttp.getRequestMethod(request); RequestMap requestMap = resolveMethod(method, rmaps).orElseThrow(() -> { String msg = UtilProperties.getMessage("WebappUiLabels", "RequestMethodNotMatchConfig", UtilMisc.toList(requestUri, method), UtilHttp.getLocale(request));

