Author: jochen
Date: Sat Jan 17 18:41:04 2009
New Revision: 735376

URL: http://svn.apache.org/viewvc?rev=735376&view=rev
Log:
PR: FILEUPLOAD-154
A FileSizeLimitExceededException does now contain the
file and field name of the item, which caused the
exception.

Modified:
    commons/proper/fileupload/trunk/src/changes/changes.xml
    
commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java

Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=735376&r1=735375&r2=735376&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/changes/changes.xml (original)
+++ commons/proper/fileupload/trunk/src/changes/changes.xml Sat Jan 17 18:41:04 
2009
@@ -68,6 +68,10 @@
         Fixed the error message for FileSizeLimitExceededException
         from "too many characters" to "too many bytes".
       </action>
+      <action dev="jochen" type="add" issue="FILEUPLOAD-154">
+        A FileSizeLimitExceededException does now contain the
+        file and field name of the item, which caused the problem.
+      </action>
     </release>
 
     <release version="1.2.1" date="2008-01-18">

Modified: 
commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java?rev=735376&r1=735375&r2=735376&view=diff
==============================================================================
--- 
commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
 (original)
+++ 
commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
 Sat Jan 17 18:41:04 2009
@@ -743,27 +743,31 @@
                 if (fileSizeMax != -1) {
                     if (pContentLength != -1
                             &&  pContentLength > fileSizeMax) {
-                        FileUploadException e =
+                       FileSizeLimitExceededException e =
                             new FileSizeLimitExceededException(
                                 "The field " + fieldName
                                 + " exceeds its maximum permitted "
                                 + " size of " + fileSizeMax
                                 + " bytes.",
                                 pContentLength, fileSizeMax);
+                        e.setFileName(pName);
+                        e.setFieldName(pFieldName);
                         throw new FileUploadIOException(e);
                     }
                     istream = new LimitedInputStream(istream, fileSizeMax) {
                         protected void raiseError(long pSizeMax, long pCount)
                                 throws IOException {
                             itemStream.close(true);
-                            FileUploadException e =
+                            FileSizeLimitExceededException e =
                                 new FileSizeLimitExceededException(
                                     "The field " + fieldName
                                     + " exceeds its maximum permitted "
                                     + " size of " + pSizeMax
                                     + " bytes.",
                                     pCount, pSizeMax);
-                            throw new FileUploadIOException(e);
+                            e.setFieldName(getFieldName());
+                            e.setFieldName(getName());
+                               throw new FileUploadIOException(e);
                         }
                     };
                 }
@@ -1292,6 +1296,16 @@
         private static final long serialVersionUID = 8150776562029630058L;
 
         /**
+         * File name of the item, which caused the exception.
+         */
+        private String fileName;
+
+        /**
+         * Field name of the item, which caused the exception.
+         */
+        private String fieldName;
+
+        /**
          * Constructs a <code>SizeExceededException</code> with
          * the specified detail message, and actual and permitted sizes.
          *
@@ -1303,6 +1317,40 @@
                 long permitted) {
             super(message, actual, permitted);
         }
+
+        /**
+         * Returns the file name of the item, which caused the
+         * exception.
+         * @return File name, if known, or null.
+         */
+        public String getFileName() {
+               return fileName;
+        }
+
+        /**
+         * Sets the file name of the item, which caused the
+         * exception.
+         */
+        public void setFileName(String pFileName) {
+               fileName = pFileName;
+        }
+
+        /**
+         * Returns the field name of the item, which caused the
+         * exception.
+         * @return Field name, if known, or null.
+         */
+        public String getFieldName() {
+               return fieldName;
+        }
+
+        /**
+         * Sets the field name of the item, which caused the
+         * exception.
+         */
+        public void setFieldName(String pFieldName) {
+               fieldName = pFieldName;
+        }
     }
 
     /**


Reply via email to