You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/01/18 15:52:31 UTC

svn commit: r613180 - in /incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters: ParameterSupport.java Util.java

Author: fmeschbe
Date: Fri Jan 18 06:52:31 2008
New Revision: 613180

URL: http://svn.apache.org/viewvc?rev=613180&view=rev
Log:
SLING-152 Removing the parsing of all parameters provided by the
servlet container. This not only comprises the url encoded input
stream data but also the query parameters from the request line.
We just take what we get from the servlet container, apply our
encoding (if any).

We still keep the parsing of multipart/form-data POST request
data, as this is never handled by the servlet container according
to the Servlet API spec.

Modified:
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/Util.java

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java?rev=613180&r1=613179&r2=613180&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java (original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/ParameterSupport.java Fri Jan 18 06:52:31 2008
@@ -97,20 +97,18 @@
 
     private ParameterMap getRequestParameterMapInternal() {
         if (this.postParameterMap == null) {
-            // actually we also have to integrate the standard servlet
-            // parameters from the URL queryString !!
+
+            // SLING-152 Get parameters from the servlet Container
             ParameterMap parameters = new ParameterMap();
-            this.parseQueryString(parameters);
+            getContainerParameters(parameters);
 
-            // read post parametervalues
+            // only read input in case of multipart-POST not handled
+            // by the servlet container
             if ("POST".equals(this.getServletRequest().getMethod())) {
                 if (ServletFileUpload.isMultipartContent(new ServletRequestContext(
                     this.getServletRequest()))) {
                     this.parseMultiPartPost(parameters);
                     this.requestDataUsed = true;
-                } else if ("application/x-www-form-urlencoded".equalsIgnoreCase(this.getServletRequest().getContentType())) {
-                    this.parseFormEncodedPost(parameters);
-                    this.requestDataUsed = true;
                 }
             }
 
@@ -122,32 +120,27 @@
         return this.postParameterMap;
     }
 
-    private void parseQueryString(ParameterMap parameters) {
-        String queryString = SlingRequestPaths.getQueryString(requestData.getSlingRequest());
-        InputStream input = Util.getInputStream(queryString);
-        try {
-            Util.parse(input, Util.ENCODING_DEFAULT, parameters, true);
-        } catch (IOException ioe) {
-            // TODO: log
-        }
-    }
+    private void getContainerParameters(ParameterMap parameters) {
 
-    protected void parseFormEncodedPost(ParameterMap parameters) {
-        // TODO see SLING-152 - for now this is hardcoded to Util.ENCODING_DEFAULT
-        final Map<?, ?> pMap = this.getServletRequest().getParameterMap();
+        final Map<?, ?> pMap = getServletRequest().getParameterMap();
         for (Map.Entry<?, ?> entry : pMap.entrySet()) {
-            final String name = (String)entry.getKey();
+            
+            final String name = (String) entry.getKey();
             final String[] values = (String[]) entry.getValue();
+            
             for (int i = 0; i < values.length; i++) {
-                final EncodedRequestParameter rp = new EncodedRequestParameter(Util.ENCODING_DEFAULT);
+                final EncodedRequestParameter rp = new EncodedRequestParameter(
+                    Util.ENCODING_DEFAULT);
                 try {
                     rp.setContent(values[i].getBytes(Util.ENCODING_DEFAULT));
-                } catch(UnsupportedEncodingException ue) {
-                    throw new Error("Unexpected UnsupportedEncodingException for encoding=" + Util.ENCODING_DEFAULT);
+                } catch (UnsupportedEncodingException ue) {
+                    throw new Error(
+                        "Unexpected UnsupportedEncodingException for encoding="
+                            + Util.ENCODING_DEFAULT);
                 }
                 parameters.addParameter(name, rp);
             }
-            
+
         }
     }
 

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/Util.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/Util.java?rev=613180&r1=613179&r2=613180&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/Util.java (original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/parameters/Util.java Fri Jan 18 06:52:31 2008
@@ -76,65 +76,6 @@
         return new ByteArrayInputStream(data);
     }
 
-    static void parse(InputStream input, String encoding,
-            ParameterMap parameterMap, boolean allowSemicolon)
-            throws IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        int b;
-        boolean readingName = true;
-        EncodedRequestParameter current = null;
-        while ((b = input.read()) >= 0) {
-            if (b == '=' && readingName) {
-                // finished reading the name
-                current = createParameter(parameterMap, bos.toByteArray(),
-                    encoding);
-                bos.reset();
-                readingName = false;
-            } else if (b == '&' || (b == ';' && allowSemicolon)) {
-                // finished reading the value
-                // smicolon allowed as per HTML 4 recommendation for HTML
-                // enclosed URLs with parameters to prevent required encoding
-                // of '&' characters inside HTML
-                // see
-                // http://www.w3.org/TR/html4/appendix/notes.html#ampersands-in-uris
-                if (readingName) {
-                    // still reading the name, have a parameter without value
-                    current = createParameter(parameterMap, bos.toByteArray(),
-                        encoding);
-                } else {
-                    if (current != null) {
-                        current.setContent(bos.toByteArray());
-                    }
-                    readingName = true;
-                }
-                bos.reset();
-            } else {
-                bos.write(b);
-            }
-        }
-
-        // finished reading the value for a potential name
-        if (bos.size() > 0 && current != null) {
-            current.setContent(bos.toByteArray());
-        }
-    }
-
-    private static EncodedRequestParameter createParameter(
-            ParameterMap parameterMap, byte[] rawName, String encoding)
-            throws UnsupportedEncodingException {
-        String name = toIdentityEncodedString(rawName);
-        if (encoding != null) {
-            try {
-                name = URLDecoder.decode(name, encoding);
-            } catch (IllegalArgumentException iae) {
-                // TODO: might log this, for now just ignore
-            }
-        }
-        EncodedRequestParameter erp = new EncodedRequestParameter(encoding);
-        parameterMap.addParameter(name, erp);
-        return erp;
-    }
-
     static void fixEncoding(ParameterMap parameterMap) {
         // default the encoding to ISO-8859-1 (aka direct, 1:1 encoding)
         String formEncoding = ENCODING_DIRECT;