myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r683275 - /myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java
Date Wed, 06 Aug 2008 14:24:07 GMT
Author: matzew
Date: Wed Aug  6 07:24:07 2008
New Revision: 683275

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

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

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java?rev=683275&r1=683274&r2=683275&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java
Wed Aug  6 07:24:07 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
   {



Mime
View raw message