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 2010/07/06 23:16:58 UTC

svn commit: r961015 - in /myfaces/trinidad/trunk: trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/ trinidad-imp...

Author: matzew
Date: Tue Jul  6 21:16:56 2010
New Revision: 961015

URL: http://svn.apache.org/viewvc?rev=961015&view=rev
Log:
TRINIDAD-1843 - Need to feedback failures for users when a file processor in chain fails

Thanks to Prakash Udupa for the patch

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/UploadedFile.java
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ChainedUploadedFileProcessor.java
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java
    myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/CompositeUploadedFileProcessorImpl.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ErrorFile.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/UploadedFile.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/UploadedFile.java?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/UploadedFile.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/model/UploadedFile.java Tue Jul  6 21:16:56 2010
@@ -40,6 +40,11 @@ public interface UploadedFile
 
   /**
    * Returns the total length (in bytes) of the file.
+   * A length of -1 is interpreted as an error situation, and will be treated as JSF convertor 
+   * failure. When this happens, the details of this error is expected to be in the toString() 
+   * implementation of the object returned through getOpaqueData(). This detail will be displayed 
+   * to the user as a conversion failure message.
+   * @see UploadedFile#getOpaqueData()
    */
   public long getLength();
 
@@ -54,6 +59,7 @@ public interface UploadedFile
    * cannot guarantee that the  instance returned from
    * code>UploadedFileProcessor</code> is the same one made available
    * later.
+   * @see UploadedFile#getLength()
    */
   public Object getOpaqueData();
 

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ChainedUploadedFileProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ChainedUploadedFileProcessor.java?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ChainedUploadedFileProcessor.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ChainedUploadedFileProcessor.java Tue Jul  6 21:16:56 2010
@@ -95,6 +95,20 @@ public interface ChainedUploadedFileProc
    *  on it. Any exception that happenes during dispose() call will be logged
    *  as warning and the processing continues with the rest of the UploadedFile(s).
    *  </p>
