Esempio n. 1
0
 /** Helper method to set password for the first HTTP basic authentication. */
 public void setPassword(String password) {
   if (authentication != null) {
     authentication.setPassword(password);
   }
 }
Esempio n. 2
0
  private Response getAPIResponse(
      String path,
      String method,
      List<Pair> queryParams,
      Object body,
      byte[] binaryBody,
      Map<String, String> headerParams,
      Map<String, Object> formParams,
      String accept,
      String contentType,
      String[] authNames)
      throws ApiException {

    if (body != null && binaryBody != null) {
      throw new ApiException(500, "either body or binaryBody must be null");
    }

    Client client = getClient();
    Response response = null;

    StringBuilder b = new StringBuilder();
    b.append("?");
    if (queryParams != null) {
      for (Pair queryParam : queryParams) {
        if (!queryParam.getName().isEmpty()) {
          b.append(escapeString(queryParam.getName()));
          b.append("=");
          b.append(escapeString(queryParam.getValue()));
          b.append("&");
        }
      }
    }

    String querystring = b.substring(0, b.length() - 1);

    WebTarget target = client.target(basePath + path + querystring);

    if (debugging) {
      target.register(new LoggingFilter());
    }

    if (authentication != null) {
      authentication.setFilter(target);
    }

    Invocation.Builder builder;
    if (accept != null) {
      builder = target.request(accept);
    } else {
      builder = target.request();
    }

    for (Map.Entry<String, String> entry : headerParams.entrySet()) {
      builder = builder.header(entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, String> entry : defaultHeaderMap.entrySet()) {
      if (!headerParams.containsKey(entry.getKey())) {
        builder = builder.header(entry.getKey(), entry.getValue());
      }
    }

    if ("GET".equals(method)) {
      response = builder.get();
    } else if ("POST".equals(method)) {
      response = builder.post(Entity.entity(body, contentType));
    } else if ("PUT".equals(method)) {
      if (body != null) {
        response = builder.put(Entity.entity(body, contentType));
      } else {
        response = builder.put(Entity.text(""));
      }
    } else if ("DELETE".equals(method)) {
      response = builder.delete();
    } else {
      throw new ApiException(500, "unknown method type " + method);
    }

    return response;
  }
Esempio n. 3
0
 /** Helper method to set username for the first HTTP basic authentication. */
 public void setUsername(String username) {
   if (authentication != null) {
     authentication.setUsername(username);
   }
 }