knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-626 - NameNode UI through Knox has various tabs not working
Date Thu, 27 Jul 2017 18:59:03 GMT
Repository: knox
Updated Branches:
  refs/heads/master edecb857a -> 0b15afc6c


KNOX-626 - NameNode UI through Knox has various tabs not working

Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/0b15afc6
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/0b15afc6
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/0b15afc6

Branch: refs/heads/master
Commit: 0b15afc6cb421de54991dfaa5193853e2cf5d2df
Parents: edecb85
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Thu Jul 27 14:58:38 2017 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Thu Jul 27 14:58:38 2017 -0400

----------------------------------------------------------------------
 ...entityAsserterHttpServletRequestWrapper.java | 108 ++++++----
 ...yAssertionHttpServletRequestWrapperTest.java |  16 +-
 .../hadoop/gateway/SpiGatewayMessages.java      |   3 +
 .../apache/hadoop/gateway/util/HttpUtils.java   |  24 +++
 .../hadoop/gateway/util/HttpUtilsTest.java      | 200 ++++++++++---------
 5 files changed, 210 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/0b15afc6/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
----------------------------------------------------------------------
diff --git a/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
b/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
index 2a2d9d9..961fef7 100644
--- a/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
+++ b/gateway-provider-identity-assertion-common/src/main/java/org/apache/hadoop/gateway/identityasserter/common/filter/IdentityAsserterHttpServletRequestWrapper.java
@@ -74,36 +74,56 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
   @SuppressWarnings("rawtypes")
   @Override
   public Map getParameterMap() {
-    return getParams();
+    Map map = null;
+    try {
+      map = getParams();
+    } catch (UnsupportedEncodingException e) {
+      log.unableToGetParamsFromQueryString(e);
+    }
+    return map;
   }
 
   @SuppressWarnings({ "unchecked", "rawtypes" })
   @Override
   public Enumeration getParameterNames() {
-    Map<String, String[]> params = getParams();
-    if (params == null) {
-      params = new HashMap<>();
+    Enumeration<String> e = null;
+    Map<String, List<String>> params;
+    try {
+      params = getParams();
+      if (params == null) {
+        params = new HashMap<>();
+      }
+      e = Collections.enumeration((Collection<String>) params.keySet());
+    } catch (UnsupportedEncodingException e1) {
+      log.unableToGetParamsFromQueryString(e1);
     }
-    Enumeration<String> e = Collections.enumeration((Collection<String>) params.keySet());
 
     return e;
   }
 
   @Override
   public String[] getParameterValues(String name) {
-    Map<String, String[]> params = getParams();
-    if (params == null) {
-      params = new HashMap<>();
+    String[] p = null;
+    Map<String, List<String>> params;
+    try {
+      params = getParams();
+      if (params == null) {
+        params = new HashMap<>();
+      }
+      p = (String[]) params.get(name).toArray();
+    } catch (UnsupportedEncodingException e) {
+      log.unableToGetParamsFromQueryString(e);
     }
 
-    return params.get(name);
+    return p;
   }
 
-  private Map<String, String[]> getParams( String qString ) {
-    Map<String, String[]> params = null;
+  private Map<String, List<String>> getParams( String qString )
+      throws UnsupportedEncodingException {
+    Map<String, List<String>> params = null;
     if (getMethod().equals("GET")) {
       if (qString != null && qString.length() > 0) {
-        params = HttpUtils.parseQueryString( qString );
+        params = HttpUtils.splitQuery( qString );
       }
       else {
         params = new HashMap<>();
@@ -114,43 +134,47 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
         return null;
       }
       else {
-        params = HttpUtils.parseQueryString( qString );
+        params = HttpUtils.splitQuery( qString );
       }
     }  
     return params;
   }
 
-  private Map<String, String[]> getParams() {
+  private Map<String, List<String>> getParams()
+      throws UnsupportedEncodingException {
     return getParams( super.getQueryString() );
   }
 
   @Override
   public String getQueryString() {
     String q = null;
-    Map<String, String[]> params = getParams();
+    Map<String, List<String>> params;
+    try {
+      params = getParams();
+      if (params == null) {
+        params = new HashMap<>();
+      }
+      ArrayList<String> al = new ArrayList<String>();
+      al.add(username);
 
-    if (params == null) {
-      params = new HashMap<>();
-    }
-    
-    ArrayList<String> al = new ArrayList<String>();
-    al.add(username);
-    String[] a = { "" };
+      List<String> principalParamNames = getImpersonationParamNames();
+      params = scrubOfExistingPrincipalParams(params, principalParamNames);
 
-    List<String> principalParamNames = getImpersonationParamNames();
-    params = scrubOfExistingPrincipalParams(params, principalParamNames);
+      if ("true".equals(System.getProperty(GatewayConfig.HADOOP_KERBEROS_SECURED))) {
+        params.put(DOAS_PRINCIPAL_PARAM, al);
+      } else {
+        params.put(PRINCIPAL_PARAM, al);
+      }
 
-    if ("true".equals(System.getProperty(GatewayConfig.HADOOP_KERBEROS_SECURED))) {
-      params.put(DOAS_PRINCIPAL_PARAM, al.toArray(a));
-    } else {
-      params.put(PRINCIPAL_PARAM, al.toArray(a));
+      String encoding = getCharacterEncoding();
+      if (encoding == null) {
+        encoding = Charset.defaultCharset().name();
+      }
+      q = urlEncode(params, encoding);
+    } catch (UnsupportedEncodingException e) {
+      log.unableToGetParamsFromQueryString(e);
     }
 
-    String encoding = getCharacterEncoding();
-    if (encoding == null) {
-      encoding = Charset.defaultCharset().name();
-    }
-    q = urlEncode(params, encoding);
     return q;
   }
 
@@ -165,8 +189,8 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
     return principalParamNames;
   }
 
-  private Map<String, String[]> scrubOfExistingPrincipalParams(
-      Map<String, String[]> params, List<String> principalParamNames) {
+  private Map<String, List<String>> scrubOfExistingPrincipalParams(
+      Map<String, List<String>> params, List<String> principalParamNames)
{
     HashSet<String> remove = new HashSet<>();
     for (String paramKey : params.keySet()) {
       for (String p : principalParamNames) {
@@ -202,7 +226,7 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
         encoding = Charset.defaultCharset().name();
       }
       String body = IOUtils.toString( super.getInputStream(), encoding );
-      Map<String, String[]> params = getParams( body );
+      Map<String, List<String>> params = getParams( body );
       if (params == null) {
         params = new HashMap<>();
       }
@@ -222,17 +246,17 @@ private static SpiGatewayMessages log = MessagesFactory.get( SpiGatewayMessages.
     }
   }
 
-  public static String urlEncode( Map<String, String[]> map, String encoding ) {
+  public static String urlEncode( Map<String, List<String>> map, String encoding
) {
     StringBuilder sb = new StringBuilder();
-    for( Map.Entry<String,String[]> entry : map.entrySet() ) {
+    for( Map.Entry<String,List<String>> entry : map.entrySet() ) {
       String name = entry.getKey();
       if( name != null && name.length() > 0 ) {
-        String[] values = entry.getValue();
-        if( values == null || values.length == 0 ) {
+        List<String> values = entry.getValue();
+        if( values == null || values.size() == 0 ) {
           sb.append( entry.getKey() );
         } else {
-          for( int i = 0; i < values.length; i++ ) {
-            String value = values[ i ];
+          for( int i = 0; i < values.size(); i++ ) {
+            String value = values.get(i);
               if( sb.length() > 0 ) {
                 sb.append( "&" );
               }

http://git-wip-us.apache.org/repos/asf/knox/blob/0b15afc6/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/filter/IdentityAssertionHttpServletRequestWrapperTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/filter/IdentityAssertionHttpServletRequestWrapperTest.java
b/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/filter/IdentityAssertionHttpServletRequestWrapperTest.java
index b026fc0..709c6e4 100644
--- a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/filter/IdentityAssertionHttpServletRequestWrapperTest.java
+++ b/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/filter/IdentityAssertionHttpServletRequestWrapperTest.java
@@ -30,7 +30,10 @@ import org.junit.experimental.categories.Category;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsString;
@@ -245,7 +248,7 @@ public class IdentityAssertionHttpServletRequestWrapperTest {
   @Test
   public void testUrlEncode() {
     String s;
-    HashMap<String,String[]> m;
+    HashMap<String,List<String>> m;
 
     m = new HashMap<>();
     m.put( "null-values", null );
@@ -253,17 +256,22 @@ public class IdentityAssertionHttpServletRequestWrapperTest {
     assertThat( s, is( "null-values" ) );
 
     m = new HashMap<>();
-    m.put( "no-values", new String[0] );
+    m.put( "no-values", new ArrayList<String>(0) );
     s = IdentityAsserterHttpServletRequestWrapper.urlEncode( m, "UTF-8" );
     assertThat( s, is( "no-values" ) );
 
     m = new HashMap<>();
-    m.put( "one-value", new String[]{ "value1" } );
+    List<String> lst = new ArrayList<String>();
+    lst.add("value1");
+    m.put( "one-value", lst);
     s = IdentityAsserterHttpServletRequestWrapper.urlEncode( m, "UTF-8" );
     assertThat( s, is( "one-value=value1" ) );
 
     m = new HashMap<>();
-    m.put( "two-values", new String[]{ "value1", "value2" } );
+    lst = new ArrayList<String>();
+    String[] a = {"value1", "value2"};
+    lst.addAll(Arrays.asList(a));
+    m.put( "two-values", lst);
     s = IdentityAsserterHttpServletRequestWrapper.urlEncode( m, "UTF-8" );
     assertThat( s, is( "two-values=value1&two-values=value2" ) );
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/0b15afc6/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
index 25226f5..7ef2f49 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/SpiGatewayMessages.java
@@ -70,4 +70,7 @@ public interface SpiGatewayMessages {
 
   @Message( level = MessageLevel.WARN, text = "Possible identity spoofing attempt - impersonation
parameter removed: {0}" )
   void possibleIdentitySpoofingAttempt( String impersonationParam );
+
+  @Message( level = MessageLevel.WARN, text = "Error ocurred while accessing params in query
string: {0}" )
+  void unableToGetParamsFromQueryString(@StackTrace(level=MessageLevel.WARN) Exception e);
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/0b15afc6/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/HttpUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/HttpUtils.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/HttpUtils.java
index 5cf62d6..7f5e96a 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/HttpUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/HttpUtils.java
@@ -18,14 +18,38 @@
 package org.apache.hadoop.gateway.util;
 
 import java.io.UnsupportedEncodingException;
+import java.net.URL;
 import java.net.URLDecoder;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
 public class HttpUtils {
 
+  public static Map<String, List<String>> splitQuery(String queryString)
+      throws UnsupportedEncodingException {
+    final Map<String, List<String>> queryPairs = new LinkedHashMap<String,
List<String>>();
+    if (queryString == null || queryString.trim().isEmpty()) {
+      return queryPairs;
+    }
+    final String[] pairs = queryString.split("&");
+    for (String pair : pairs) {
+      final int idx = pair.indexOf("=");
+      final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8")
: pair;
+      if (!queryPairs.containsKey(key)) {
+        queryPairs.put(key, new LinkedList<String>());
+      }
+      final String value = idx > 0 && pair.length() > idx + 1 
+          ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : "";
+      queryPairs.get(key).add(value);
+    }
+    return queryPairs;
+  }
+
   public static Map<String,String[]> parseQueryString( String queryString ) {
     Map<String,String[]> map = new HashMap<>();
     if( queryString != null && !queryString.isEmpty() ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/0b15afc6/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/HttpUtilsTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/HttpUtilsTest.java
b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/HttpUtilsTest.java
index 0e86a3b..a0b725b 100644
--- a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/HttpUtilsTest.java
+++ b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/HttpUtilsTest.java
@@ -19,185 +19,195 @@ package org.apache.hadoop.gateway.util;
 
 import org.junit.Test;
 
+import java.util.List;
 import java.util.Map;
 
 import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
 public class HttpUtilsTest {
 
   @Test
-  public void testParseQueryString_BugKnox599() {
+  public void testParseQueryString_BugKnox599() throws Exception {
 
-    Map<String,String[]> map;
+    Map<String,List<String>> map;
 
-    map = HttpUtils.parseQueryString( null );
+    map = HttpUtils.splitQuery( null );
     assertThat( map, notNullValue() );
     assertThat( map.isEmpty(), is( true ) );
 
-    map = HttpUtils.parseQueryString( "" );
+    map = HttpUtils.splitQuery( "" );
     assertThat( map, notNullValue() );
     assertThat( map.isEmpty(), is( true ) );
 
-    map = HttpUtils.parseQueryString( "test-name=test-value" );
+    map = HttpUtils.splitQuery( "test-name=test-value" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test-name" ), is( true ) );
-    assertThat( map.get( "test-name" ).length, is( 1 ) );
-    assertThat( map.get( "test-name" )[0], is( "test-value" ) );
+    assertThat( map.get( "test-name" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name" ).get(0), is( "test-value" ) );
 
-    map = HttpUtils.parseQueryString( "test-name-one=test-value-one&test-name-two=two=test-value-two"
);
+    map = HttpUtils.splitQuery( "test-name-one=test-value-one&test-name-two=two=test-value-two"
);
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 2 ) );
     assertThat( map.containsKey( "test-name-one" ), is( true ) );
-    assertThat( map.get( "test-name-one" ).length, is( 1 ) );
-    assertThat( map.get( "test-name-one" )[0], is( "test-value-one" ) );
+    assertThat( map.get( "test-name-one" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name-one" ).get(0), is( "test-value-one" ) );
     assertThat( map.containsKey( "test-name-two" ), is( true ) );
-    assertThat( map.get( "test-name-two" ).length, is( 1 ) );
-    assertThat( map.get( "test-name-two" )[0], is( "test-value-two" ) );
+    assertThat( map.get( "test-name-two" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name-two" ).get(0), is( "two=test-value-two" ) );
 
-    map = HttpUtils.parseQueryString( "test-name-one=test-value-one?test-name-two=two=test-value-two"
);
+    map = HttpUtils.splitQuery( "test-name-one=test-value-one?test-name-two=two=test-value-two"
);
     assertThat( map, notNullValue() );
-    assertThat( map.size(), is( 2 ) );
-    assertThat( map.containsKey( "test-name-one" ), is( true ) );
-    assertThat( map.get( "test-name-one" ).length, is( 1 ) );
-    assertThat( map.get( "test-name-one" )[0], is( "test-value-one" ) );
-    assertThat( map.containsKey( "test-name-two" ), is( true ) );
-    assertThat( map.get( "test-name-two" ).length, is( 1 ) );
-    assertThat( map.get( "test-name-two" )[0], is( "test-value-two" ) );
+    assertThat( map.size(), is( 1 ) );
+    assertThat( map.containsKey( "test-name-two" ), is( false ) );
+    assertThat( map.get( "test-name-one" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name-one" ).get(0), is( "test-value-one?test-name-two=two=test-value-two"
) );
 
-    map = HttpUtils.parseQueryString( "test-name-one=test-value-one;test-name-two=two=test-value-two"
);
+    map = HttpUtils.splitQuery( "test-name-one=test-value-one;test-name-two=two=test-value-two"
);
     assertThat( map, notNullValue() );
-    assertThat( map.size(), is( 2 ) );
+    assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test-name-one" ), is( true ) );
-    assertThat( map.get( "test-name-one" ).length, is( 1 ) );
-    assertThat( map.get( "test-name-one" )[0], is( "test-value-one" ) );
-    assertThat( map.containsKey( "test-name-two" ), is( true ) );
-    assertThat( map.get( "test-name-two" ).length, is( 1 ) );
-    assertThat( map.get( "test-name-two" )[0], is( "test-value-two" ) );
+    assertThat( map.get( "test-name-one" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name-one" ).get(0), is( "test-value-one;test-name-two=two=test-value-two"
) );
+    assertThat( map.containsKey( "test-name-two" ), is( false ) );
 
-    map = HttpUtils.parseQueryString( "test-name=test-value-one?test-name=test-value-two"
);
+    map = HttpUtils.splitQuery( "test-name=test-value-one?test-name=test-value-two" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test-name" ), is( true ) );
-    assertThat( map.get( "test-name" ).length, is( 2 ) );
-    assertThat( map.get( "test-name" )[0], is( "test-value-one" ) );
-    assertThat( map.get( "test-name" )[1], is( "test-value-two" ) );
+    assertThat( map.get( "test-name" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name" ).get(0), is( "test-value-one?test-name=test-value-two"
) );
 
-    map = HttpUtils.parseQueryString( "test-name=test-value-one&test-name=test-value-two"
);
+    map = HttpUtils.splitQuery( "test-name=test-value-one&test-name=test-value-two" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test-name" ), is( true ) );
-    assertThat( map.get( "test-name" ).length, is( 2 ) );
-    assertThat( map.get( "test-name" )[0], is( "test-value-one" ) );
-    assertThat( map.get( "test-name" )[1], is( "test-value-two" ) );
-
-    map = HttpUtils.parseQueryString( "test-name=test-value-one;test-name=test-value-two"
);
+    assertThat( map.get( "test-name" ).size(), is( 2 ) );
+    assertThat( map.get( "test-name" ).get(0), is( "test-value-one" ) );
+    assertThat( map.get( "test-name" ).get(1), is( "test-value-two" ) );
+
+    // https://www.w3.org/TR/2014/REC-html5-20141028/forms.html#url-encoded-form-data
+    // 4.10.22.6 URL-encoded form data
+    // To decode application/x-www-form-urlencoded payloads, the following algorithm should
be used
+    // This algorithm uses as inputs the payload itself, payload, consisting of a Unicode
string
+    // using only characters in the range U+0000 to U+007F; a default character encoding
encoding;
+    // and optionally an isindex flag indicating that the payload is to be processed as if
it had
+    // been generated for a form containing an isindex control. The output of this algorithm
is a
+    // sorted list of name-value pairs. If the isindex flag is set and the first control
really was
+    // an isindex control, then the first name-value pair will have as its name the empty
string.
+    // Which default character encoding to use can only be determined on a case-by-case basis,
but
+    // generally the best character encoding to use as a default is the one that was used
to encode
+    // the page on which the form used to create the payload was itself found. In the absence
of a
+    // better default, UTF-8 is suggested.
+    // The isindex flag is for legacy use only. Forms in conforming HTML documents will not
generate
+    // payloads that need to be decoded with this flag set.
+    //
+    // Let strings be the result of strictly splitting the string payload on U+0026 AMPERSAND
+    // characters (&).
+    map = HttpUtils.splitQuery( "test-name=test-value-one;test-name=test-value-two" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test-name" ), is( true ) );
-    assertThat( map.get( "test-name" ).length, is( 2 ) );
-    assertThat( map.get( "test-name" )[0], is( "test-value-one" ) );
-    assertThat( map.get( "test-name" )[1], is( "test-value-two" ) );
+    assertThat( map.get( "test-name" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name" ).get(0), is( "test-value-one;test-name=test-value-two"
) );
 
-    map = HttpUtils.parseQueryString( "test-name=" );
+    map = HttpUtils.splitQuery( "test-name=" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test-name" ), is( true ) );
-    assertThat( map.get( "test-name" ).length, is( 1 ) );
-    assertThat( map.get( "test-name" )[0], is( "" ) );
+    assertThat( map.get( "test-name" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name" ).get(0), is( "" ) );
 
-    map = HttpUtils.parseQueryString( "test-name" );
+    map = HttpUtils.splitQuery( "test-name" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test-name" ), is( true ) );
-    assertThat( map.get( "test-name" ).length, is( 1 ) );
-    assertThat( map.get( "test-name" )[0], nullValue() );
+    assertThat( map.get( "test-name" ).size(), is( 1 ) );
+    assertThat( map.get( "test-name" ).get(0), is("") );
 
-    map = HttpUtils.parseQueryString( "=test-value" );
+    map = HttpUtils.splitQuery( "=test-value" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( "" ), is( true ) );
-    assertThat( map.get( "" ).length, is( 1 ) );
-    assertThat( map.get( "" )[0], is( "test-value" ) );
+    assertThat( map.containsKey( "=test-value" ), is( true ) );
+    assertThat( map.get( "=test-value" ).size(), is( 1 ) );
+    assertThat( map.get( "=test-value" ).get(0), is( "" ) );
 
-    map = HttpUtils.parseQueryString( "=" );
+    map = HttpUtils.splitQuery( "=" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( "" ), is( true ) );
-    assertThat( map.get( "" ).length, is( 1 ) );
-    assertThat( map.get( "" )[0], is( "" ) );
+    assertThat( map.containsKey( "=" ), is( true ) );
+    assertThat( map.get( "=" ).size(), is( 1 ) );
+    assertThat( map.get( "=" ).get(0), is( "" ) );
 
-    map = HttpUtils.parseQueryString( "==" );
+    map = HttpUtils.splitQuery( "==" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( "" ), is( true ) );
-    assertThat( map.get( "" ).length, is( 2 ) );
-    assertThat( map.get( "" )[0], is( "" ) );
-    assertThat( map.get( "" )[1], is( "" ) );
+    assertThat( map.containsKey( "==" ), is( true ) );
+    assertThat( map.get( "==" ).size(), is( 1 ) );
+    assertThat( map.get( "==" ).get(0), is( "" ) );
 
-    map = HttpUtils.parseQueryString( "&" );
+    map = HttpUtils.splitQuery( "&" );
     assertThat( map, notNullValue() );
-    assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( null ), is( true ) );
-    assertThat( map.get( null ).length, is( 1 ) );
-    assertThat( map.get( null )[0], nullValue() );
+    assertThat( map.size(), is( 0 ) );
+    assertThat( map.containsKey( null ), is( false ) );
 
-    map = HttpUtils.parseQueryString( "?" );
+    map = HttpUtils.splitQuery( "?" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( null ), is( true ) );
-    assertThat( map.get( null ).length, is( 1 ) );
-    assertThat( map.get( null )[0], nullValue() );
+    assertThat( map.containsKey( "?" ), is( true ) );
+    assertThat( map.get( "?" ).size(), is( 1 ) );
+    assertThat( map.get( "?" ).get(0), is("") );
 
-    map = HttpUtils.parseQueryString( ";" );
+    map = HttpUtils.splitQuery( ";" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( null ), is( true ) );
-    assertThat( map.get( null ).length, is( 1 ) );
-    assertThat( map.get( null )[0], nullValue() );
+    assertThat( map.containsKey( ";" ), is( true ) );
+    assertThat( map.get( ";" ).size(), is( 1 ) );
+    assertThat( map.get( ";" ).get(0), is("") );
 
-    map = HttpUtils.parseQueryString( "&=" );
+    map = HttpUtils.splitQuery( "&=" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 2 ) );
     assertThat( map.containsKey( "" ), is( true ) );
-    assertThat( map.get( "" ).length, is( 1 ) );
-    assertThat( map.get( "" )[0], is( "" ) );
-    assertThat( map.containsKey( null ), is( true ) );
-    assertThat( map.get( null ).length, is( 1 ) );
-    assertThat( map.get( null )[0], nullValue() );
+    assertThat( map.get( "" ).size(), is( 1 ) );
+    assertThat( map.get( "" ).get(0), is( "" ) );
+    assertThat( map.containsKey( "=" ), is( true ) );
+    assertThat( map.get( "=" ).size(), is( 1 ) );
+    assertThat( map.get( "=" ).get(0), is("") );
 
-    map = HttpUtils.parseQueryString( "=&" );
+    map = HttpUtils.splitQuery( "=&" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( "" ), is( true ) );
-    assertThat( map.get( "" ).length, is( 1 ) );
-    assertThat( map.get( "" )[0], is( "" ) );
+    assertThat( map.containsKey( "=" ), is( true ) );
+    assertThat( map.get( "=" ).size(), is( 1 ) );
+    assertThat( map.get( "=" ).get(0), is( "" ) );
 
-    map = HttpUtils.parseQueryString( "&&" );
+    map = HttpUtils.splitQuery( "&&" );
     assertThat( map, notNullValue() );
-    assertThat( map.size(), is( 1 ) );
-    assertThat( map.containsKey( null ), is( true ) );
-    assertThat( map.get( null ).length, is( 2 ) );
-    assertThat( map.get( null )[0], nullValue() );
-    assertThat( map.get( null )[1], nullValue() );
+    assertThat( map.size(), is( 0 ) );
 
-    map = HttpUtils.parseQueryString( "test+name=test+value" );
+    map = HttpUtils.splitQuery( "test+name=test+value" );
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test name" ), is( true ) );
-    assertThat( map.get( "test name" ).length, is( 1 ) );
-    assertThat( map.get( "test name" )[0], is( "test value" ) );
+    assertThat( map.get( "test name" ).size(), is( 1 ) );
+    assertThat( map.get( "test name" ).get(0), is( "test value" ) );
 
-    map = HttpUtils.parseQueryString( "test%26name=test%3Dvalue" );
+    map = HttpUtils.splitQuery("test%26name=test%3Dvalue");
     assertThat( map, notNullValue() );
     assertThat( map.size(), is( 1 ) );
     assertThat( map.containsKey( "test&name" ), is( true ) );
-    assertThat( map.get( "test&name" ).length, is( 1 ) );
-    assertThat( map.get( "test&name" )[0], is( "test=value" ) );
+    assertThat( map.get( "test&name" ).size(), is( 1 ) );
+    assertThat( map.get( "test&name" ).get(0), is( "test=value" ) );
 
+    map = HttpUtils.splitQuery( "qry=Hadoop:service=NameNode,name=NameNodeInfo" );
+    assertThat( map, notNullValue() );
+    assertThat( map.size(), is( 1 ) );
+    assertThat( map.containsKey( "qry" ), is( true ) );
+    assertThat( map.get( "qry" ).size(), is( 1 ) );
+    assertThat( map.get( "qry" ).get(0), is( "Hadoop:service=NameNode,name=NameNodeInfo"
) );
   }
 
 }


Mime
View raw message