You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2003/11/13 02:29:59 UTC
cvs commit: jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet PerformForward.java PerformInclude.java PopulateActionForm.java ValidateActionForm.java
mrdon 2003/11/12 17:29:59
Modified: contrib/struts-chain/src/conf chain-config.xml
contrib/struts-chain/src/java/org/apache/struts/chain/legacy
ComposableRequestProcessor.java
contrib/struts-chain/src/java/org/apache/struts/chain/servlet
PerformForward.java PerformInclude.java
PopulateActionForm.java ValidateActionForm.java
Log:
Added support for multipart requests (file uploads). Should perfectly emulate
legacy behavior.
Revision Changes Path
1.9 +2 -2 jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml
Index: chain-config.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- chain-config.xml 25 Oct 2003 01:16:52 -0000 1.8
+++ chain-config.xml 13 Nov 2003 01:29:59 -0000 1.9
@@ -58,7 +58,7 @@
between the processXxx methods and the Commands that perform the
corresponding functionality:
- processMultipart NOT SUPPORTED YET (so no file upload support)
+ processMultipart Integrated into servlet and legacy classes
processPath SelectAction (which also does processMapping)
1.5 +31 -4 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/ComposableRequestProcessor.java
Index: ComposableRequestProcessor.java
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/ComposableRequestProcessor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ComposableRequestProcessor.java 29 Sep 2003 06:55:07 -0000 1.4
+++ ComposableRequestProcessor.java 13 Nov 2003 01:29:59 -0000 1.5
@@ -73,6 +73,7 @@
import org.apache.struts.action.ActionServlet;
import org.apache.struts.chain.Constants;
import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.Command;
@@ -95,6 +96,7 @@
* @author Craig R. McClanahan
* @author Cedric Dumoulin
* @author Greg Reddin
+ * @author Don Brown
*
* @version $Revision$ $Date$
* @since Struts 1.1
@@ -173,6 +175,9 @@
HttpServletResponse response)
throws IOException, ServletException {
+ // Wrap the request in the case of a multipart request
+ request = processMultipart(request);
+
// Create and populate a Context for this request
ServletWebContext context = new ServletWebContext();
context.initialize(getServletContext(), request, response);
@@ -197,6 +202,28 @@
// Release the context.
context.release();
+ }
+
+ /**
+ * If this is a multipart request, wrap it with a special wrapper.
+ * Otherwise, return the request unchanged.
+ *
+ * @param request The HttpServletRequest we are processing
+ */
+ protected HttpServletRequest processMultipart(HttpServletRequest request) {
+
+ if (!"POST".equalsIgnoreCase(request.getMethod())) {
+ return (request);
+ }
+
+ String contentType = request.getContentType();
+ if ((contentType != null) &&
+ contentType.startsWith("multipart/form-data")) {
+ return (new MultipartRequestWrapper(request));
+ } else {
+ return (request);
+ }
+
}
1.2 +15 -6 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PerformForward.java
Index: PerformForward.java
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PerformForward.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PerformForward.java 11 Aug 2003 04:55:34 -0000 1.1
+++ PerformForward.java 13 Nov 2003 01:29:59 -0000 1.2
@@ -63,12 +63,14 @@
import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.web.servlet.ServletWebContext;
import org.apache.struts.Globals;
import org.apache.struts.chain.AbstractPerformForward;
import org.apache.struts.chain.Constants;
import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.struts.util.RequestUtils;
@@ -77,6 +79,7 @@
* <code>ForwardConfig</code> (if any).</p>
*
* @author Craig R. McClanahan
+ * @author Don Brown
* @version $Revision$ $Date$
*/
@@ -107,18 +110,24 @@
} else {
uri = forwardPath;
}
+
+ // Get the underlying request in the case of a multipart wrapper
+ HttpServletRequest request = swcontext.getRequest();
+ if (request instanceof MultipartRequestWrapper) {
+ request = ((MultipartRequestWrapper) request).getRequest();
+ }
// Perform redirect or forward
if (forwardConfig.getRedirect()) {
if (uri.startsWith("/")) {
- uri = swcontext.getRequest().getContextPath() + uri;
+ uri = request.getContextPath() + uri;
}
swcontext.getResponse().sendRedirect
(swcontext.getResponse().encodeRedirectURL(uri));
} else {
RequestDispatcher rd =
swcontext.getContext().getRequestDispatcher(uri);
- rd.forward(swcontext.getRequest(), swcontext.getResponse());
+ rd.forward(request, swcontext.getResponse());
}
}
1.2 +13 -5 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PerformInclude.java
Index: PerformInclude.java
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PerformInclude.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PerformInclude.java 25 Oct 2003 00:02:33 -0000 1.1
+++ PerformInclude.java 13 Nov 2003 01:29:59 -0000 1.2
@@ -63,11 +63,13 @@
import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.web.servlet.ServletWebContext;
import org.apache.struts.Globals;
import org.apache.struts.chain.AbstractPerformInclude;
import org.apache.struts.chain.Constants;
+import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.struts.util.RequestUtils;
@@ -97,9 +99,15 @@
ServletWebContext swcontext = (ServletWebContext) context;
+ // Get the underlying request in the case of a multipart wrapper
+ HttpServletRequest request = swcontext.getRequest();
+ if (request instanceof MultipartRequestWrapper) {
+ request = ((MultipartRequestWrapper) request).getRequest();
+ }
+
RequestDispatcher rd =
swcontext.getContext().getRequestDispatcher(uri);
- rd.forward(swcontext.getRequest(), swcontext.getResponse());
+ rd.forward(request, swcontext.getResponse());
}
1.2 +14 -5 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PopulateActionForm.java
Index: PopulateActionForm.java
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/PopulateActionForm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PopulateActionForm.java 11 Aug 2003 04:55:34 -0000 1.1
+++ PopulateActionForm.java 13 Nov 2003 01:29:59 -0000 1.2
@@ -64,6 +64,7 @@
import org.apache.commons.chain.Context;
import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.chain.AbstractPopulateActionForm;
@@ -71,9 +72,11 @@
/**
- * <p>Populate the form bean (if any) for this request.</p>
+ * <p>Populate the form bean (if any) for this request. Sets the multipart
+ * class from the action config in the request attributes.</p>
*
* @author Craig R. McClanahan
+ * @author Don Brown
* @version $Revision$ $Date$
*/
@@ -89,6 +92,12 @@
ServletWebContext swcontext = (ServletWebContext) context;
actionForm.reset((ActionMapping) actionConfig, swcontext.getRequest());
+
+ // Set the multipart class
+ if (actionConfig.getMultipartClass() != null) {
+ swcontext.getRequestScope().put(Globals.MULTIPART_KEY,
+ actionConfig.getMultipartClass());
+ }
}
1.3 +28 -6 jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/ValidateActionForm.java
Index: ValidateActionForm.java
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/ValidateActionForm.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ValidateActionForm.java 31 Aug 2003 22:42:45 -0000 1.2
+++ ValidateActionForm.java 13 Nov 2003 01:29:59 -0000 1.3
@@ -64,6 +64,8 @@
import org.apache.commons.chain.Context;
import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
@@ -76,14 +78,22 @@
/**
* <p>Validate the properties of the form bean for this request. If there are
* any validation errors, execute the child commands in our chain; otherwise,
- * proceed normally.</p>
+ * proceed normally. Also, if any errors are found and the request is a
+ * multipart request, rollback the <code>MultipartRequestHandler</code>.</p>
*
* @author Craig R. McClanahan
+ * @author Don Brown
* @version $Revision$ $Date$
*/
public class ValidateActionForm extends AbstractValidateActionForm {
+ // ------------------------------------------------------ Instance Variables
+
+
+ private static final Log log =
+ LogFactory.getLog(ValidateActionForm.class);
+
// ------------------------------------------------------- Protected Methods
@@ -100,8 +110,20 @@
ActionForm actionForm) {
ServletWebContext swcontext = (ServletWebContext) context;
- return (actionForm.validate((ActionMapping) actionConfig,
+ ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig,
swcontext.getRequest()));
+
+ // Special handling for multipart request
+ if ((errors == null) || errors.isEmpty()) {
+ if (actionForm.getMultipartRequestHandler() != null) {
+ if (log.isTraceEnabled()) {
+ log.trace(" Rolling back multipart request");
+ }
+ actionForm.getMultipartRequestHandler().rollback();
+ }
+ }
+
+ return errors;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org