Return-Path: Delivered-To: apmail-struts-commits-archive@locus.apache.org Received: (qmail 45361 invoked from network); 6 Dec 2007 11:05:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Dec 2007 11:05:53 -0000 Received: (qmail 8497 invoked by uid 500); 6 Dec 2007 11:05:37 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 8423 invoked by uid 500); 6 Dec 2007 11:05:36 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 8398 invoked by uid 99); 6 Dec 2007 11:05:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Dec 2007 03:05:36 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Dec 2007 11:05:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 640EF1A9832; Thu, 6 Dec 2007 03:05:13 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@struts.apache.org From: nilsga@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071206110513.640EF1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ org.springframework spring-mock 2.0.7 - test + test + + org.springframework + spring-portlet + 2.0.7 + test + org.springframework spring-core 2.0.7 + test + + + commons-fileupload + commons-fileupload + 1.1.1 test 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 extraContext = new HashMap(); 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 requestMap = new HashMap(); + Map paramMap = new HashMap(); + Map sessionMap = new HashMap(); + Map applicationMap = new HashMap(); + 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]); } - }