예제 #1
0
  private static MultiMap toMultiMap(Map<String, Object> headers) {
    if (headers == null) {
      return null;
    }

    MultiMap multiMap = new CaseInsensitiveMultiMap();

    for (Map.Entry<String, Object> entry : headers.entrySet()) {
      Object o = entry.getValue();
      if (o != null) {
        if (o instanceof List) {
          List<String> entries = new ArrayList<>();
          for (Object v : (List) o) {
            if (v != null) {
              if (v instanceof String) {
                entries.add((String) v);
                continue;
              }
              entries.add(v.toString());
            }
          }
          multiMap.add(entry.getKey(), entries);
          continue;
        }
        if (o instanceof String) {
          multiMap.add(entry.getKey(), (String) o);
          continue;
        }

        multiMap.add(entry.getKey(), o.toString());
      }
    }

    return multiMap;
  }
예제 #2
0
파일: URI.java 프로젝트: GBspace/vertx-test
  public URI(String uri) {
    this.uri = uri;
    if (uri == null) throw new IllegalArgumentException("[" + uri + "] is not a valid HTTP URL");
    Matcher httpUrlMatcher = HTTP_URL_PATTERN.matcher(uri);
    if (httpUrlMatcher.matches()) {

      scheme = httpUrlMatcher.group(1);
      userInfo = httpUrlMatcher.group(4);
      host = httpUrlMatcher.group(5);
      if (!Strings.isNullOrEmpty(httpUrlMatcher.group(7))) {
        port = Integer.parseInt(httpUrlMatcher.group(7));
      } else {
        port = (scheme.equals("http") ? 80 : 443);
      }
      path = httpUrlMatcher.group(8);
      Map<String, List<String>> parameters = new QueryStringDecoder(uri).parameters();
      for (String name : parameters.keySet()) {
        params.add(name, parameters.get(name));
      }
    } else {
      throw new IllegalArgumentException("[" + uri + "] is not a valid HTTP URL");
    }
  }