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
  public Post fetch(Session session, NextRequest next) {
    LOGGER.debug(
        ((next == null) ? "Initial request" : "next request: " + next)
            + "/n Session: "
            + session.toString());
    WebTarget target = createInitialFetchTarget();

    if (next != null) {
      target = fillNextParameters(next, target);
    }

    Invocation.Builder request = target.request();

    request = appendCookies(session, request);

    Response response =
        request.post(
            Entity.entity(
                new NextToken.NextTokenBuilder().createNextToken(),
                MediaType.APPLICATION_JSON_TYPE));

    response.bufferEntity();
    try {
      String responseJson = response.readEntity(String.class);
      LOGGER.debug("Full response: " + responseJson);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    Post post = response.readEntity(Post.class);
    response.close();

    return post;
  }
Exemplo n.º 3
0
 public Response postSequenceFile(
     String url, String recordId, EntryType entryType, String sequence) {
   WebTarget target = client.target("https://" + url).path("/rest/file/sequence");
   Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
   final FormDataMultiPart multiPart = new FormDataMultiPart();
   multiPart.field("file", IOUtils.toInputStream(sequence), MediaType.TEXT_PLAIN_TYPE);
   multiPart.field("entryRecordId", recordId);
   multiPart.field("entryType", entryType.name());
   return invocationBuilder.post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
 }
Exemplo n.º 4
0
  public Response collectMoney(MoneyCollect moneyCollect) {
    Gson gson = new Gson();
    String payload = gson.toJson(moneyCollect);

    WebTarget moneyTarget = appTarget.path("money");
    WebTarget collectMoneyTarget = moneyTarget.path("collect");
    return collectMoneyTarget
        .request()
        .accept(MediaType.APPLICATION_JSON)
        .post(Entity.entity(payload, MediaType.APPLICATION_JSON), Response.class);
  }
Exemplo n.º 5
0
  public Response sendMoney(MoneySend moneySend) {
    Gson gson = new Gson();
    String payload = gson.toJson(moneySend);

    WebTarget moneyTarget = appTarget.path("money");
    WebTarget sendMoneyTarget = moneyTarget.path("send");
    return sendMoneyTarget
        .request()
        .accept(MediaType.APPLICATION_JSON)
        .post(Entity.entity(payload, MediaType.APPLICATION_JSON), Response.class);
  }
Exemplo n.º 6
0
  public Session login(final UserCredential userCredential) {
    WebTarget target =
        client
            .target("http://auth.getprismatic.com")
            .path("auth")
            .path("login")
            .queryParam("api-version", "1.2")
            .queryParam("ignore", "true")
            .queryParam("whitelist_url", "http%3A%2F%2Fgetprismatic.com%2Fnews%2Fhome")
            .queryParam("soon_url", "http%3A%2F%2Fgetprismatic.com%2Fwelcome")
            .queryParam("create_url", "http%3A%2F%2Fgetprismatic.com%2Fcreateaccount")
            .queryParam("resetpassword_url", "http%3A%2F%2Fgetprismatic.com%2Fresetpassword");

    Response response =
        target.request().post(Entity.entity(userCredential, MediaType.APPLICATION_JSON_TYPE));

    checkResponseStatus(response);

    return Session.parseFromHeaders(response.getHeaders().get("Set-Cookie"));
  }
Exemplo n.º 7
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;
  }
Exemplo n.º 8
0
  public <T> T put(String url, String resourcePath, Object object, Class<T> responseClass) {
    WebTarget target = client.target("https://" + url).path(resourcePath);
    Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
    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.º 9
0
 public Response put(String url, String resourcePath, Object object) {
   WebTarget target = client.target("https://" + url).path(resourcePath);
   Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON_TYPE);
   return invocationBuilder.put(Entity.entity(object, MediaType.APPLICATION_JSON_TYPE));
 }