incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awi...@apache.org
Subject svn commit: r507315 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload: FileUploadConfiguratorImpl.java UploadRequestWrapper.java
Date Wed, 14 Feb 2007 00:02:09 GMT
Author: awiner
Date: Tue Feb 13 16:02:08 2007
New Revision: 507315

URL: http://svn.apache.org/viewvc?view=rev&rev=507315
Log:
File upload fixes:
- Fix potential double-decoding of parameters
- Fix incorrect warnings of "can't call setCharacterEncoding(), it's too late"
- Fix unnecessary extra merge of the already-present request parameters
- Add warning of "can't call setCharacterEncoding()" back where appropriate

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java?view=diff&rev=507315&r1=507314&r2=507315
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
Tue Feb 13 16:02:08 2007
@@ -165,13 +165,6 @@
 
     if(addedParams != null)
     {
-      @SuppressWarnings("unchecked")
-      Map<String, String[]> parameters = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
-      parameters.putAll(addedParams);
-
-      // TODO sobryan (dependency = JSF 1.2)
-      // For JSF 1.2, we can probably simply wrap the request objects and set them on
-      // the existing ExternalContext.
       return _getExternalContextWrapper(externalContext, addedParams);
     }
 

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java?view=diff&rev=507315&r1=507314&r2=507315
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java
Tue Feb 13 16:02:08 2007
@@ -16,10 +16,10 @@
  * Request wrapper class that hooks in parameters identified in
  * the servlet request.
  *
- * @todo Stop going String -> bytes -> String;  change MultipartFormHandler
- *  to simply extract byte arrays, and do all the type conversion here.
  * @author The Oracle ADF Faces Team
  */
+// TODO Stop going String -> bytes -> String;  change MultipartFormHandler
+//    to simply extract byte arrays, and do all the type conversion here.
 @SuppressWarnings("deprecation")
 public class UploadRequestWrapper extends HttpServletRequestWrapper
 {
@@ -30,10 +30,12 @@
     super(request);
     
     @SuppressWarnings("unchecked")
-    Map<String, String[]> origionalMap = super.getParameterMap();
+    // Merge in all the original parameters
+    Map<String, String[]> originalMap = super.getParameterMap();
     
-    _extractedParams = new HashMap<String, String[]>(origionalMap);
+    _extractedParams = new HashMap<String, String[]>(originalMap);
     _extractedParams.putAll(params);
+    _encoding = super.getCharacterEncoding();
   }
   
   /**
@@ -46,6 +48,12 @@
     return _WWW_FORM_URLENCODED_TYPE;
   }
 
+  @Override
+  public String getCharacterEncoding()
+  {
+    return _encoding;
+  }
+
   /**
    * Trap calls to setCharacterEncoding() to decode parameters correctly
    */
@@ -53,7 +61,24 @@
   public void setCharacterEncoding(String encoding)
     throws UnsupportedEncodingException
   {
-    super.setCharacterEncoding(encoding);
+    // It is illegal to set the character encoding after parameters
+    // have been retrieved.  This is an annoying restriction,
+    // but we shouldn't break it
+    if (_parametersRetrieved)
+    {
+      _LOG.warning("Unable to set request character encoding to {0}, " + 
+                   "because request parameters have already been read.",
+                   encoding);
+      return;
+    }
+
+    // If the encoding is already right, we can bail
+    if (encoding.equals(_encoding))
+      return;
+    
+    // Don't call super.setCharacterEncoding() - it's too late
+    // and we'll get a warning
+    _encoding = encoding;
     if (_LOG.isFine())
       _LOG.fine("Switching encoding of wrapper to " + encoding);
 
@@ -62,6 +87,9 @@
       
     byte[] buffer = new byte[256];
     
+    // FIXME: decodeRequestParameter() assumes the incoming
+    // character set is ISO-8859-1 - but this is not
+    // necessarily true!
     for(Map.Entry<String, String[]> entry : _extractedParams.entrySet())
     {
       String key = entry.getKey();
@@ -130,6 +158,9 @@
    */
   private Map<String, String[]> _getMap()
   {
+    // Mark that parameters have been retrieved so we 
+    // can log a proper warning
+    _parametersRetrieved = true;
     if (_extractedAndDecodedParams != null)
       return _extractedAndDecodedParams;
 
@@ -138,6 +169,8 @@
 
   private Map<String, String[]> _extractedAndDecodedParams;
   private Map<String, String[]> _extractedParams;
+  private String                _encoding;
+  private boolean               _parametersRetrieved;
 
   private static final String _WWW_FORM_URLENCODED_TYPE =
     "application/x-www-form-urlencoded";



Mime
View raw message