You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ni...@apache.org on 2005/11/09 06:12:01 UTC
svn commit: r331954 - in /struts:
core/trunk/src/java/org/apache/struts/action/
core/trunk/src/java/org/apache/struts/actions/
core/trunk/src/java/org/apache/struts/chain/commands/servlet/
core/trunk/src/java/org/apache/struts/upload/ core/trunk/src/ja...
Author: niallp
Date: Tue Nov 8 21:11:45 2005
New Revision: 331954
URL: http://svn.apache.org/viewcvs?rev=331954&view=rev
Log:
Fix for Bug 33132 (Support Servlet 2.4 methods) and Bug 17583 (Handling of Multipart request parameters).
Fixes Bug 33132 - Changed MultipartRequestWrapper to extend HttpServletRequestWrapper, which support 2.4 methods.
Fixes Bug 17583 - No longer need to "un-wrap" the MultipartRequestWrapper, since in Servlet 2.3 wrapped requests can be forwarded/included.
Modified:
struts/core/trunk/src/java/org/apache/struts/action/RequestProcessor.java
struts/core/trunk/src/java/org/apache/struts/actions/IncludeAction.java
struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformForward.java
struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformInclude.java
struts/core/trunk/src/java/org/apache/struts/upload/MultipartRequestWrapper.java
struts/core/trunk/src/java/org/apache/struts/util/RequestUtils.java
struts/tiles/trunk/src/java/org/apache/struts/tiles/commands/TilesPreProcessor.java
Modified: struts/core/trunk/src/java/org/apache/struts/action/RequestProcessor.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/action/RequestProcessor.java?rev=331954&r1=331953&r2=331954&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/action/RequestProcessor.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/action/RequestProcessor.java Tue Nov 8 21:11:45 2005
@@ -1089,11 +1089,6 @@
HttpServletResponse response)
throws IOException, ServletException {
- // Unwrap the multipart request, if there is one.
- if (request instanceof MultipartRequestWrapper) {
- request = ((MultipartRequestWrapper) request).getRequest();
- }
-
RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
if (rd == null) {
response.sendError(
@@ -1119,11 +1114,6 @@
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
-
- // Unwrap the multipart request, if there is one.
- if (request instanceof MultipartRequestWrapper) {
- request = ((MultipartRequestWrapper) request).getRequest();
- }
RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
if (rd == null) {
Modified: struts/core/trunk/src/java/org/apache/struts/actions/IncludeAction.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/actions/IncludeAction.java?rev=331954&r1=331953&r2=331954&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/actions/IncludeAction.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/actions/IncludeAction.java Tue Nov 8 21:11:45 2005
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
-import org.apache.struts.upload.MultipartRequestWrapper;
/**
* <p>An <strong>Action</strong> that includes the context-relative
@@ -94,11 +93,6 @@
if (rd == null) {
throw new ServletException(messages.getMessage("include.rd", path));
- }
-
- // Unwrap the multipart request, if there is one.
- if (request instanceof MultipartRequestWrapper) {
- request = ((MultipartRequestWrapper) request).getRequest();
}
// Forward control to the specified resource
Modified: struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformForward.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformForward.java?rev=331954&r1=331953&r2=331954&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformForward.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformForward.java Tue Nov 8 21:11:45 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2003,2004 The Apache Software Foundation.
+ * Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.config.ModuleConfig;
-import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.RequestUtils;
@@ -76,11 +75,7 @@
uri = forwardPath;
}
- // Get the underlying request in the case of a multipart wrapper
HttpServletRequest request = sacontext.getRequest();
- if (request instanceof MultipartRequestWrapper) {
- request = ((MultipartRequestWrapper) request).getRequest();
- }
// Perform redirect or forward
if (forwardConfig.getRedirect()) {
Modified: struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformInclude.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformInclude.java?rev=331954&r1=331953&r2=331954&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformInclude.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/commands/servlet/PerformInclude.java Tue Nov 8 21:11:45 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2003,2004 The Apache Software Foundation.
+ * Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
import org.apache.struts.chain.commands.AbstractPerformInclude;
import org.apache.struts.chain.contexts.ActionContext;
import org.apache.struts.chain.contexts.ServletActionContext;
-import org.apache.struts.upload.MultipartRequestWrapper;
/**
@@ -51,11 +50,7 @@
ServletActionContext swcontext = (ServletActionContext) 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);
Modified: struts/core/trunk/src/java/org/apache/struts/upload/MultipartRequestWrapper.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/upload/MultipartRequestWrapper.java?rev=331954&r1=331953&r2=331954&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/upload/MultipartRequestWrapper.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/upload/MultipartRequestWrapper.java Tue Nov 8 21:11:45 2005
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,50 +19,28 @@
package org.apache.struts.upload;
import java.util.Map;
-import java.util.Locale;
import java.util.Vector;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.security.Principal;
-import javax.servlet.ServletInputStream;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
/**
* This class functions as a wrapper around HttpServletRequest to
- * provide working getParameter methods for multipart requests. Once
- * Struts requires Servlet 2.3, this class will definately be changed to
- * extend javax.servlet.http.HttpServletRequestWrapper instead of
- * implementing HttpServletRequest. Servlet 2.3 methods are implemented
- * to return <code>null</code> or do nothing if called on. Use
- * {@link #getRequest() getRequest} to retrieve the underlying HttpServletRequest
- * object and call on the 2.3 method there, the empty methods are here only
- * so that this will compile with the Servlet 2.3 jar. This class exists temporarily
- * in the process() method of ActionServlet, just before the ActionForward is processed
- * and just after the Action is performed, the request is set back to the original
- * HttpServletRequest object.
+ * provide working getParameter methods for multipart requests.
*/
-public class MultipartRequestWrapper implements HttpServletRequest {
+public class MultipartRequestWrapper extends HttpServletRequestWrapper {
/**
* The parameters for this multipart request
*/
protected Map parameters;
- /**
- * The underlying HttpServletRequest
- */
- protected HttpServletRequest request;
-
public MultipartRequestWrapper(HttpServletRequest request) {
- this.request = request;
+ super(request);
this.parameters = new HashMap();
}
@@ -90,7 +68,7 @@
* request
*/
public String getParameter(String name) {
- String value = request.getParameter(name);
+ String value = getRequest().getParameter(name);
if (value == null) {
String[] mValue = (String[]) parameters.get(name);
if ((mValue != null) && (mValue.length > 0)) {
@@ -106,7 +84,7 @@
* names plus the parameters read from the multipart request
*/
public Enumeration getParameterNames() {
- Enumeration baseParams = request.getParameterNames();
+ Enumeration baseParams = getRequest().getParameterNames();
Vector list = new Vector();
while (baseParams.hasMoreElements()) {
list.add(baseParams.nextElement());
@@ -119,8 +97,14 @@
return Collections.enumeration(list);
}
+ /**
+ * Returns the values of a parameter in this request.
+ * It first looks in the underlying HttpServletRequest object
+ * for the parameter, and if that doesn't exist it looks for
+ * the parameter retrieved from the multipart request.
+ */
public String[] getParameterValues(String name) {
- String[] value = request.getParameterValues(name);
+ String[] value = getRequest().getParameterValues(name);
if (value == null) {
value = (String[]) parameters.get(name);
}
@@ -128,184 +112,14 @@
}
/**
- * Returns the underlying HttpServletRequest for this wrapper
- */
- public HttpServletRequest getRequest() {
- return request;
- }
-
- //WRAPPER IMPLEMENTATIONS OF SERVLET REQUEST METHODS
- public Object getAttribute(String name) {
- return request.getAttribute(name);
- }
- public Enumeration getAttributeNames() {
- return request.getAttributeNames();
- }
- public String getCharacterEncoding() {
- return request.getCharacterEncoding();
- }
- public int getContentLength() {
- return request.getContentLength();
- }
- public String getContentType() {
- return request.getContentType();
- }
- public ServletInputStream getInputStream() throws IOException {
- return request.getInputStream();
- }
- public String getProtocol() {
- return request.getProtocol();
- }
- public String getScheme() {
- return request.getScheme();
- }
- public String getServerName() {
- return request.getServerName();
- }
- public int getServerPort() {
- return request.getServerPort();
- }
- public BufferedReader getReader() throws IOException {
- return request.getReader();
- }
- public String getRemoteAddr() {
- return request.getRemoteAddr();
- }
- public String getRemoteHost() {
- return request.getRemoteHost();
- }
- public void setAttribute(String name, Object o) {
- request.setAttribute(name, o);
- }
- public void removeAttribute(String name) {
- request.removeAttribute(name);
- }
- public Locale getLocale() {
- return request.getLocale();
- }
- public Enumeration getLocales() {
- return request.getLocales();
- }
- public boolean isSecure() {
- return request.isSecure();
- }
- public RequestDispatcher getRequestDispatcher(String path) {
- return request.getRequestDispatcher(path);
- }
- public String getRealPath(String path) {
- return request.getRealPath(path);
- }
-
- //WRAPPER IMPLEMENTATIONS OF HTTPSERVLETREQUEST METHODS
- public String getAuthType() {
- return request.getAuthType();
- }
- public Cookie[] getCookies() {
- return request.getCookies();
- }
- public long getDateHeader(String name) {
- return request.getDateHeader(name);
- }
- public String getHeader(String name) {
- return request.getHeader(name);
- }
- public Enumeration getHeaders(String name) {
- return request.getHeaders(name);
- }
- public Enumeration getHeaderNames() {
- return request.getHeaderNames();
- }
- public int getIntHeader(String name) {
- return request.getIntHeader(name);
- }
- public String getMethod() {
- return request.getMethod();
- }
- public String getPathInfo() {
- return request.getPathInfo();
- }
- public String getPathTranslated() {
- return request.getPathTranslated();
- }
- public String getContextPath() {
- return request.getContextPath();
- }
- public String getQueryString() {
- return request.getQueryString();
- }
- public String getRemoteUser() {
- return request.getRemoteUser();
- }
- public boolean isUserInRole(String user) {
- return request.isUserInRole(user);
- }
- public Principal getUserPrincipal() {
- return request.getUserPrincipal();
- }
- public String getRequestedSessionId() {
- return request.getRequestedSessionId();
- }
- public String getRequestURI() {
- return request.getRequestURI();
- }
- public String getServletPath() {
- return request.getServletPath();
- }
- public HttpSession getSession(boolean create) {
- return request.getSession(create);
- }
- public HttpSession getSession() {
- return request.getSession();
- }
- public boolean isRequestedSessionIdValid() {
- return request.isRequestedSessionIdValid();
- }
- public boolean isRequestedSessionIdFromURL() {
- return request.isRequestedSessionIdFromURL();
- }
- public boolean isRequestedSessionIdFromUrl() {
- return request.isRequestedSessionIdFromUrl();
- }
-
- //SERVLET 2.3 EMPTY METHODS
- /**
- * This method returns null. To use any Servlet 2.3 methods,
- * call on getRequest() and use that request object. Once Servlet 2.3
- * is required to build Struts, this will no longer be an issue.
+ * Combines the parameters stored here with those in the underlying
+ * request. If paramater values in the underlying request take
+ * precedence over those stored here.
*/
public Map getParameterMap() {
- return null;
+ Map map = new HashMap(parameters);
+ map.putAll(getRequest().getParameterMap());
+ return map;
}
- /**
- * This method does nothing. To use any Servlet 2.3 methods,
- * call on getRequest() and use that request object. Once Servlet 2.3
- * is required to build Struts, this will no longer be an issue.
- */
- public void setCharacterEncoding(String encoding) {
- ;
- }
- /**
- * This method returns null. To use any Servlet 2.3 methods,
- * call on getRequest() and use that request object. Once Servlet 2.3
- * is required to build Struts, this will no longer be an issue.
- */
- public StringBuffer getRequestURL() {
- return null;
- }
- /**
- * This method returns false. To use any Servlet 2.3 methods,
- * call on getRequest() and use that request object. Once Servlet 2.3
- * is required to build Struts, this will no longer be an issue.
- */
- public boolean isRequestedSessionIdFromCookie() {
- return false;
- }
-
-
-
-
-
-
-
}
Modified: struts/core/trunk/src/java/org/apache/struts/util/RequestUtils.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/util/RequestUtils.java?rev=331954&r1=331953&r2=331954&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/util/RequestUtils.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/util/RequestUtils.java Tue Nov 8 21:11:45 2005
@@ -599,7 +599,7 @@
}
if (request instanceof MultipartRequestWrapper) {
- request = ((MultipartRequestWrapper) request).getRequest();
+ request = (HttpServletRequest)((MultipartRequestWrapper)request).getRequest();
e = request.getParameterNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
Modified: struts/tiles/trunk/src/java/org/apache/struts/tiles/commands/TilesPreProcessor.java
URL: http://svn.apache.org/viewcvs/struts/tiles/trunk/src/java/org/apache/struts/tiles/commands/TilesPreProcessor.java?rev=331954&r1=331953&r2=331954&view=diff
==============================================================================
--- struts/tiles/trunk/src/java/org/apache/struts/tiles/commands/TilesPreProcessor.java (original)
+++ struts/tiles/trunk/src/java/org/apache/struts/tiles/commands/TilesPreProcessor.java Tue Nov 8 21:11:45 2005
@@ -236,11 +236,6 @@
HttpServletRequest request = context.getRequest();
- // Unwrap the multipart request, if there is one.
- if (request instanceof MultipartRequestWrapper) {
- request = ((MultipartRequestWrapper) request).getRequest();
- }
-
HttpServletResponse response = context.getResponse();
RequestDispatcher rd = context.getContext().getRequestDispatcher(uri);
if (rd == null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org