You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2008/08/06 16:25:30 UTC

svn commit: r683277 - /myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java

Author: matzew
Date: Wed Aug  6 07:25:30 2008
New Revision: 683277

URL: http://svn.apache.org/viewvc?rev=683277&view=rev
Log:
TRINIDAD-1169 - inputfile: no feedback when file is too big (like 30mb)

Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java?rev=683277&r1=683276&r2=683277&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java Wed Aug  6 07:25:30 2008
@@ -23,6 +23,7 @@
 
 import java.util.Map;
 
+import javax.portlet.ActionRequest;
 import javax.portlet.PortletContext;
 import javax.portlet.PortletRequest;
 
@@ -120,7 +121,11 @@
       Object request, UploadedFile tempFile) throws IOException
   {
     RequestInfo info = _getRequestInfo(request);
-
+    int contentLength = getContentLength(request);
+    if(contentLength>_maxDiskSpace)
+    {
+      return new ErrorFile();
+    }
     // Process one new file, loading only as much as can fit
     // in the remaining memory and disk space.
     UploadedFileImpl file = new UploadedFileImpl();
@@ -151,6 +156,21 @@
     return file;
   }
 
+  private int getContentLength(Object request)
+  {
+    int length = -1;
+    if (_PORTLET_REQUEST_CLASS != null && _PORTLET_REQUEST_CLASS.isInstance(request))
+    {
+      length = _getPortletRequestLength(request);
+    }
+    else
+    {
+      length = _getServletRequestLength(request);
+    }
+
+    return length;
+  }
+  
   private RequestInfo _getRequestInfo(Object request)
   {
     Map<String, Object> attributes;
@@ -209,6 +229,20 @@
     return new PortletRequestMap((PortletRequest) request);
   }
 
+  private static final int _getServletRequestLength(final Object request)
+  {
+    assert(request instanceof ServletRequest);
+
+    return ((ServletRequest) request).getContentLength();
+  }
+
+  private static final int _getPortletRequestLength(final Object request)
+  {
+    if (!(request instanceof ActionRequest))
+      return -1;
+
+    return ((ActionRequest) request).getContentLength();
+  }
 
   static private class RequestInfo
   {