예제 #1
0
  /** Asynchronously wipe collection on server. */
  protected void wipeServer(
      final CredentialsSource credentials, final WipeServerDelegate wipeDelegate) {
    SyncStorageRequest request;

    try {
      request = new SyncStorageRequest(session.config.collectionURI(getCollection()));
    } catch (URISyntaxException ex) {
      Logger.warn(LOG_TAG, "Invalid URI in wipeServer.");
      wipeDelegate.onWipeFailed(ex);
      return;
    }

    request.delegate =
        new SyncStorageRequestDelegate() {

          @Override
          public String ifUnmodifiedSince() {
            return null;
          }

          @Override
          public void handleRequestSuccess(SyncStorageResponse response) {
            BaseResource.consumeEntity(response);
            resetLocal();
            wipeDelegate.onWiped(response.normalizedWeaveTimestamp());
          }

          @Override
          public void handleRequestFailure(SyncStorageResponse response) {
            Logger.warn(
                LOG_TAG, "Got request failure " + response.getStatusCode() + " in wipeServer.");
            // Process HTTP failures here to pick up backoffs, etc.
            session.interpretHTTPFailure(response.httpResponse());
            BaseResource.consumeEntity(
                response); // The exception thrown should not need the body of the response.
            wipeDelegate.onWipeFailed(new HTTPFailureException(response));
          }

          @Override
          public void handleRequestError(Exception ex) {
            Logger.warn(LOG_TAG, "Got exception in wipeServer.", ex);
            wipeDelegate.onWipeFailed(ex);
          }

          @Override
          public String credentials() {
            return credentials.credentials();
          }
        };

    request.delete();
  }
예제 #2
0
  protected void wipeServer(
      final AuthHeaderProvider authHeaderProvider, final WipeServerDelegate wipeDelegate) {
    SyncStorageRequest request;
    final GlobalSession self = this;

    try {
      request = new SyncStorageRequest(config.storageURL());
    } catch (URISyntaxException ex) {
      Logger.warn(LOG_TAG, "Invalid URI in wipeServer.");
      wipeDelegate.onWipeFailed(ex);
      return;
    }

    request.delegate =
        new SyncStorageRequestDelegate() {

          @Override
          public String ifUnmodifiedSince() {
            return null;
          }

          @Override
          public void handleRequestSuccess(SyncStorageResponse response) {
            BaseResource.consumeEntity(response);
            wipeDelegate.onWiped(response.normalizedWeaveTimestamp());
          }

          @Override
          public void handleRequestFailure(SyncStorageResponse response) {
            Logger.warn(
                LOG_TAG, "Got request failure " + response.getStatusCode() + " in wipeServer.");
            // Process HTTP failures here to pick up backoffs, etc.
            self.interpretHTTPFailure(response.httpResponse());
            BaseResource.consumeEntity(
                response); // The exception thrown should not need the body of the response.
            wipeDelegate.onWipeFailed(new HTTPFailureException(response));
          }

          @Override
          public void handleRequestError(Exception ex) {
            Logger.warn(LOG_TAG, "Got exception in wipeServer.", ex);
            wipeDelegate.onWipeFailed(ex);
          }

          @Override
          public AuthHeaderProvider getAuthHeaderProvider() {
            return GlobalSession.this.getAuthHeaderProvider();
          }
        };
    request.delete();
  }