Exemplo n.º 1
0
  @Override
  public State retrieveState(String id, String activityId, Agent agent, UUID registration)
      throws Exception {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("stateId", id);
    params.put("activityId", activityId);
    params.put("agent", agent.toJSON(this.getVersion(), this.usePrettyJSON()));
    if (registration != null) {
      params.put("registration", registration.toString());
    }

    String queryString = "?";
    Boolean first = true;
    for (Map.Entry<String, String> parameter : params.entrySet()) {
      queryString +=
          (first ? "" : "&")
              + URLEncoder.encode(parameter.getKey(), "UTF-8")
              + "="
              + URLEncoder.encode(parameter.getValue(), "UTF-8").replace("+", "%20");
      first = false;
    }

    HTTPRequest request = new HTTPRequest();
    request.setURL(this.getEndpoint() + "activities/state" + queryString);

    HTTPResponse response = this.sendRequest(request);
    int status = response.getStatus();

    if (status == 200) {
      return new State(id, response.getContentBytes(), activityId, agent, registration);
    } else if (status == 404) {
      return null;
    }
    throw new UnexpectedHTTPResponse(response);
  }
Exemplo n.º 2
0
  private LRSResponse getDocument(
      String resource, Map<String, String> queryParams, Document document) {
    HTTPRequest request = new HTTPRequest();
    request.setMethod(HttpMethods.GET);
    request.setResource(resource);
    request.setQueryParams(queryParams);

    HTTPResponse response = makeSyncRequest(request);

    LRSResponse lrsResponse = new LRSResponse(request, response);

    if (response.getStatus() == 200) {
      document.setContent(response.getContentBytes());
      document.setContentType(response.getContentType());
      document.setTimestamp(response.getLastModified());
      document.setEtag(response.getEtag());
      lrsResponse.setSuccess(true);
    } else if (response.getStatus() == 404) {
      lrsResponse.setSuccess(true);
    } else {
      lrsResponse.setSuccess(false);
    }

    return lrsResponse;
  }