Exemplo n.º 1
0
 /**
  * Adds parameters from the passed on request body.
  *
  * @param body request body
  * @param params map parameters
  */
 private static void addParams(final String body, final Map<String, String[]> params) {
   for (final String nv : body.split("&")) {
     final String[] parts = nv.split("=", 2);
     if (parts.length < 2) continue;
     try {
       params.put(parts[0], new String[] {URLDecoder.decode(parts[1], Token.UTF8)});
     } catch (final Exception ex) {
       Util.notexpected(ex);
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Decodes the specified path segments.
  *
  * @param segments strings to be decoded
  * @return argument
  * @throws IllegalArgumentException invalid path segments
  */
 public static String[] decode(final String[] segments) {
   try {
     final int sl = segments.length;
     for (int s = 0; s < sl; s++) {
       segments[s] = URLDecoder.decode(segments[s], Prop.ENCODING);
     }
     return segments;
   } catch (final UnsupportedEncodingException ex) {
     throw new IllegalArgumentException(ex);
   }
 }
Exemplo n.º 3
0
 /**
  * Parse the query string.
  *
  * @param map parsed key-values will be stored here
  * @param qs query string
  */
 private static void parseQueryString(final Map<String, String> map, final String qs) {
   if (qs == null) return;
   for (final String nv : qs.split("&")) {
     final String[] parts = nv.split("=");
     final String key = parts[0];
     String val = null;
     if (parts.length > 1) {
       val = parts[1];
       if (val != null) {
         try {
           val = URLDecoder.decode(val, Token.UTF8);
         } catch (final UnsupportedEncodingException ex) {
           throw new RuntimeException(ex);
         }
       }
     }
     map.put(key, val);
   }
 }