code: public static Map<String,String> getQueryKeyValuePairs(URI uri) throws UnsupportedEncodingException {
          Map<String,String> queryParameters = new HashMap<String, String>();
          String query = uri.getRawQuery();
          if(query == null) {
              // Maybe invalid URI
              try {
                  uri = URI.create(uri.getRawSchemeSpecificPart());
                  query = uri.getRawQuery();
                  if(query == null) {
                      return queryParameters;
                  }
              } catch (IllegalArgumentException ex) {
                  return queryParameters;
              }
          }
          StringTokenizer stringTokenizer = new StringTokenizer(query, "&");
          while (stringTokenizer.hasMoreTokens()) {
              String keyValue = stringTokenizer.nextToken().trim();
              if(!keyValue.isEmpty()) {
                  int equalPos = keyValue.indexOf("=");
                  // If there is no value
                  String key = URLDecoder.decode(keyValue.substring(0,equalPos != -1 ?
                          equalPos : keyValue.length()), ENCODING);
                  if(equalPos==-1 || equalPos == keyValue.length() - 1) {
                      // Key without value
                      queryParameters.put(key.toLowerCase(),"");
                  } else {
                      String value = URLDecoder.decode(keyValue.substring(equalPos+1), ENCODING);
                      queryParameters.put(key.toLowerCase(),value);
                  }
              }
          }
          return queryParameters;
      }
docs: Read the Query part of an URI.
  
  @param uri URI to split
  
  @return Key/Value pairs of query, the key is lowercase and value may be null
  
  @throws java.io.UnsupportedEncodingException