Ejemplo n.º 1
0
 private static Request.Builder request(final int port, final String... segments) {
   HttpUrl.Builder url = new HttpUrl.Builder().scheme("http").host("localhost").port(port);
   if (segments != null) {
     for (final String segment : segments) {
       url.addPathSegment(segment);
     }
   }
   return new Request.Builder().url(url.build());
 }
Ejemplo n.º 2
0
  private URL buildRequestURL(
      String baseUrl, String docId, String index, String type, String fields)
      throws MalformedURLException {
    if (StringUtils.isEmpty(baseUrl)) {
      throw new MalformedURLException("Base URL cannot be null");
    }
    HttpUrl.Builder builder = HttpUrl.parse(baseUrl).newBuilder();
    builder.addPathSegment(index);
    builder.addPathSegment((StringUtils.isEmpty(type)) ? "_all" : type);
    builder.addPathSegment(docId);
    if (!StringUtils.isEmpty(fields)) {
      String trimmedFields =
          Stream.of(fields.split(",")).map(String::trim).collect(Collectors.joining(","));
      builder.addQueryParameter(FIELD_INCLUDE_QUERY_PARAM, trimmedFields);
    }

    return builder.build().url();
  }