Exemplo n.º 1
0
  public <T> T putWor(
      String url,
      String resourcePath,
      Object object,
      Class<T> responseClass,
      Map<String, Object> queryParams,
      String worToken) {
    WebTarget target = client.target("https://" + url).path(resourcePath);
    if (queryParams != null) {
      for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
        target = target.queryParam(entry.getKey(), entry.getValue());
      }
    }

    Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    setHeaders(invocationBuilder, worToken);
    Response putResponse =
        invocationBuilder.put(Entity.entity(object, MediaType.APPLICATION_JSON_TYPE));
    if (putResponse.getStatus() != Response.Status.OK.getStatusCode()) {
      Logger.error(
          "PUT call to "
              + url
              + "/"
              + resourcePath
              + " returned status of "
              + putResponse.getStatus());
      return null;
    }

    if (responseClass != null
        && putResponse.hasEntity()
        && putResponse.getStatus() == Response.Status.OK.getStatusCode())
      return putResponse.readEntity(responseClass);
    return null;
  }
Exemplo n.º 2
0
 private WebTarget fillNextParameters(NextRequest next, WebTarget target) {
   target =
       target
           .queryParam("first-article-idx", next.getQueryParams().getFirstArticleIdx())
           .queryParam("last-article-idx", next.getQueryParams().getLastArticleIdx())
           .queryParam("last-feed-id", next.getQueryParams().getLastFeedID())
           .queryParam("subpage", next.getQueryParams().isSubpage());
   return target;
 }
Exemplo n.º 3
0
 @Override
 public <T> T get(String url, String path, Class<T> clazz, Map<String, Object> queryParams) {
   WebTarget target = client.target("https://" + url).path(path);
   if (queryParams != null) {
     for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
       target = target.queryParam(entry.getKey(), entry.getValue());
     }
   }
   return target.request(MediaType.APPLICATION_JSON_TYPE).buildGet().invoke(clazz);
 }
Exemplo n.º 4
0
 // WOR
 public <T> T getWor(
     String url, String path, Class<T> clazz, Map<String, Object> queryParams, String token) {
   WebTarget target = client.target("https://" + url).path(path);
   if (queryParams != null) {
     for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
       target = target.queryParam(entry.getKey(), entry.getValue());
     }
   }
   Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
   setHeaders(invocationBuilder, token);
   return invocationBuilder.buildGet().invoke(clazz);
 }
Exemplo n.º 5
0
  @Override
  public <T> T post(
      String url,
      String resourcePath,
      Object object,
      Class<T> responseClass,
      Map<String, Object> queryParams) {
    WebTarget target = client.target("https://" + url).path(resourcePath);
    if (queryParams != null) {
      for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
        target = target.queryParam(entry.getKey(), entry.getValue());
      }
    }

    Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    Response postResponse =
        invocationBuilder.post(Entity.entity(object, MediaType.APPLICATION_JSON_TYPE));
    if (postResponse.hasEntity() && postResponse.getStatus() == Response.Status.OK.getStatusCode())
      return postResponse.readEntity(responseClass);
    return null;
  }