Author: nbelaevski
Date: 2011-04-21 13:59:08 -0400 (Thu, 21 Apr 2011)
New Revision: 22439
Added:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPhaseListener.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestSizeExceeded.java
Removed:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java
trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java
trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml
trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java
Log:
RF-10128
Deleted:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java 2011-04-21
15:55:38 UTC (rev 22438)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadExternalContextFactory.java 2011-04-21
17:59:08 UTC (rev 22439)
@@ -1,228 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.context;
-
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.AbstractMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import javax.faces.FacesException;
-import javax.faces.FacesWrapper;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.ExternalContextFactory;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.richfaces.exception.FileUploadException;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.model.UploadedFile;
-import org.richfaces.request.MultipartRequest;
-import org.richfaces.request.MultipartRequest.ResponseState;
-import org.richfaces.request.MultipartRequest25;
-import org.richfaces.request.MultipartRequestParser;
-import org.richfaces.request.ProgressControl;
-
-import com.google.common.collect.LinkedListMultimap;
-import com.google.common.collect.Lists;
-
-
-/**
- * @author Nick Belaevski
- *
- */
-public class FileUploadExternalContextFactory extends ExternalContextFactory implements
FacesWrapper<ExternalContextFactory> {
-
- private static class HttpSessionMap extends AbstractMap<String, Object> {
-
- private HttpSession session;
-
- public HttpSessionMap(HttpSession session) {
- super();
- this.session = session;
- }
-
- @Override
- public Object get(Object key) {
- return session.getAttribute((String) key);
- }
-
- @Override
- public Object put(String key, Object value) {
- session.setAttribute(key, value);
- return null;
- }
-
- @Override
- public Object remove(Object key) {
- session.removeAttribute((String) key);
- return null;
- }
-
- @Override
- public Set<java.util.Map.Entry<String, Object>> entrySet() {
- throw new UnsupportedOperationException();
- }
- }
-
- public static final String UID_KEY = "rf_fu_uid";
-
- private static final Logger LOGGER = RichfacesLogger.CONTEXT.getLogger();
-
- private static final Pattern AMPERSAND = Pattern.compile("&+");
-
- private ExternalContextFactory wrappedFactory;
-
- public FileUploadExternalContextFactory(ExternalContextFactory wrappedFactory) {
- super();
-
- //TODO Use ConfigurationServiceHelper to initialize InitParameters.
- this.wrappedFactory = wrappedFactory;
- }
-
- @Override
- public ExternalContextFactory getWrapped() {
- return wrappedFactory;
- }
-
- private String getParameterValueFromQueryString(String queryString, String paramName)
{
- if (queryString != null) {
- String[] nvPairs = AMPERSAND.split(queryString);
- for (String nvPair : nvPairs) {
- if (nvPair.length() == 0) {
- continue;
- }
-
- int eqIdx = nvPair.indexOf('=');
- if (eqIdx >= 0) {
- try {
- String name = URLDecoder.decode(nvPair.substring(0, eqIdx),
"UTF-8");
-
- if (paramName.equals(name)) {
- return URLDecoder.decode(nvPair.substring(eqIdx + 1),
"UTF-8");
- }
- } catch (UnsupportedEncodingException e) {
- // log warning and skip this parameter
- LOGGER.debug(e.getMessage(), e);
- }
- }
- }
- }
-
- return null;
- }
-
- private boolean isCreateTempFiles(ServletContext servletContext) {
- String param =
servletContext.getInitParameter("org.richfaces.fileUpload.createTempFiles");
- if (param != null) {
- return Boolean.parseBoolean(param);
- }
-
- return true;
- }
-
- private String getTempFilesDirectory(ServletContext servletContext) {
- String result =
servletContext.getInitParameter("org.richfaces.fileUpload.tempFilesDirectory");
- if (result == null) {
- File servletTempDir = (File)
servletContext.getAttribute("javax.servlet.context.tempdir");
- if (servletTempDir != null) {
- result = servletTempDir.getAbsolutePath();
- }
- }
- if (result == null) {
- result = new
File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
- }
-
- return result;
- }
-
- private long getMaxRequestSize(ServletContext servletContext) {
- String param =
servletContext.getInitParameter("org.richfaces.fileUpload.maxRequestSize");
- if (param != null) {
- return Long.parseLong(param);
- }
-
- return 0;
- }
-
- @Override
- public ExternalContext getExternalContext(Object context, Object request, Object
response) throws FacesException {
- Object wrappedRequest = request;
-
- if (wrappedRequest instanceof HttpServletRequest) {
- HttpServletRequest httpRequest = (HttpServletRequest) wrappedRequest;
-
- if (httpRequest.getContentType() != null &&
httpRequest.getContentType().startsWith("multipart/")) {
- String uid =
getParameterValueFromQueryString(httpRequest.getQueryString(), UID_KEY);
-
- if (uid != null) {
- long contentLength =
Long.parseLong(httpRequest.getHeader("Content-Length"));
-
- Map<String,Object> contextMap = new
HttpSessionMap(httpRequest.getSession());
-
- ProgressControl progressControl = new ProgressControl(contextMap,
uid, contentLength);
-
- wrappedRequest = wrapMultipartRequestServlet25((ServletContext)
context, httpRequest, uid,
- contentLength, progressControl);
- }
- }
- }
-
- return getWrapped().getExternalContext(context, wrappedRequest, response);
- }
-
- private MultipartRequest wrapMultipartRequestServlet25(ServletContext servletContext,
HttpServletRequest request,
- String uploadId, long contentLength, ProgressControl progressControl) {
-
- MultipartRequest multipartRequest;
-
- long maxRequestSize = getMaxRequestSize(servletContext);
- if (maxRequestSize == 0 || contentLength <= maxRequestSize) {
- MultipartRequestParser requestParser = new MultipartRequestParser(request,
isCreateTempFiles(servletContext),
- getTempFilesDirectory(servletContext), progressControl);
-
- ResponseState result = ResponseState.ok;
-
- try {
- requestParser.parse();
- } catch (FileUploadException e) {
- result = ResponseState.serverError;
- }
-
- multipartRequest = new MultipartRequest25(request, uploadId, progressControl,
requestParser.getParameters(),
- requestParser.getUploadedFiles(), result);
- } else {
- multipartRequest = new MultipartRequest25(request, uploadId, progressControl,
LinkedListMultimap.<String, String>create(),
- Lists.<UploadedFile>newArrayList(), ResponseState.sizeExceeded);
- }
-
- request.setAttribute(MultipartRequest.REQUEST_ATTRIBUTE_NAME, multipartRequest);
-
- return multipartRequest;
- }
-
-}
\ No newline at end of file
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java 2011-04-21
15:55:38 UTC (rev 22438)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadFacesContextFactory.java 2011-04-21
17:59:08 UTC (rev 22439)
@@ -21,22 +21,27 @@
*/
package org.richfaces.context;
-import java.io.IOException;
-import java.io.Writer;
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.regex.Pattern;
import javax.faces.FacesException;
import javax.faces.FacesWrapper;
-import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
import javax.faces.context.FacesContextWrapper;
import javax.faces.lifecycle.Lifecycle;
-import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.request.MultipartRequest;
-import org.richfaces.request.MultipartRequest.ResponseState;
+import org.richfaces.request.MultipartRequest25;
+import org.richfaces.request.MultipartRequestParser;
+import org.richfaces.request.MultipartRequestSizeExceeded;
+import org.richfaces.request.ProgressControl;
/**
* @author Nick Belaevski
@@ -44,8 +49,6 @@
*/
public class FileUploadFacesContextFactory extends FacesContextFactory implements
FacesWrapper<FacesContextFactory> {
- private static final Logger LOGGER = RichfacesLogger.CONTEXT.getLogger();
-
private static final class FileUploadFacesContext extends FacesContextWrapper {
private FacesContext facesContext;
@@ -72,6 +75,12 @@
}
}
+ public static final String UID_KEY = "rf_fu_uid";
+
+ private static final Logger LOGGER = RichfacesLogger.CONTEXT.getLogger();
+
+ private static final Pattern AMPERSAND = Pattern.compile("&+");
+
private FacesContextFactory wrappedFactory;
public FileUploadFacesContextFactory(FacesContextFactory wrappedFactory) {
@@ -84,36 +93,114 @@
return wrappedFactory;
}
+ private String getParameterValueFromQueryString(String queryString, String paramName)
{
+ if (queryString != null) {
+ String[] nvPairs = AMPERSAND.split(queryString);
+ for (String nvPair : nvPairs) {
+ if (nvPair.length() == 0) {
+ continue;
+ }
+
+ int eqIdx = nvPair.indexOf('=');
+ if (eqIdx >= 0) {
+ try {
+ String name = URLDecoder.decode(nvPair.substring(0, eqIdx),
"UTF-8");
+
+ if (paramName.equals(name)) {
+ return URLDecoder.decode(nvPair.substring(eqIdx + 1),
"UTF-8");
+ }
+ } catch (UnsupportedEncodingException e) {
+ // log warning and skip this parameter
+ LOGGER.debug(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
@Override
public FacesContext getFacesContext(Object context, Object request, Object response,
Lifecycle lifecycle)
throws FacesException {
- FacesContext facesContext = wrappedFactory.getFacesContext(context, request,
response, lifecycle);
-
- MultipartRequest multipartRequest = (MultipartRequest)
facesContext.getExternalContext().getRequestMap().get(MultipartRequest.REQUEST_ATTRIBUTE_NAME);
- if (multipartRequest != null) {
- facesContext = new FileUploadFacesContext(facesContext);
-
- if (multipartRequest.getResponseState() != ResponseState.ok) {
- printResponse(facesContext, multipartRequest);
+ if (request instanceof HttpServletRequest) {
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ if (httpRequest.getContentType() != null &&
httpRequest.getContentType().startsWith("multipart/")) {
+ String uid =
getParameterValueFromQueryString(httpRequest.getQueryString(), UID_KEY);
+
+ if (uid != null) {
+ long contentLength =
Long.parseLong(httpRequest.getHeader("Content-Length"));
+
+ ProgressControl progressControl = new ProgressControl(uid,
contentLength);
+
+ HttpServletRequest wrappedRequest =
wrapMultipartRequestServlet25((ServletContext) context, httpRequest, uid,
+ contentLength, progressControl);
+
+ FacesContext facesContext = wrappedFactory.getFacesContext(context,
wrappedRequest, response, lifecycle);
+
progressControl.setContextMap(facesContext.getExternalContext().getSessionMap());
+ return new FileUploadFacesContext(facesContext);
+ }
}
+
}
- return facesContext;
+ return wrappedFactory.getFacesContext(context, request, response, lifecycle);
}
+ private boolean isCreateTempFiles(ServletContext servletContext) {
+ String param =
servletContext.getInitParameter("org.richfaces.fileUpload.createTempFiles");
+ if (param != null) {
+ return Boolean.parseBoolean(param);
+ }
+
+ return true;
+ }
- private void printResponse(FacesContext facesContext, MultipartRequest
multipartRequest) {
- facesContext.responseComplete();
- ExternalContext externalContext = facesContext.getExternalContext();
- externalContext.setResponseStatus(HttpServletResponse.SC_OK);
- externalContext.setResponseContentType("text/html");
- try {
- Writer writer = externalContext.getResponseOutputWriter();
- writer.write("<html id=\"" +
FileUploadExternalContextFactory.UID_KEY + multipartRequest.getUploadId() + ":"
+ multipartRequest.getResponseState() + "\"/>");
- writer.close();
- } catch (IOException e) {
- LOGGER.error(e.getMessage(), e);
+ private String getTempFilesDirectory(ServletContext servletContext) {
+ String result =
servletContext.getInitParameter("org.richfaces.fileUpload.tempFilesDirectory");
+ if (result == null) {
+ File servletTempDir = (File)
servletContext.getAttribute("javax.servlet.context.tempdir");
+ if (servletTempDir != null) {
+ result = servletTempDir.getAbsolutePath();
+ }
}
+ if (result == null) {
+ result = new
File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
+ }
+
+ return result;
}
+
+ private long getMaxRequestSize(ServletContext servletContext) {
+ String param =
servletContext.getInitParameter("org.richfaces.fileUpload.maxRequestSize");
+ if (param != null) {
+ return Long.parseLong(param);
+ }
+
+ return 0;
+ }
+
+ private HttpServletRequest wrapMultipartRequestServlet25(ServletContext
servletContext, HttpServletRequest request,
+ String uploadId, long contentLength, ProgressControl progressControl) {
+
+ HttpServletRequest multipartRequest;
+
+ long maxRequestSize = getMaxRequestSize(servletContext);
+ if (maxRequestSize == 0 || contentLength <= maxRequestSize) {
+ boolean createTempFiles = isCreateTempFiles(servletContext);
+ String tempFilesDirectory = getTempFilesDirectory(servletContext);
+
+ MultipartRequestParser requestParser = new MultipartRequestParser(request,
createTempFiles, tempFilesDirectory, progressControl);
+
+ multipartRequest = new MultipartRequest25(request, uploadId, progressControl,
requestParser);
+ } else {
+ multipartRequest = new MultipartRequestSizeExceeded(request, uploadId,
progressControl);
+ }
+
+ request.setAttribute(MultipartRequest.REQUEST_ATTRIBUTE_NAME, multipartRequest);
+
+ return multipartRequest;
+ }
+
}
Added: trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPhaseListener.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPhaseListener.java
(rev 0)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPhaseListener.java 2011-04-21
17:59:08 UTC (rev 22439)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.servlet.http.HttpServletResponse;
+
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+import org.richfaces.request.MultipartRequest;
+import org.richfaces.request.MultipartRequest.ResponseState;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileUploadPhaseListener implements PhaseListener {
+
+ private static final long serialVersionUID = -3130357236442351405L;
+
+ private static final Logger LOGGER = RichfacesLogger.CONTEXT.getLogger();
+
+ public void afterPhase(PhaseEvent event) {
+ }
+
+ public void beforePhase(PhaseEvent event) {
+ MultipartRequest multipartRequest = (MultipartRequest)
event.getFacesContext().getExternalContext().getRequestMap().get(MultipartRequest.REQUEST_ATTRIBUTE_NAME);
+ if (multipartRequest != null) {
+ if (multipartRequest.getResponseState() != ResponseState.ok) {
+ printResponse(event.getFacesContext(), multipartRequest);
+ }
+ }
+ }
+
+
+ private void printResponse(FacesContext facesContext, MultipartRequest
multipartRequest) {
+ facesContext.responseComplete();
+ ExternalContext externalContext = facesContext.getExternalContext();
+ externalContext.setResponseStatus(HttpServletResponse.SC_OK);
+ externalContext.setResponseContentType("text/html");
+ try {
+ Writer writer = externalContext.getResponseOutputWriter();
+ writer.write("<html id=\"" +
FileUploadFacesContextFactory.UID_KEY + multipartRequest.getUploadId() + ":" +
multipartRequest.getResponseState() + "\"/>");
+ writer.close();
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ }
+
+ public PhaseId getPhaseId() {
+ return PhaseId.RENDER_RESPONSE;
+ }
+
+}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java 2011-04-21
15:55:38 UTC (rev 22438)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequest25.java 2011-04-21
17:59:08 UTC (rev 22439)
@@ -28,6 +28,7 @@
import javax.servlet.http.HttpServletRequest;
+import org.richfaces.exception.FileUploadException;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.model.UploadedFile;
@@ -57,20 +58,38 @@
}
};
- private Multimap<String, String> params;
-
- private Iterable<UploadedFile> uploadedFiles;
-
+ private MultipartRequestParser requestParser;
+
private ResponseState responseState;
+ private Iterable<UploadedFile> uploadedFiles;
+
+ private Multimap<String, String> params;
+
public MultipartRequest25(HttpServletRequest request, String uploadId,
ProgressControl progressControl,
- Multimap<String, String> params, Iterable<UploadedFile>
uploadedFiles, ResponseState responseState) {
+ MultipartRequestParser requestParser) {
+
super(request, uploadId, progressControl);
- this.params = params;
- this.uploadedFiles = uploadedFiles;
- this.responseState = responseState;
+ this.requestParser = requestParser;
}
+
+ private void parseIfNecessary() {
+ if (responseState != null) {
+ return;
+ }
+
+ try {
+ requestParser.parse();
+
+ uploadedFiles = requestParser.getUploadedFiles();
+ params = requestParser.getParameters();
+ responseState = ResponseState.ok;
+ } catch (FileUploadException e) {
+ LOGGER.error(e.getMessage(), e);
+ responseState = ResponseState.serverError;
+ }
+ }
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@@ -84,6 +103,7 @@
result.add(name);
}
+ parseIfNecessary();
result.addAll(params.keySet());
return Iterators.asEnumeration(result.iterator());
@@ -91,11 +111,13 @@
@Override
public String getParameter(String name) {
+
String parameter = super.getParameter(name);
if (parameter != null) {
return parameter;
}
+ parseIfNecessary();
Collection<String> values = params.get(name);
if (values.isEmpty()) {
@@ -112,6 +134,7 @@
return parameterValues;
}
+ parseIfNecessary();
Collection<String> values = params.get(name);
if (values.isEmpty()) {
@@ -125,28 +148,35 @@
@Override
public Map getParameterMap() {
Map parameterMap = Maps.newHashMap(super.getParameterMap());
+ parseIfNecessary();
parameterMap.putAll(Maps.transformValues(params.asMap(),
MULTIMAP_VALUE_TRANSFORMER));
return parameterMap;
}
public Iterable<UploadedFile> getUploadedFiles() {
+ parseIfNecessary();
+
return uploadedFiles;
}
public void release() {
super.release();
- for (UploadedFile uploadedFile : uploadedFiles) {
- try {
- uploadedFile.delete();
- } catch (IOException e) {
- LOGGER.error(e.getMessage(), e);
+ if (uploadedFiles != null) {
+ for (UploadedFile uploadedFile : uploadedFiles) {
+ try {
+ uploadedFile.delete();
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ }
}
}
}
public ResponseState getResponseState() {
+ parseIfNecessary();
+
return responseState;
}
Added:
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestSizeExceeded.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestSizeExceeded.java
(rev 0)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/request/MultipartRequestSizeExceeded.java 2011-04-21
17:59:08 UTC (rev 22439)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.request;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.richfaces.model.UploadedFile;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MultipartRequestSizeExceeded extends BaseMultipartRequest {
+
+ public MultipartRequestSizeExceeded(HttpServletRequest request, String uploadId,
ProgressControl progressControl) {
+ super(request, uploadId, progressControl);
+ }
+
+ public ResponseState getResponseState() {
+ return ResponseState.sizeExceeded;
+ }
+
+ public Iterable<UploadedFile> getUploadedFiles() {
+ return Lists.newArrayList();
+ }
+}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java 2011-04-21
15:55:38 UTC (rev 22438)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/request/ProgressControl.java 2011-04-21
17:59:08 UTC (rev 22439)
@@ -44,8 +44,7 @@
private byte lastUpdatedPercentValue;
- public ProgressControl(Map<String, Object> contextMap, String uploadId, long
length) {
- this.contextMap = contextMap;
+ public ProgressControl(String uploadId, long length) {
this.attributeName = getContextAttributeName(uploadId);
this.length = length;
}
@@ -65,7 +64,9 @@
}
void clearProgress() {
- contextMap.remove(attributeName);
+ if (contextMap != null) {
+ contextMap.remove(attributeName);
+ }
}
public void advance(long bytesRead) {
@@ -78,12 +79,16 @@
percent = 100;
}
- if (percent > lastUpdatedPercentValue) {
+ if (percent > lastUpdatedPercentValue && contextMap != null) {
lastUpdatedPercentValue = percent;
contextMap.put(attributeName, lastUpdatedPercentValue);
}
}
+ public void setContextMap(Map<String, Object> contextMap) {
+ this.contextMap = contextMap;
+ }
+
public ServletInputStream wrapStream(ServletInputStream inputStream) {
return new ProgressServletInputStream(inputStream, this);
}
Modified: trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml 2011-04-21
15:55:38 UTC (rev 22438)
+++ trunk/ui/input/ui/src/main/resources/META-INF/fileupload.faces-config.xml 2011-04-21
17:59:08 UTC (rev 22439)
@@ -29,6 +29,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<factory>
<faces-context-factory>org.richfaces.context.FileUploadFacesContextFactory</faces-context-factory>
-
<external-context-factory>org.richfaces.context.FileUploadExternalContextFactory</external-context-factory>
</factory>
+ <lifecycle>
+
<phase-listener>org.richfaces.context.FileUploadPhaseListener</phase-listener>
+ </lifecycle>
</faces-config>
Modified: trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java
===================================================================
---
trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java 2011-04-21
15:55:38 UTC (rev 22438)
+++
trunk/ui/input/ui/src/test/java/org/richfaces/request/ProgressControlTest.java 2011-04-21
17:59:08 UTC (rev 22439)
@@ -44,7 +44,8 @@
@Test
public void testAdvance() throws Exception {
Map<String, Object> contextMap = Maps.newHashMap();
- ProgressControl control = new ProgressControl(contextMap, UPLOAD_ID, 400);
+ ProgressControl control = new ProgressControl(UPLOAD_ID, 400);
+ control.setContextMap(contextMap);
assertNull(contextMap.get(ATTRIBUTE_NAME));
control.advance(1);
@@ -63,7 +64,8 @@
@Test
public void testClearProgress() throws Exception {
Map<String, Object> contextMap = Maps.newHashMap();
- ProgressControl control = new ProgressControl(contextMap, UPLOAD_ID, 100);
+ ProgressControl control = new ProgressControl(UPLOAD_ID, 100);
+ control.setContextMap(contextMap);
assertNull(contextMap.get(ATTRIBUTE_NAME));
control.advance(50);