+   *  <p>
+   *  If one of chained file processor throws an IOException in this method, it is considered that
+   *  there is a error in processing the uploaded file, the chain is broken hence, the file upload
+   *  process stops, and the message contained in the IOException is shown to the user as a value 
+   *  conversion warning.
+   *  If the processing failure is less severe, and if the failure need to be meaningfully reported 
+   *  to the end users, the length of the returned UploadedFile should be set to -1, and its 
+   *  getOpaqueData() should provide the error details. The object returned by getOpaqueData() 
+   *  should implement a toString() that returns a detailed error message. During the JSF life cycle 
+   *  later, the input file component would show this message as value conversion warning to the 
+   *  user.
+   *  @see UploadedFile#getLength()
+   *  @see UploadedFile#getOpaqueData()
+   *  </p>
    * @param request the current servlet or portlet request
    * @param file a temporary file object
    * @return a new instance of UploadedFile.  It is legal to return null,

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/UploadedFileProcessor.java Tue Jul  6 21:16:56 2010
@@ -109,6 +109,19 @@ public interface UploadedFileProcessor
    *  guarantees that {@link UploadedFile#dispose}</code> will be called before
    *  the request completes.
    *  </p>
+   *  <p>
+   *  If any implementation of this method throws an IOException, it is considered that there is a 
+   *  error in processing the uploaded file, and the message contained in the IOException is shown 
+   *  to the user as a value conversion warning.
+   *  If the processing failure is less severe, and if the failure need to be meaningfully reported 
+   *  to the end users, the length of the returned UploadedFile should be set to -1, and its 
+   *  getOpaqueData() should provide the error details. The object returned by getOpaqueData() 
+   *  should implement a toString() that returns a detailed error message. During the JSF life cycle 
+   *  later, the input file component would show this message as value conversion warning to the 
+   *  user.
+   *  @see UploadedFile#getLength()
+   *  @see UploadedFile#getOpaqueData()
+   *  </p>
    * @param request the current servlet or portlet request
    * @param file a temporary file object
    * @return a new instance of UploadedFile.  It is legal to return null,

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts Tue Jul  6 21:16:56 2010
@@ -71,8 +71,8 @@
   <resource key="org.apache.myfaces.trinidad.UIXEditableValue.CONVERSION_detail">Enter a value that matches this pattern: {2}</resource>
 
   <!-- Upload ConversionException messages -->
-  <resource key="org.apache.myfaces.trinidad.UPLOAD">The file is too large.</resource>
-  <resource key="org.apache.myfaces.trinidad.UPLOAD_detail">The file could not be uploaded because it is too large.</resource>
+  <resource key="org.apache.myfaces.trinidad.UPLOAD_FAILURE">The file upload failed.</resource>
+  <resource key="org.apache.myfaces.trinidad.UPLOAD_FAILURE_detail">{0}.</resource>
 
   <!-- hints for validators -->
   <resource key="org.apache.myfaces.trinidad.validator.RangeValidator.MAXIMUM_HINT">Enter a number less than or equal to {0}.</resource>

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/CompositeUploadedFileProcessorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/CompositeUploadedFileProcessorImpl.java?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/CompositeUploadedFileProcessorImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/CompositeUploadedFileProcessorImpl.java Tue Jul  6 21:16:56 2010
@@ -102,7 +102,20 @@ public class CompositeUploadedFileProces
       files.add(original);
       for(UploadedFileProcessor processor: chainedProcessors)
       {
-        original = processor.processFile(request, original);
+        try
+        {
+          original = processor.processFile(request, original);
+        }
+        catch (IOException ioe)
+        {
+          _LOG.severe(ioe);
+          String test = ioe.getLocalizedMessage();
+          original = new ErrorFile(ioe.getLocalizedMessage());
+          // The chain breaks if one of the chained processor throws an IOException, if the intent
+          //  is to allow rest of the processors in chain to process, they could return custom 
+          //  UploadedFile instance with length -1 and opaqueData having the failure details.
+          break;
+        }
         files.add(original);
       }
       //the dispose order should be reverse!
@@ -258,7 +271,7 @@ public class CompositeUploadedFileProces
   }
 
   private UploadedFile _processFile(
-      Object request, UploadedFile tempFile) throws IOException
+      Object request, UploadedFile tempFile)
   {
     RequestInfo info = _getRequestInfo(request);
     int contentLength = getContentLength(request);
@@ -288,7 +301,7 @@ public class CompositeUploadedFileProces
 
     if(contentLength>_maxDiskSpace)
     {
-      return new ErrorFile();
+      return new ErrorFile(_LOG.getMessage("UPLOADED_FILE_LARGE"));
     }
     // Process one new file, loading only as much as can fit
     // in the remaining memory and disk space.
@@ -303,7 +316,7 @@ public class CompositeUploadedFileProces
     catch(IOException ioe)
     {
       _LOG.severe(ioe);
-      return new ErrorFile();
+      return new ErrorFile(ioe.getLocalizedMessage());
     }
 
     // Keep a tally of how much we've stored in memory and on disk.

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ErrorFile.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ErrorFile.java?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ErrorFile.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ErrorFile.java Tue Jul  6 21:16:56 2010
@@ -26,6 +26,11 @@ import org.apache.myfaces.trinidad.model
 
 public class ErrorFile implements UploadedFile, Serializable
 {
+  
+  public ErrorFile(String errorMessage)
+  {
+    _errorMessage = errorMessage;
+  }
 
   public void dispose()
   {
@@ -53,8 +58,10 @@ public class ErrorFile implements Upload
 
   public Object getOpaqueData()
   {
-    return null;
+    return _errorMessage;
   }
+  
+  private String _errorMessage = null;
 
-  private static final long serialVersionUID = 1L;
+  private static final long serialVersionUID = 2L;
 }
\ No newline at end of file

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=961015&r1=961014&r2=961015&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 Tue Jul  6 21:16:56 2010
@@ -153,7 +153,7 @@ public class UploadedFileProcessorImpl i
     
     if(contentLength>_maxDiskSpace)
     {
-      return new ErrorFile();
+      return new ErrorFile(_LOG.getMessage("UPLOADED_FILE_LARGE"));
     }
     // Process one new file, loading only as much as can fit
     // in the remaining memory and disk space.
@@ -168,7 +168,7 @@ public class UploadedFileProcessorImpl i
     catch(IOException ioe)
     {
       _LOG.severe(ioe);
-      return new ErrorFile();
+      return new ErrorFile(ioe.getLocalizedMessage());
     }
 
     // Keep a tally of how much we've stored in memory and on disk.

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java Tue Jul  6 21:16:56 2010
@@ -109,7 +109,13 @@ public class SimpleInputFileRenderer ext
     UploadedFile file = (UploadedFile) submittedValue;
     if(file.getLength() == -1)
     {
-      FacesMessage fm = MessageFactory.getMessage(context, "org.apache.myfaces.trinidad.UPLOAD");
+      // There was a failure while one of the UploadedFileProcessor in the chain processed this file,
+      // we expect the details to be in opaqueData
+      String errorMessage = file.getOpaqueData().toString();
+      FacesMessage fm = MessageFactory.getMessage(context, 
+                                                  FacesMessage.SEVERITY_WARN, 
+                                                  "org.apache.myfaces.trinidad.UPLOAD_FAILURE", 
+                                                  new Object[]{errorMessage}, component); 
       throw new ConverterException(fm);
     }
 

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts?rev=961015&r1=961014&r2=961015&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/xrts/org/apache/myfaces/trinidadinternal/resource/LoggerBundle.xrts Tue Jul  6 21:16:56 2010
@@ -90,6 +90,9 @@
 <!-- CANNOT_INSTANTIATE_UPLOADEDFILEPROCESSOR -->
 <resource key="CANNOT_INSTANTIATE_UPLOADEDFILEPROCESSOR">Could not instantiate UploadedFileProcessor</resource>
 
+<!-- UPLOADED_FILE_LARGE -->
+<resource key="UPLOADED_FILE_LARGE">The file could not be uploaded because it is too large.</resource>
+
 <!-- RUNNING_IN_DEBUG_MODE -->
 <resource key="RUNNING_IN_DEBUG_MODE">Trinidad is running in debug mode. Do not use in a production environment. See:{0}</resource>