tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1467 repeated query param support for embedded http layer
Date Thu, 04 Dec 2014 15:20:20 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop 8112ec545 -> 4c05a943d


TOMEE-1467 repeated query param support for embedded http layer


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/4c05a943
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/4c05a943
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/4c05a943

Branch: refs/heads/develop
Commit: 4c05a943df8bfee1f7e099bed834ff552afea8f3
Parents: 8112ec5
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Thu Dec 4 16:19:37 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Thu Dec 4 16:19:37 2014 +0100

----------------------------------------------------------------------
 .../openejb/server/httpd/HttpRequestImpl.java   | 78 +++++++++++---------
 1 file changed, 42 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/4c05a943/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
index 21af108..78367ab 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
@@ -54,12 +54,16 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import static java.util.Collections.singletonList;
+
 /**
  * A class to take care of HTTP Requests.  It parses headers, content, form and url
  * parameters.
@@ -71,7 +75,7 @@ public class HttpRequestImpl implements HttpRequest {
     protected static final String EJBSESSIONID = "EJBSESSIONID";
 
     // note: no eviction so invalidate has to be called properly
-    private static final ConcurrentMap<String, HttpSession> SESSIONS = new ConcurrentHashMap<String,
HttpSession>();
+    private static final ConcurrentMap<String, HttpSession> SESSIONS = new ConcurrentHashMap<>();
 
     public static final Class<?>[] SERVLET_CONTEXT_INTERFACES = new Class<?>[]{ServletContext.class};
     public static final InvocationHandler SERVLET_CONTEXT_HANDLER = new InvocationHandler()
{
@@ -97,24 +101,24 @@ public class HttpRequestImpl implements HttpRequest {
     /**
      * the headers for this page
      */
-    private final Map<String, String> headers = new HashMap<String, String>();
+    private final Map<String, String> headers = new HashMap<>();
 
     /**
      * the form parameters for this page
      */
-    private final Map<String, String> formParams = new HashMap<String, String>();
+    private final Map<String, String> formParams = new HashMap<>();
 
     /**
      * the URL (or query) parameters for this page
      */
-    private final Map<String, String> queryParams = new HashMap<String, String>();
+    private final Map<String, List<String>> queryParams = new HashMap<>();
 
     /**
      * All form and query parameters.  Query parameters override form parameters.
      */
-    private final Map<String, String> parameters = new HashMap<String, String>();
+    private final Map<String, List<String>> parameters = new HashMap<>();
 
-    private final Map<String, Part> parts = new HashMap<String, Part>();
+    private final Map<String, Part> parts = new HashMap<>();
 
     /**
      * Cookies sent from the client
@@ -137,7 +141,7 @@ public class HttpRequestImpl implements HttpRequest {
     /**
      * Request scoped data which is set and used by application code.
      */
-    private final Map<String, Object> attributes = new HashMap<String, Object>();
+    private final Map<String, Object> attributes = new HashMap<>();
 
     private String path = "/";
     private Locale locale = Locale.getDefault();
@@ -187,21 +191,7 @@ public class HttpRequestImpl implements HttpRequest {
     }
 
     public Map<String, String> getFormParameters() {
-        return new HashMap<String, String>(formParams);
-    }
-
-    public Map<String, String> getQueryParameters() {
-        return new HashMap<String, String>(queryParams);
-    }
-
-    /**
-     * Gets a URL (or query) parameter based on the name passed in.
-     *
-     * @param name The name of the URL (or query) parameter
-     * @return The value of the URL (or query) parameter
-     */
-    public String getQueryParameter(String name) {
-        return queryParams.get(name);
+        return new HashMap<>(formParams);
     }
 
     /**
@@ -244,8 +234,10 @@ public class HttpRequestImpl implements HttpRequest {
     @Override
     public String getQueryString() {
         StringBuilder str = new StringBuilder("");
-        for (Map.Entry<String, String> q : queryParams.entrySet()) {
-            str.append(q.getKey()).append("=").append(q.getValue()).append("&");
+        for (final Map.Entry<String, List<String>> q : queryParams.entrySet())
{
+            for (final String v : q.getValue()) {
+                str.append(q.getKey()).append("=").append(v).append("&");
+            }
         }
         String out = str.toString();
         if (out.isEmpty()) {
@@ -362,8 +354,10 @@ public class HttpRequestImpl implements HttpRequest {
         readHeaders(di);
         readBody(di);
 
-        parameters.putAll(this.getFormParameters());
-        parameters.putAll(this.getQueryParameters());
+        for (final Map.Entry<String, String> formParameters : getFormParameters().entrySet())
{
+            parameters.put(formParameters.getKey(), singletonList(formParameters.getValue()));
+        }
+        parameters.putAll(queryParams);
 
         if (headers.containsKey("Cookie")) {
             final String cookie = headers.get("Cookie");
@@ -524,8 +518,12 @@ public class HttpRequestImpl implements HttpRequest {
                 value = URLDecoder.decode(param.nextToken());
             }
 
-            //System.out.println("[] "+name+" = "+value);
-            queryParams.put(name, value);
+            List<String> list = queryParams.get(name);
+            if (list == null) {
+                list = new LinkedList<String>();
+                queryParams.put(name, list);
+            }
+            list.add(value);
         }
     }
 
@@ -948,26 +946,29 @@ public class HttpRequestImpl implements HttpRequest {
     }
 
     public String getParameter(String name) {
-        return parameters.get(name);
+        final List<String> strings = parameters.get(name);
+        return strings == null ? null : strings.iterator().next();
     }
 
     @Override
     public Map<String, String[]> getParameterMap() {
-        Map<String, String[]> params = new HashMap<String, String[]>();
-        for (Map.Entry<String, String> p : parameters.entrySet()) {
-            params.put(p.getKey(), new String[]{p.getValue()});
+        final Map<String, String[]> params = new HashMap<String, String[]>();
+        for (final Map.Entry<String, List<String>> p : parameters.entrySet())
{
+            final List<String> values = p.getValue();
+            params.put(p.getKey(), values.toArray(new String[values.size()]));
         }
         return params;
     }
 
     @Override
     public Enumeration<String> getParameterNames() {
-        return new ArrayEnumeration(new ArrayList<String>(parameters.keySet()));
+        return new ArrayEnumeration(new ArrayList<>(parameters.keySet()));
     }
 
     @Override
-    public String[] getParameterValues(String s) {
-        return new String[]{parameters.get(s)};
+    public String[] getParameterValues(final String s) {
+        final List<String> strings = parameters.get(s);
+        return strings == null ? null : strings.toArray(new String[strings.size()]);
     }
 
     @Override
@@ -985,8 +986,13 @@ public class HttpRequestImpl implements HttpRequest {
         return path;
     }
 
+    @Deprecated // TODO should be dropped, do we drop axis module as well?
     public Map<String, String> getParameters() {
-        return new HashMap<String, String>(parameters);
+        final HashMap<String, String> converted = new HashMap<String, String>(parameters.size());
+        for (final Map.Entry<String, List<String>> entry : parameters.entrySet())
{
+            converted.put(entry.getKey(), entry.getValue().iterator().next());
+        }
+        return converted;
     }
 
     public String getRemoteAddr() {


Mime
View raw message