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:23:38 UTC

svn commit: r683274 - /myfaces/trinidad/branches/1.2.8.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java

Author: matzew
Date: Wed Aug  6 07:23:37 2008
New Revision: 683274

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

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

Modified: myfaces/trinidad/branches/1.2.8.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.8.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java?rev=683274&r1=683273&r2=683274&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.8.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java (original)
+++ myfaces/trinidad/branches/1.2.8.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java Wed Aug  6 07:23:37 2008
@@ -23,6 +23,7 @@
 
 import java.util.Map;
 
+import javax.portlet.ActionRequest;
 import javax.portlet.PortletContext;
 import javax.portlet.PortletRequest;
 
@@ -68,7 +69,7 @@
       {
         try
         {
-          _maxMemory = Integer.parseInt(maxMemory);
+          _maxMemory = Long.parseLong(maxMemory);
         }
         catch (NumberFormatException nfe)
         {
@@ -88,7 +89,7 @@
       {
         try
         {
-          _maxDiskSpace = Integer.parseInt(maxDiskSpace);
+          _maxDiskSpace = Long.parseLong(maxDiskSpace);
         }
         catch (NumberFormatException nfe)
         {
@@ -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
   {