Java Code Examples for com.microsoft.azure.storage.StorageException#getHttpStatusCode()

The following examples show how to use com.microsoft.azure.storage.StorageException#getHttpStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AzureStorageService.java    From crate with Apache License 2.0 7 votes vote down vote up
public void writeBlob(String container, String blobName, InputStream inputStream, long blobSize,
                      boolean failIfAlreadyExists)
    throws URISyntaxException, StorageException, IOException {
    LOGGER.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {})", blobName, blobSize));
    final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
    final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
    final CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobName);
    try {
        final AccessCondition accessCondition =
            failIfAlreadyExists ? AccessCondition.generateIfNotExistsCondition() : AccessCondition.generateEmptyCondition();
        blob.upload(inputStream, blobSize, accessCondition, null, client.v2().get());
    } catch (final StorageException se) {
        if (failIfAlreadyExists && se.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT &&
            StorageErrorCodeStrings.BLOB_ALREADY_EXISTS.equals(se.getErrorCode())) {
            throw new FileAlreadyExistsException(blobName, null, se.getMessage());
        }
        throw se;
    }
    LOGGER.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {}) - done", blobName, blobSize));
}
 
Example 2
Source File: CloudFileDirectory.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the directory if it exists using the specified request options and operation context.
 * 
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the directory.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the directory existed and was deleted; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException 
 */
@DoesServiceRequest
public boolean deleteIfExists(AccessCondition accessCondition, FileRequestOptions options,
        OperationContext opContext) throws StorageException, URISyntaxException {
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);

    boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
    else {
        return false;
    }
}
 
Example 3
Source File: AzureCloudBlobClientActions.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public void cleanupContainer(String baseLocation) {
    String containerName = getContainerName(baseLocation);
    CloudBlobContainer cloudBlobContainer = getCloudBlobContainer(containerName);

    try {
        Log.log(LOGGER, format(" Removing Azure Adls Gen 2 Blob Container with Name: %s at Base Location: %s", containerName, baseLocation));
        cloudBlobContainer.deleteIfExists();
        Log.log(LOGGER, format(" Azure Adls Gen 2 Blob Container: %s delete has been initiated. ", containerName));
    } catch (StorageException e) {
        if (e.getHttpStatusCode() == 404) {
            LOGGER.error("Azure Adls Gen2 Blob Container does not present with name: {} at Base Location: {}", containerName, baseLocation);
            throw new TestFailException("Azure Adls Gen2 Blob Container does not present with name: " +  containerName
                    + " at Base Location: " + baseLocation);
        } else {
            LOGGER.error("Azure Adls Gen2 Blob Container delete cannot be succeed!", e);
            throw new TestFailException("Azure Adls Gen2 Blob Container delete cannot be succeed!" + e);
        }
    } finally {
        createCloudBlobContainer(containerName);
    }
}
 
Example 4
Source File: CloudQueue.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the queue if it exists, using the specified request options and operation context.
 * 
 * @param options
 *            A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudQueueClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return A value of <code>true</code> if the queue existed in the storage service and has been deleted, otherwise
 *         <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred during the operation.
 */
