Пример #1
0
 private MultiValueMap<String, String> readFormParameters(MediaType bodyType, byte[] bodyBytes) {
   if (bodyType != null && bodyType.equals(MediaType.APPLICATION_FORM_URLENCODED)) {
     String body;
     try {
       body = new String(bodyBytes, UTF8_CHARSET_NAME);
     } catch (UnsupportedEncodingException shouldntHappen) {
       throw new IllegalStateException(shouldntHappen);
     }
     return parseFormParameters(body);
   } else {
     return EmptyMultiValueMap.instance();
   }
 }
Пример #2
0
 private MultiValueMap<String, String> parseFormParameters(String parameterString) {
   if (parameterString == null || parameterString.length() == 0) {
     return EmptyMultiValueMap.instance();
   }
   String[] pairs = StringUtils.tokenizeToStringArray(parameterString, "&");
   MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(pairs.length);
   for (String pair : pairs) {
     int idx = pair.indexOf('=');
     if (idx == -1) {
       result.add(formDecode(pair), "");
     } else {
       String name = formDecode(pair.substring(0, idx));
       String value = formDecode(pair.substring(idx + 1));
       result.add(name, value);
     }
   }
   return result;
 }