diff --git a/spring-webflow/src/main/java/org/springframework/webflow/context/portlet/PortletRequestParameterMap.java b/spring-webflow/src/main/java/org/springframework/webflow/context/portlet/PortletRequestParameterMap.java index cbb8b369..d9af187c 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/context/portlet/PortletRequestParameterMap.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/portlet/PortletRequestParameterMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.webflow.context.portlet; import java.util.Iterator; +import java.util.List; import javax.portlet.PortletRequest; @@ -29,7 +30,7 @@ import org.springframework.webflow.core.collection.CollectionUtils; /** * Map backed by the Portlet request parameter map for accessing request parameters. Also provides support for * multi-part requests, providing transparent access to the request "fileMap" as a request parameter entry. - * + * * @author Keith Donald * @author Scott Andrews */ @@ -51,9 +52,13 @@ public class PortletRequestParameterMap extends StringKeyedMapAdapter { protected Object getAttribute(String key) { if (request instanceof MultipartActionRequest) { MultipartActionRequest multipartRequest = (MultipartActionRequest) request; - MultipartFile data = multipartRequest.getFileMap().get(key); - if (data != null) { - return data; + List data = multipartRequest.getMultiFileMap().get(key); + if (data != null && data.size() > 0) { + if (data.size() == 1) { + return data.get(0); + } else { + return data; + } } } String[] parameters = request.getParameterValues(key); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/HttpServletRequestParameterMap.java b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/HttpServletRequestParameterMap.java index f647ca4c..3db2ca0d 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/HttpServletRequestParameterMap.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/HttpServletRequestParameterMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,21 @@ package org.springframework.webflow.context.servlet; import java.util.Iterator; +import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.binding.collection.StringKeyedMapAdapter; import org.springframework.util.Assert; import org.springframework.util.CompositeIterator; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.webflow.core.collection.CollectionUtils; /** * Map backed by the Servlet HTTP request parameter map for accessing request parameters. Also provides support for * multi-part requests, providing transparent access to the request "fileMap" as a request parameter entry. - * + * * @author Keith Donald */ public class HttpServletRequestParameterMap extends StringKeyedMapAdapter { @@ -49,9 +51,13 @@ public class HttpServletRequestParameterMap extends StringKeyedMapAdapter data = multipartRequest.getMultiFileMap().get(key); + if (data != null && data.size() > 0) { + if (data.size() == 1) { + return data.get(0); + } else { + return data; + } } } String[] parameters = request.getParameterValues(key); @@ -84,7 +90,6 @@ public class HttpServletRequestParameterMap extends StringKeyedMapAdapter getRequestParameterNames() { return CollectionUtils.toIterator(request.getParameterNames()); } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java b/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java index fc5ed81c..778a5073 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java @@ -19,6 +19,7 @@ import java.io.StringWriter; import java.io.Writer; import java.security.Principal; import java.util.HashMap; +import java.util.List; import java.util.Locale; import org.springframework.binding.collection.SharedMapDecorator; @@ -337,6 +338,16 @@ public class MockExternalContext implements ExternalContext { getMockRequestParameterMap().put(parameterName, parameterValue); } + /** + * Puts a multi-valued MultipartFile request parameter into the mock parameter map. + * + * @param parameterName the parameter name + * @param parameterValue the parameter value + */ + public void putRequestParameter(String parameterName, List parameterValue) { + getMockRequestParameterMap().put(parameterName, parameterValue); + } + /** * Sets the id of the event that should be signaled by this context. For use when resuming a flow. This method * depends on a MockViewFactory being configured for parsing the event id on a resume operation. diff --git a/spring-webflow/src/main/java/org/springframework/webflow/test/MockParameterMap.java b/spring-webflow/src/main/java/org/springframework/webflow/test/MockParameterMap.java index 28a7dbbe..92b6d2ef 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/test/MockParameterMap.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/test/MockParameterMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.webflow.test; import java.util.HashMap; +import java.util.List; import org.springframework.web.multipart.MultipartFile; import org.springframework.webflow.core.collection.LocalParameterMap; @@ -23,11 +24,12 @@ import org.springframework.webflow.core.collection.ParameterMap; /** * A extension of parameter map that allows for mutation of parameters. Useful as a stub for testing. - * + * * @see ParameterMap - * + * * @author Keith Donald */ +@SuppressWarnings("serial") public class MockParameterMap extends LocalParameterMap { /** @@ -70,4 +72,15 @@ public class MockParameterMap extends LocalParameterMap { return this; } + /** + * Add a new multi-valued multi-part file parameter to this map. + * @param parameterName the parameter name + * @param parameterValues the parameter values + * @return this, to support call chaining + */ + public MockParameterMap put(String parameterName, List parameterValues) { + getMapInternal().put(parameterName, parameterValues); + return this; + } + } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/test/MockRequestContext.java b/spring-webflow/src/main/java/org/springframework/webflow/test/MockRequestContext.java index db39638c..0be064e8 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/test/MockRequestContext.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/test/MockRequestContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package org.springframework.webflow.test; +import java.util.List; + import org.springframework.binding.message.DefaultMessageContext; import org.springframework.binding.message.MessageContext; import org.springframework.web.multipart.MultipartFile; @@ -38,10 +40,10 @@ import org.springframework.webflow.execution.View; /** * Mock implementation of the RequestContext interface to facilitate standalone flow artifact (e.g. action) * unit tests. - * + * * @see org.springframework.webflow.execution.RequestContext * @see org.springframework.webflow.execution.Action - * + * * @author Keith Donald * @author Erwin Vervaet */ @@ -299,6 +301,15 @@ public class MockRequestContext implements RequestContext { getMockExternalContext().putRequestParameter(parameterName, parameterValue); } + /** + * Puts a multi-valued MultipartFile request parameter into the mock parameter map. + * @param parameterName the parameter name + * @param parameterValue the parameter value + */ + public void putRequestParameter(String parameterName, List parameterValue) { + getMockExternalContext().putRequestParameter(parameterName, parameterValue); + } + // convenience accessors /**