@Test public void testExtractAllQueryParameters() throws Exception { Map<String, List<String>> result = RestUtil.extractAllQueryParameters("some=value", "false"); Assert.assertEquals("value", result.get("some").get(0)); result = RestUtil.extractAllQueryParameters("some=value&another=v", "false"); Assert.assertEquals("value", result.get("some").get(0)); Assert.assertEquals("v", result.get("another").get(0)); result = RestUtil.extractAllQueryParameters("", "false"); Assert.assertTrue(result.isEmpty()); result = RestUtil.extractAllQueryParameters("some=v1&another=v&some=v2", "false"); Assert.assertEquals("v1", result.get("some").get(0)); Assert.assertEquals("v2", result.get("some").get(1)); Assert.assertEquals("v", result.get("another").get(0)); }
public static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding) { Map<String, List<String>> allQueryParameterMap = new HashMap<String, List<String>>(); if(Boolean.parseBoolean(formEncoding)){ List<String> encoding = new ArrayList<String>(); encoding.add(formEncoding); allQueryParameterMap.put(ACCEPT_FORM_ENCODING, encoding ); } if (queryString != null && queryString.length() > 0) { List<String> queryParameters = Arrays.asList(queryString.split("\\&")); for (String param : queryParameters) { String decodedParam = Decoder.decode(param); int indexOfEqualSign = decodedParam.indexOf("="); if (indexOfEqualSign < 0) { final List<String> parameterList = allQueryParameterMap.containsKey(decodedParam) ? allQueryParameterMap.get(decodedParam) : new LinkedList<String>(); allQueryParameterMap.put(decodedParam, parameterList); parameterList.add(""); } else { final String key = decodedParam.substring(0, indexOfEqualSign); final List<String> parameterList = allQueryParameterMap.containsKey(key) ? allQueryParameterMap.get(key) : new LinkedList<String>(); allQueryParameterMap.put(key, parameterList); parameterList.add(decodedParam.substring(indexOfEqualSign + 1)); } } } return allQueryParameterMap; }
RestUtil { public static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding) { Map<String, List<String>> allQueryParameterMap = new HashMap<String, List<String>>(); if(Boolean.parseBoolean(formEncoding)){ List<String> encoding = new ArrayList<String>(); encoding.add(formEncoding); allQueryParameterMap.put(ACCEPT_FORM_ENCODING, encoding ); } if (queryString != null && queryString.length() > 0) { List<String> queryParameters = Arrays.asList(queryString.split("\\&")); for (String param : queryParameters) { String decodedParam = Decoder.decode(param); int indexOfEqualSign = decodedParam.indexOf("="); if (indexOfEqualSign < 0) { final List<String> parameterList = allQueryParameterMap.containsKey(decodedParam) ? allQueryParameterMap.get(decodedParam) : new LinkedList<String>(); allQueryParameterMap.put(decodedParam, parameterList); parameterList.add(""); } else { final String key = decodedParam.substring(0, indexOfEqualSign); final List<String> parameterList = allQueryParameterMap.containsKey(key) ? allQueryParameterMap.get(key) : new LinkedList<String>(); allQueryParameterMap.put(key, parameterList); parameterList.add(decodedParam.substring(indexOfEqualSign + 1)); } } } return allQueryParameterMap; } }
RestUtil { public static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding) { Map<String, List<String>> allQueryParameterMap = new HashMap<String, List<String>>(); if(Boolean.parseBoolean(formEncoding)){ List<String> encoding = new ArrayList<String>(); encoding.add(formEncoding); allQueryParameterMap.put(ACCEPT_FORM_ENCODING, encoding ); } if (queryString != null && queryString.length() > 0) { List<String> queryParameters = Arrays.asList(queryString.split("\\&")); for (String param : queryParameters) { String decodedParam = Decoder.decode(param); int indexOfEqualSign = decodedParam.indexOf("="); if (indexOfEqualSign < 0) { final List<String> parameterList = allQueryParameterMap.containsKey(decodedParam) ? allQueryParameterMap.get(decodedParam) : new LinkedList<String>(); allQueryParameterMap.put(decodedParam, parameterList); parameterList.add(""); } else { final String key = decodedParam.substring(0, indexOfEqualSign); final List<String> parameterList = allQueryParameterMap.containsKey(key) ? allQueryParameterMap.get(key) : new LinkedList<String>(); allQueryParameterMap.put(key, parameterList); parameterList.add(decodedParam.substring(indexOfEqualSign + 1)); } } } return allQueryParameterMap; }  }
RestUtil { public static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding) { Map<String, List<String>> allQueryParameterMap = new HashMap<String, List<String>>(); if(Boolean.parseBoolean(formEncoding)){ List<String> encoding = new ArrayList<String>(); encoding.add(formEncoding); allQueryParameterMap.put(ACCEPT_FORM_ENCODING, encoding ); } if (queryString != null && queryString.length() > 0) { List<String> queryParameters = Arrays.asList(queryString.split("\\&")); for (String param : queryParameters) { String decodedParam = Decoder.decode(param); int indexOfEqualSign = decodedParam.indexOf("="); if (indexOfEqualSign < 0) { final List<String> parameterList = allQueryParameterMap.containsKey(decodedParam) ? allQueryParameterMap.get(decodedParam) : new LinkedList<String>(); allQueryParameterMap.put(decodedParam, parameterList); parameterList.add(""); } else { final String key = decodedParam.substring(0, indexOfEqualSign); final List<String> parameterList = allQueryParameterMap.containsKey(key) ? allQueryParameterMap.get(key) : new LinkedList<String>(); allQueryParameterMap.put(key, parameterList); parameterList.add(decodedParam.substring(indexOfEqualSign + 1)); } } } return allQueryParameterMap; }  static ContentType extractRequestContentType(final String contentType); static Map<String, String> extractQueryParameters(final String queryString); static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding); static List<Locale> extractAcceptableLanguage(final String acceptableLanguageHeader); static List<String> extractAcceptHeaders(final String acceptHeader); @SuppressWarnings("unchecked") static Map<String, List<String>> extractHeaders(final HttpServletRequest req); static PathInfo buildODataPathInfo(final HttpServletRequest req, final int pathSplit); }
RestUtil { public static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding) { Map<String, List<String>> allQueryParameterMap = new HashMap<String, List<String>>(); if(Boolean.parseBoolean(formEncoding)){ List<String> encoding = new ArrayList<String>(); encoding.add(formEncoding); allQueryParameterMap.put(ACCEPT_FORM_ENCODING, encoding ); } if (queryString != null && queryString.length() > 0) { List<String> queryParameters = Arrays.asList(queryString.split("\\&")); for (String param : queryParameters) { String decodedParam = Decoder.decode(param); int indexOfEqualSign = decodedParam.indexOf("="); if (indexOfEqualSign < 0) { final List<String> parameterList = allQueryParameterMap.containsKey(decodedParam) ? allQueryParameterMap.get(decodedParam) : new LinkedList<String>(); allQueryParameterMap.put(decodedParam, parameterList); parameterList.add(""); } else { final String key = decodedParam.substring(0, indexOfEqualSign); final List<String> parameterList = allQueryParameterMap.containsKey(key) ? allQueryParameterMap.get(key) : new LinkedList<String>(); allQueryParameterMap.put(key, parameterList); parameterList.add(decodedParam.substring(indexOfEqualSign + 1)); } } } return allQueryParameterMap; }  static ContentType extractRequestContentType(final String contentType); static Map<String, String> extractQueryParameters(final String queryString); static Map<String, List<String>> extractAllQueryParameters(final String queryString, String formEncoding); static List<Locale> extractAcceptableLanguage(final String acceptableLanguageHeader); static List<String> extractAcceptHeaders(final String acceptHeader); @SuppressWarnings("unchecked") static Map<String, List<String>> extractHeaders(final HttpServletRequest req); static PathInfo buildODataPathInfo(final HttpServletRequest req, final int pathSplit);  }