Author: jacopoc
Date: Thu Apr 9 17:33:44 2015 New Revision: 1672430 URL: http://svn.apache.org/r1672430 Log: Fix for bug reported by Eric de Maulde in OFBIZ-5035: character encoding issue happening in the ecommerce application; the issue was caused by the CatalogUrlFilter and ContentUrlFilter because, under special conditions, they are preventing the ContextFilter (where encoding is set) to be executed. Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentUrlFilter.java ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java 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=1672430&r1=1672429&r2=1672430&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 Thu Apr 9 17:33:44 2015 @@ -56,6 +56,9 @@ public class ContentUrlFilter extends Co //Get ServletContext ServletContext servletContext = config.getServletContext(); + + ContextFilter.setCharacterEncoding(request); + //Set request attribute and session UrlServletHelper.setRequestAttributes(request, delegator, servletContext); String urlContentId = null; @@ -84,7 +87,8 @@ public class ContentUrlFilter extends Co StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append("/" + CONTROL_MOUNT_POINT); urlBuilder.append("/" + config.getInitParameter("viewRequest") + "?contentId=" + urlContentId); - + + ContextFilter.setAttributesFromRequestBody(request); //Set view query parameters UrlServletHelper.setViewQueryParameters(request, urlBuilder); Debug.logInfo("[Filtered request]: " + pathInfo + " (" + urlBuilder + ")", module); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java?rev=1672430&r1=1672429&r2=1672430&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java Thu Apr 9 17:33:44 2015 @@ -66,7 +66,9 @@ public class CatalogUrlFilter extends Co //Get ServletContext ServletContext servletContext = config.getServletContext(); - + + ContextFilter.setCharacterEncoding(request); + //Set request attribute and session UrlServletHelper.setRequestAttributes(request, delegator, servletContext); @@ -323,6 +325,7 @@ public class CatalogUrlFilter extends Co UrlServletHelper.setViewQueryParameters(request, urlBuilder); if (UtilValidate.isNotEmpty(productId) || UtilValidate.isNotEmpty(productCategoryId) || UtilValidate.isNotEmpty(urlContentId)) { Debug.logInfo("[Filtered request]: " + pathInfo + " (" + urlBuilder + ")", module); + ContextFilter.setAttributesFromRequestBody(request); RequestDispatcher dispatch = request.getRequestDispatcher(urlBuilder.toString()); dispatch.forward(request, response); return; 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=1672430&r1=1672429&r2=1672430&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 Thu Apr 9 17:33:44 2015 @@ -21,6 +21,7 @@ package org.ofbiz.webapp.control; import static org.ofbiz.base.util.UtilGenerics.checkMap; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.List; import java.util.Map; @@ -317,22 +318,11 @@ public class ContextFilter implements Fi } } - // read the body (for JSON requests) and set the parameters as attributes: - Map<String, Object> requestBodyMap = null; - try { - requestBodyMap = RequestBodyMapHandlerFactory.extractMapFromRequestBody(request); - } catch (IOException ioe) { - Debug.logWarning(ioe, module); - } - if (requestBodyMap != null) { - Set<String> parameterNames = requestBodyMap.keySet(); - for (String parameterName: parameterNames) { - httpRequest.setAttribute(parameterName, requestBodyMap.get(parameterName)); - } - } + setCharacterEncoding(request); + setAttributesFromRequestBody(request); // we're done checking; continue on - chain.doFilter(httpRequest, httpResponse); + chain.doFilter(request, httpResponse); } /** @@ -353,6 +343,33 @@ public class ContextFilter implements Fi return dispatcher; } + public static void setCharacterEncoding(ServletRequest request) throws UnsupportedEncodingException { + String charset = request.getServletContext().getInitParameter("charset"); + if (UtilValidate.isEmpty(charset)) charset = request.getCharacterEncoding(); + if (UtilValidate.isEmpty(charset)) charset = "UTF-8"; + if (Debug.verboseOn()) Debug.logVerbose("The character encoding of the request is: [" + request.getCharacterEncoding() + "]. The character encoding we will use for the request is: [" + charset + "]", module); + + if (!"none".equals(charset)) { + request.setCharacterEncoding(charset); + } + } + + public static void setAttributesFromRequestBody(ServletRequest request) { + // read the body (for JSON requests) and set the parameters as attributes: + Map<String, Object> requestBodyMap = null; + try { + requestBodyMap = RequestBodyMapHandlerFactory.extractMapFromRequestBody(request); + } catch (IOException ioe) { + Debug.logWarning(ioe, module); + } + if (requestBodyMap != null) { + Set<String> parameterNames = requestBodyMap.keySet(); + for (String parameterName: parameterNames) { + request.setAttribute(parameterName, requestBodyMap.get(parameterName)); + } + } + } + /** This method only sets up a dispatcher for the current webapp and passed in delegator, it does not save it to the ServletContext or anywhere else, just returns it */ public static LocalDispatcher makeWebappDispatcher(ServletContext servletContext, Delegator delegator) { if (delegator == null) { Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java?rev=1672430&r1=1672429&r2=1672430&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java Thu Apr 9 17:33:44 2015 @@ -98,18 +98,11 @@ public class ControlServlet extends Http HttpSession session = request.getSession(); // setup DEFAULT character encoding and content type, this will be overridden in the RequestHandler for view rendering - String charset = getServletContext().getInitParameter("charset"); - if (UtilValidate.isEmpty(charset)) charset = request.getCharacterEncoding(); - if (UtilValidate.isEmpty(charset)) charset = "UTF-8"; - if (Debug.verboseOn()) Debug.logVerbose("The character encoding of the request is: [" + request.getCharacterEncoding() + "]. The character encoding we will use for the request and response is: [" + charset + "]", module); - - if (!"none".equals(charset)) { - request.setCharacterEncoding(charset); - } + String charset = request.getCharacterEncoding(); // setup content type String contentType = "text/html"; - if (charset.length() > 0 && !"none".equals(charset)) { + if (UtilValidate.isNotEmpty(charset) && !"none".equals(charset)) { response.setContentType(contentType + "; charset=" + charset); response.setCharacterEncoding(charset); } else { |
Free forum by Nabble | Edit this page |