Esempio n. 1
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;
  }
Esempio n. 2
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"));
  }
Esempio n. 3
0
 private Invocation.Builder appendCookies(Session session, Invocation.Builder request) {
   for (Cookie cookie : session.getCookies()) {
     request = request.cookie(cookie);
   }
   return request;
 }