Author: jacopoc
Date: Mon Mar 9 09:26:18 2015 New Revision: 1665162 URL: http://svn.apache.org/r1665162 Log: Fix for issue happening when a service event was executed using JSON (i.e. parameters in the request body) after a getParameter was called (by other framework code) to fetch the parameter from the body; in that case an io error was thrown because the reuest body stream can be read only once. This fix move the code that reads the JSON parameters from the body into the ContextFilter: the parameters are then stored as attributes that can be later used by events and other artifacts (service events, simple events, scripts events support this and Java events if they use UtilHttp.getCombinedMap(request) to get the map of input parameters. Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java?rev=1665162&r1=1665161&r2=1665162&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java Mon Mar 9 09:26:18 2015 @@ -82,7 +82,7 @@ public final class MethodContext { public MethodContext(HttpServletRequest request, HttpServletResponse response, ClassLoader loader) { this.methodType = MethodContext.EVENT; - this.parameters = UtilHttp.getParameterMap(request); + this.parameters = UtilHttp.getCombinedMap(request); this.loader = loader; this.request = request; this.response = response; 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=1665162&r1=1665161&r2=1665162&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 Mon Mar 9 09:26:18 2015 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Enumeration; import java.util.List; import java.util.Map; +import java.util.Set; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -54,6 +55,7 @@ import org.ofbiz.security.SecurityConfig import org.ofbiz.security.SecurityFactory; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceContainer; +import org.ofbiz.webapp.event.RequestBodyMapHandlerFactory; import org.ofbiz.webapp.website.WebSiteWorker; /** @@ -317,6 +319,20 @@ 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)); + } + } + // we're done checking; continue on chain.doFilter(httpRequest, httpResponse); } Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java?rev=1665162&r1=1665161&r2=1665162&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java Mon Mar 9 09:26:18 2015 @@ -21,7 +21,6 @@ package org.ofbiz.webapp.event; import static org.ofbiz.base.util.UtilGenerics.checkList; import java.io.File; -import java.io.IOException; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.LinkedList; @@ -231,17 +230,8 @@ public class ServiceEventHandler impleme // store the multi-part map as an attribute so we can access the parameters request.setAttribute("multiPartMap", multiPartMap); - Map<String, Object> rawParametersMap = UtilHttp.getParameterMap(request, null, null); + Map<String, Object> rawParametersMap = UtilHttp.getCombinedMap(request); Set<String> urlOnlyParameterNames = UtilHttp.getUrlOnlyParameterMap(request).keySet(); - Map<String, Object> requestBodyMap = null; - try { - requestBodyMap = RequestBodyMapHandlerFactory.extractMapFromRequestBody(request); - } catch (IOException ioe) { - Debug.logWarning(ioe, module); - } - if (requestBodyMap != null) { - rawParametersMap.putAll(requestBodyMap); - } // we have a service and the model; build the context Map<String, Object> serviceContext = new HashMap<String, Object>(); |
Free forum by Nabble | Edit this page |