@DoesServiceRequest
public boolean deleteIfExists(QueueRequestOptions options, OperationContext opContext) throws StorageException {
    options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

    boolean exists = this.exists(true, options, opContext);
    if (exists) {
        try {
            this.delete(options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.QUEUE_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }

    }
    else {
        return false;
    }
}
 
Example 5
Source File: CloudQueue.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the queue if it does not already exist, using the specified request options and operation context.
 * 
 * @param options
 *            A {@link QueueRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudQueueClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return A value of <code>true</code> if the queue is created in the storage service, otherwise <code>false</code>
 *         .
 * 
 * @throws StorageException
 *             If a storage service error occurred during the operation.
 */
@DoesServiceRequest
public boolean createIfNotExists(QueueRequestOptions options, OperationContext opContext) throws StorageException {
    options = QueueRequestOptions.populateAndApplyDefaults(options, this.queueServiceClient);

    boolean exists = this.exists(true, options, opContext);
    if (exists) {
        return false;
    }
    else {
        try {
            this.create(options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
                    && StorageErrorCodeStrings.QUEUE_ALREADY_EXISTS.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
}
 
Example 6
Source File: CloudTable.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the table from the storage service using the specified request options and operation context, if it
 * exists.
 *
 * @param options
 *            A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudTableClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 *
 * @return A value of <code>true</code> if the table existed in the storage service and has been deleted, otherwise
 *         <code>false</code>.
 *
 * @throws StorageException
 *             If a storage service error occurred during the operation.
 */
@DoesServiceRequest
public boolean deleteIfExists(TableRequestOptions options, OperationContext opContext) throws StorageException {
    options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient);

    if (this.exists(true, options, opContext)) {
        try {
            this.delete(options, opContext);
        }
        catch (StorageException ex) {
            if (ex.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(ex.getErrorCode())) {
                return false;
            }
            else {
                throw ex;
            }
        }
        return true;
    }
    else {
        return false;
    }
}
 
Example 7
Source File: CloudTable.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the table in the storage service with the specified request options and operation context, if it does not
 * already exist.
 *
 * @param options
 *            A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudTableClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 *
 * @return <code>true</code> if the table did not already exist and was created; otherwise <code>false</code> .
 *
 * @throws StorageException
 *             If a storage service error occurred during the operation.
 */
@DoesServiceRequest
public boolean createIfNotExists(TableRequestOptions options, OperationContext opContext) throws StorageException {
    options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient);

    boolean exists = this.exists(true, options, opContext);
    if (exists) {
        return false;
    }
    else {
        try {
            this.create(options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
                    && StorageErrorCodeStrings.TABLE_ALREADY_EXISTS.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
}
 
Example 8
Source File: CloudFileShare.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the share if it does not exist, using the specified request options and operation context.
 * 
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request.
 *            Specifying <code>null</code> will use the default request options from the associated service client
 *            ({@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the share did not already exist and was created; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public boolean createIfNotExists(FileRequestOptions options, OperationContext opContext) throws StorageException {
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);

    boolean exists = this.exists(true /* primaryOnly */, null /* accessCondition */, options, opContext);
    if (exists) {
        return false;
    }
    else {
        try {
            this.create(options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
                    && StorageErrorCodeStrings.SHARE_ALREADY_EXISTS.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
}
 
Example 9
Source File: AzureBackuper.java    From cassandra-backup with Apache License 2.0 6 votes vote down vote up
@Override
public FreshenResult freshenRemoteObject(final RemoteObjectReference object) throws Exception {
    final CloudBlockBlob blob = ((AzureRemoteObjectReference) object).blob;

    final Instant now = Instant.now();

    try {
        blob.getMetadata().put(DATE_TIME_METADATA_KEY, now.toString());
        blob.uploadMetadata();

        return FreshenResult.FRESHENED;

    } catch (final StorageException e) {
        if (e.getHttpStatusCode() != 404) {
            throw e;
        }

        return FreshenResult.UPLOAD_REQUIRED;
    }
}
 
Example 10
Source File: CloudBlobContainer.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes the container if it exists using the specified request options and operation context.
 * 
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the container.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the container existed and was deleted; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public boolean deleteIfExists(AccessCondition accessCondition, BlobRequestOptions options,
        OperationContext opContext) throws StorageException {
    options = BlobRequestOptions.populateAndApplyDefaults(options, BlobType.UNSPECIFIED, this.blobServiceClient);

    boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.CONTAINER_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
    else {
        return false;
    }
}
 
Example 11
Source File: AzureStorageService.java    From front50 with Apache License 2.0 6 votes vote down vote up
@Override
public <T extends Timestamped> T loadObject(ObjectType objectType, String objectKey) {
  String key = buildKeyPath(objectType.group, objectKey, objectType.defaultMetadataFilename);
  try {
    CloudBlockBlob blob = getBlobContainer().getBlockBlobReference(key);
    if (blob.exists()) {
      return deserialize(blob, (Class<T>) objectType.clazz);
    }
    throw new NotFoundException(
        "Object not found (key: " + objectKey + ", group: " + objectType.group + ")");
  } catch (StorageException se) {
    logStorageException(se, key);
    if (se.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) {
      throw new NotFoundException(
          "Object not found (key: " + objectKey + ", group: " + objectType.group + ")");
    }
    throw new RuntimeException(se);
  } catch (Exception e) {
    throw new IllegalStateException(
        "Unable to fetch object (key: " + objectKey + ", group: " + objectType.group + ")");
  }
}
 
Example 12
Source File: LeaseBlobManager.java    From samza with Apache License 2.0 6 votes vote down vote up
/**
 * Acquires a lease on a blob. The lease ID is NULL initially.
 * @param leaseTimeInSec The time in seconds you want to acquire the lease for.
 * @param leaseId Proposed ID you want to acquire the lease with, null if not proposed.
 * @return String that represents lease ID.  Null if acquireLease is unsuccessful because the blob is leased already.
 * @throws AzureException If a Azure storage service error occurred. This includes the case where the blob you're trying to lease does not exist.
 */
public String acquireLease(int leaseTimeInSec, String leaseId) {
  try {
    String id = leaseBlob.acquireLease(leaseTimeInSec, leaseId);
    LOG.info("Acquired lease with lease id = " + id);
    return id;
  } catch (StorageException storageException) {
    int httpStatusCode = storageException.getHttpStatusCode();
    if (httpStatusCode == HttpStatus.CONFLICT_409) {
      LOG.info("The blob you're trying to acquire is leased already.", storageException.getMessage());
    } else if (httpStatusCode == HttpStatus.NOT_FOUND_404) {
      LOG.error("The blob you're trying to lease does not exist.", storageException);
      throw new AzureException(storageException);
    } else {
      LOG.error("Error acquiring lease!", storageException);
      throw new AzureException(storageException);
    }
  }
  return null;
}
 
Example 13
Source File: CloudFileDirectory.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the directory if it does not exist, using the specified request options and operation context.
 * 
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request.
 *            Specifying <code>null</code> will use the default request options from the associated service client
 *            ({@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the directory did not already exist and was created; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException 
 */
@DoesServiceRequest
public boolean createIfNotExists(FileRequestOptions options, OperationContext opContext) throws StorageException, URISyntaxException {
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);

    this.getShare().assertNoSnapshot();

    boolean exists = this.exists(true /* primaryOnly */, null /* accessCondition */, options, opContext);
    if (exists) {
        return false;
    }
    else {
        try {
            this.create(options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
                    && StorageErrorCodeStrings.RESOURCE_ALREADY_EXISTS.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
}
 
Example 14
Source File: CloudBlob.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the blob if it exists, using the specified snapshot and request options, and operation context.
 * <p>
 * A blob that has snapshots cannot be deleted unless the snapshots are also deleted. If a blob has snapshots, use
 * the {@link DeleteSnapshotsOption#DELETE_SNAPSHOTS_ONLY} or {@link DeleteSnapshotsOption#INCLUDE_SNAPSHOTS} value
 * in the <code>deleteSnapshotsOption</code> parameter to specify how the snapshots should be handled when the blob
 * is deleted.
 *
 * @param deleteSnapshotsOption
 *            A {@link DeleteSnapshotsOption} object that indicates whether to delete only snapshots, or the blob
 *            and its snapshots.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 *
 * @return <code>true</code> if the blob existed and was deleted; otherwise, <code>false</code>
 *
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public final boolean deleteIfExists(final DeleteSnapshotsOption deleteSnapshotsOption,
        final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext)
        throws StorageException {
    options = BlobRequestOptions.populateAndApplyDefaults(options, this.properties.getBlobType(), this.blobServiceClient);

    boolean exists = this.exists(true, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(deleteSnapshotsOption, accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.BLOB_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }

    }
    else {
        return false;
    }
}
 
Example 15
Source File: CloudFile.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the file if it exists, using the specified access condition, request options, and operation context.
 * 
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the file.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the file existed and was deleted; otherwise, <code>false</code>
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException 
 */
@DoesServiceRequest
public final boolean deleteIfExists(final AccessCondition accessCondition, FileRequestOptions options,
        OperationContext opContext) throws StorageException, URISyntaxException {
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
    this.getShare().assertNoSnapshot();

    boolean exists = this.exists(true, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }

    }
    else {
        return false;
    }
}
 
Example 16
Source File: CloudBlobContainer.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the container if it does not exist, using the specified request options and operation context.
 * 
 * @param accessType
 *            A {@link BlobContainerPublicAccessType} object that specifies whether data in the container may be
 *            accessed publicly and what level of access is to be allowed.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request.
 *            Specifying <code>null</code> will use the default request options from the associated service client
 *            ({@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the container did not already exist and was created; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public boolean createIfNotExists(BlobContainerPublicAccessType accessType, BlobRequestOptions options, OperationContext opContext) throws StorageException {
    if (accessType == BlobContainerPublicAccessType.UNKNOWN) {
        throw new IllegalArgumentException(String.format(Utility.LOCALE_US, SR.ARGUMENT_OUT_OF_RANGE_ERROR, "accessType", accessType));
    }

    options = BlobRequestOptions.populateAndApplyDefaults(options, BlobType.UNSPECIFIED, this.blobServiceClient);

    boolean exists = this.exists(true /* primaryOnly */, null /* accessCondition */, options, opContext);
    if (exists) {
        return false;
    }
    else {
        try {
            this.create(accessType, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT
                    && StorageErrorCodeStrings.CONTAINER_ALREADY_EXISTS.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
}
 
Example 17
Source File: AzureExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BackgroundException map(final StorageException failure) {
    final StringBuilder buffer = new StringBuilder();
    this.append(buffer, failure.getMessage());
    if(ExceptionUtils.getRootCause(failure) instanceof UnknownHostException) {
        return new NotfoundException(buffer.toString(), failure);
    }
    switch(failure.getHttpStatusCode()) {
        case 403:
            return new LoginFailureException(buffer.toString(), failure);
        case 404:
            return new NotfoundException(buffer.toString(), failure);
        case 304:
        case 405:
        case 400:
        case 411:
        case 412:
            return new InteroperabilityException(buffer.toString(), failure);
        case 500:
            // InternalError
            // OperationTimedOut
            return new ConnectionTimeoutException(buffer.toString(), failure);
        case 503:
            // ServerBusy
            return new RetriableAccessDeniedException(buffer.toString(), failure);
    }
    for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if(cause instanceof SSLException) {
            return new SSLExceptionMappingService().map(buffer.toString(), (SSLException) cause);
        }
    }
    return this.wrap(failure, buffer);
}
 
Example 18
Source File: CloudFileShare.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Deletes the share if it exists, using the specified snapshot and request options, and operation context.
 * <p>
 * A share that has snapshots cannot be deleted unless the snapshots are also deleted. If a share has snapshots, use
 * the {@link DeleteShareSnapshotsOption#INCLUDE_SNAPSHOTS} value
 * in the <code>deleteSnapshotsOption</code> parameter to include the snapshots when deleting the base share.
 *
 * @param deleteSnapshotsOption
 *            A {@link DeleteShareSnapshotsOption} object that indicates whether to delete only snapshots, or the share
 *            and its snapshots.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the share.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the share existed and was deleted; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public boolean deleteIfExists(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options,
        OperationContext opContext) throws StorageException {
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);

    boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(deleteSnapshotsOption, accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.SHARE_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
    else {
        return false;
    }
}
 
Example 19
Source File: AzureConfigProvider.java    From exhibitor with Apache License 2.0 4 votes vote down vote up
private boolean isNotFoundError(StorageException e) {
    return (e.getHttpStatusCode() == HTTP_NOT_FOUND);
}
 
Example 20
Source File: AzureConfigProvider.java    From exhibitor with Apache License 2.0 4 votes vote down vote up
private boolean isForbiddenError(StorageException e) {
    return ((e.getHttpStatusCode() == HTTP_FORBIDDEN));
}