struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nil...@apache.org
Subject svn commit: r601700 - in /struts/struts2/trunk/plugins/portlet: pom.xml src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
Date Thu, 06 Dec 2007 11:05:12 GMT
Author: nilsga
Date: Thu Dec  6 03:05:08 2007
New Revision: 601700

URL: http://svn.apache.org/viewvc?rev=601700&view=rev
Log:
WW-2347,WW-2348 - Make multipart form fields available in the parameter map.

Modified:
    struts/struts2/trunk/plugins/portlet/pom.xml
    struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
    struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java

Modified: struts/struts2/trunk/plugins/portlet/pom.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/pom.xml?rev=601700&r1=601699&r2=601700&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/pom.xml (original)
+++ struts/struts2/trunk/plugins/portlet/pom.xml Thu Dec  6 03:05:08 2007
@@ -124,12 +124,24 @@
             <groupId>org.springframework</groupId>
             <artifactId>spring-mock</artifactId>
             <version>2.0.7</version>
-      <scope>test</scope>
+			<scope>test</scope>
         </dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-portlet</artifactId>
+			<version>2.0.7</version>
+			<scope>test</scope>
+		</dependency>
     <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
             <version>2.0.7</version>
+      <scope>test</scope>
+        </dependency>
+		<dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+			<version>1.1.1</version>
       <scope>test</scope>
         </dependency>
    </dependencies>

Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java?rev=601700&r1=601699&r2=601700&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
Thu Dec  6 03:05:08 2007
@@ -21,6 +21,7 @@
 package org.apache.struts2.portlet.dispatcher;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Locale;
@@ -50,6 +51,7 @@
 import org.apache.struts2.dispatcher.SessionMap;
 import org.apache.struts2.dispatcher.mapper.ActionMapper;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
 import org.apache.struts2.portlet.PortletActionConstants;
 import org.apache.struts2.portlet.PortletApplicationMap;
 import org.apache.struts2.portlet.PortletRequestMap;
@@ -358,6 +360,11 @@
     	ServletContext dummyServletContext = new PortletServletContext(getPortletContext());
     	if(EVENT_PHASE.equals(phase)) {
     		dummyRequest = dispatcherUtils.wrapRequest(dummyRequest, dummyServletContext);
+    		if(dummyRequest instanceof MultiPartRequestWrapper) {
+    			// Multipart request. Request parameters are encoded in the multipart data,
+    			// so we need to manually add them to the parameter map.
+    			parameterMap.putAll(dummyRequest.getParameterMap());
+    		}
     	}
         // ServletActionContext
         HashMap<String,Object> extraContext = new HashMap<String,Object>();

Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java?rev=601700&r1=601699&r2=601700&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
Thu Dec  6 03:05:08 2007
@@ -20,6 +20,7 @@
  */
 package org.apache.struts2.portlet.dispatcher;
 
+import java.io.File;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -36,19 +37,16 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-
-import junit.textui.TestRunner;
 
 import org.apache.struts2.StrutsConstants;
-import org.apache.struts2.dispatcher.mapper.ActionMapper;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
 import org.apache.struts2.portlet.PortletActionConstants;
 import org.easymock.EasyMock;
 import org.jmock.Mock;
 import org.jmock.cglib.MockObjectTestCase;
 import org.jmock.core.Constraint;
+import org.springframework.mock.web.portlet.MockActionRequest;
+import org.springframework.mock.web.portlet.MockActionResponse;
 import org.springframework.mock.web.portlet.MockPortletConfig;
 import org.springframework.mock.web.portlet.MockPortletContext;
 
@@ -57,7 +55,6 @@
 import com.opensymphony.xwork2.ActionProxy;
 import com.opensymphony.xwork2.ActionProxyFactory;
 import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
 
 /**
  * Jsr168DispatcherTest. Insert description.
@@ -65,6 +62,17 @@
  */
 public class Jsr168DispatcherTest extends MockObjectTestCase implements PortletActionConstants
{
 
+	private final String MULTIPART_REQUEST = "-----------------------------4827543632391\r\n"

+		+ "Content-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\n"
+		+ "Content-Type: text/plain\r\n"
+		+ "\r\n"
+		+ "This is a test file\r\n"
+		+ "-----------------------------4827543632391\r\n"
+		+ "Content-Disposition: form-data; name=\"caption\"\r\n"
+		+ "\r\n"
+		+ "TestCaption\r\n"
+		+ "-----------------------------4827543632391--";
+	
     Jsr168Dispatcher dispatcher = null;
     Mock mockConfig = null;
     Mock mockCtx = null;
@@ -304,9 +312,24 @@
             fail("Error occured");
         }
     }
-
-    public static void main(String[] args) {
-        TestRunner.run(Jsr168DispatcherTest.class);
+    
+    public void testMultipartRequest_parametersAreCopiedToActionInvocation() throws Exception
{
+    	MockPortletContext ctx = new MockPortletContext();
+    	ctx.setAttribute("javax.servlet.context.tempdir", new File("target").getAbsoluteFile());
+    	MockActionRequest request = new MockActionRequest(ctx);
+    	request.setContent(MULTIPART_REQUEST.getBytes("US-ASCII"));
+    	request.setContentType("multipart/form-data; boundary=---------------------------4827543632391");
+    	request.setProperty("Content-Length", "" + MULTIPART_REQUEST.length());
+    	MockActionResponse response = new MockActionResponse();
+    	Map<String, Object> requestMap = new HashMap<String, Object>();
+    	Map<String, String[]> paramMap = new HashMap<String, String[]>();
+    	Map<String, Object> sessionMap = new HashMap<String, Object>();
+    	Map<String, Object> applicationMap = new HashMap<String, Object>();
+    	initPortletConfig(new HashMap(), new HashMap());
+    	MockPortletConfig config = new MockPortletConfig(ctx);
+    	dispatcher.init(config);
+    	dispatcher.createContextMap(requestMap, paramMap, sessionMap, applicationMap, request,
response, config, PortletActionConstants.EVENT_PHASE);
+    	assertNotNull("Caption was not found in parameter map!", paramMap.get("caption"));
+    	assertEquals("TestCaption", paramMap.get("caption")[0]);
     }
-
 }



Mime
View raw message