Ejemplo n.º 1
0
  public String getAdminToken() {

    String adminToken =
        curAdminToken != null && curAdminToken.isValid() ? curAdminToken.getToken() : null;

    if (adminToken == null) {
      final ServiceClientResponse<AuthenticateResponse> serviceResponse =
          client.post(authUrl + "/tokens", requestBody, MediaType.APPLICATION_XML_TYPE);

      switch (HttpStatusCode.fromInt(serviceResponse.getStatusCode())) {
        case OK:
          final AuthenticateResponse authenticateResponse =
              marshaller.unmarshall(serviceResponse.getData(), AuthenticateResponse.class);

          Token token = authenticateResponse.getToken();
          curAdminToken = new AdminToken(token.getId(), token.getExpires().toGregorianCalendar());
          adminToken = curAdminToken.getToken();
          break;

        default:
          LOG.error(
              "Unable to get admin token.  Verify admin credentials. "
                  + serviceResponse.getStatusCode());
          curAdminToken = null;
          break;
      }
    }

    return adminToken;
  }
Ejemplo n.º 2
0
  @Override
  public Object handleResponse(ServiceClientResponse response)
      throws IOException, DatastoreOperationException {
    if (response.getStatusCode() != HttpStatusCode.ACCEPTED.intValue()) {
      throw new DatastoreOperationException(
          "Remote request failed with: " + response.getStatusCode());
    }

    return Boolean.TRUE;
  }