protected StorageRequest<ServiceClient, Void, AccountInformation> downloadAccountInformationImpl( final RequestOptions options) { final StorageRequest<ServiceClient, Void, AccountInformation> headRequest = new StorageRequest<ServiceClient, Void, AccountInformation>( options, this.getStorageUri()) { @Override public void setRequestLocationMode() { this.setRequestLocationMode(RequestLocationMode.PRIMARY_OR_SECONDARY); } @Override public HttpURLConnection buildRequest(ServiceClient client, Void parentObject, OperationContext context) throws Exception { return BaseRequest.getAccountInfo(credentials.transformUri(client.getStorageUri().getUri(this.getCurrentLocation())), options, null, context); } @Override public void signRequest(HttpURLConnection connection, ServiceClient client, OperationContext context) throws Exception { StorageRequest.signBlobQueueAndFileRequest(connection, client, -1, context); } @Override public AccountInformation preProcessResponse(Void parentObject, ServiceClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); } return BlobResponse.getAccountInformation(this.getConnection()); } }; return headRequest; }
/** * Creates an instance of the <code>CloudBlobContainer</code> class using the specified name and client. * * @param containerName * A <code>String</code> which represents the name of the container, which must adhere to container * naming rules. * The container name should not include any path separator characters (/). * Container names must be lowercase, between 3-63 characters long and must start with a letter or * number. Container names may contain only letters, numbers, and the dash (-) character. * @param client * A {@link CloudBlobClient} object that represents the associated service client, and that specifies the * endpoint for the Blob service. * * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI constructed based on the containerName is invalid. * * @see <a href="http://msdn.microsoft.com/library/azure/dd135715.aspx">Naming and Referencing Containers, Blobs, * and Metadata</a> */ protected CloudBlobContainer(final String containerName, final CloudBlobClient client) throws URISyntaxException, StorageException { Utility.assertNotNull("client", client); Utility.assertNotNull("containerName", containerName); this.storageUri = PathUtility.appendPathToUri(client.getStorageUri(), containerName); this.name = containerName; this.blobServiceClient = client; }
/** * Creates an instance of the <code>CloudBlobContainer</code> class using the specified name and client. * * @param containerName * A <code>String</code> which represents the name of the container, which must adhere to container * naming rules. * The container name should not include any path separator characters (/). * Container names must be lowercase, between 3-63 characters long and must start with a letter or * number. Container names may contain only letters, numbers, and the dash (-) character. * @param client * A {@link CloudBlobClient} object that represents the associated service client, and that specifies the * endpoint for the Blob service. * * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI constructed based on the containerName is invalid. * * @see <a href="http://msdn.microsoft.com/library/azure/dd135715.aspx">Naming and Referencing Containers, Blobs, * and Metadata</a> */ protected CloudBlobContainer(final String containerName, final CloudBlobClient client) throws URISyntaxException, StorageException { Utility.assertNotNull("client", client); Utility.assertNotNull("containerName", containerName); this.storageUri = PathUtility.appendPathToUri(client.getStorageUri(), containerName); this.name = containerName; this.blobServiceClient = client; }
options, this.getStorageUri()) {
options, this.getStorageUri()) {
@Override public HttpURLConnection buildRequest(CloudBlobClient client, Void parentObject, OperationContext context) throws Exception { listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken() .getNextMarker() : null); return BlobRequest.listContainers( client.getCredentials().transformUri(client.getStorageUri()).getUri(this.getCurrentLocation()), options, context, listingContext, detailsIncluded); }
@Override public HttpURLConnection buildRequest(CloudBlobClient client, Void parentObject, OperationContext context) throws Exception { listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken() .getNextMarker() : null); return BlobRequest.listContainers( client.getCredentials().transformUri(client.getStorageUri()).getUri(this.getCurrentLocation()), options, context, listingContext, detailsIncluded); }
@Test public void testCloudStorageAccountWithStorageUri() throws URISyntaxException, InvalidKeyException { StorageUri blobEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + BLOB_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + BLOB_SERVICE + ENDPOINT_SUFFIX)); StorageUri queueEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + QUEUE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + QUEUE_SERVICE + ENDPOINT_SUFFIX)); StorageUri tableEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + TABLE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + TABLE_SERVICE + ENDPOINT_SUFFIX)); CloudStorageAccount account = CloudStorageAccount.parse(String.format( "DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=dummyKey", ACCOUNT_NAME)); assertEquals(blobEndpoint, account.getBlobStorageUri()); assertEquals(queueEndpoint, account.getQueueStorageUri()); assertEquals(tableEndpoint, account.getTableStorageUri()); assertEquals(blobEndpoint, account.createCloudBlobClient().getStorageUri()); assertEquals(queueEndpoint, account.createCloudQueueClient().getStorageUri()); assertEquals(tableEndpoint, account.createCloudTableClient().getStorageUri()); assertEquals(blobEndpoint.getPrimaryUri(), account.getBlobEndpoint()); assertEquals(queueEndpoint.getPrimaryUri(), account.getQueueEndpoint()); assertEquals(tableEndpoint.getPrimaryUri(), account.getTableEndpoint()); }
@Test @Category(SlowTests.class) public void testBlobSaS() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { SharedAccessBlobPolicy sp = createSharedAccessPolicy( EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST), 3600); BlobContainerPermissions perms = new BlobContainerPermissions(); perms.getSharedAccessPolicies().put("readperm", sp); this.container.uploadPermissions(perms); Thread.sleep(30000); CloudBlockBlob sasBlob = new CloudBlockBlob(new URI(this.blob.getUri().toString() + "?" + this.blob.generateSharedAccessSignature(null, "readperm"))); sasBlob.download(new ByteArrayOutputStream()); // do not give the client and check that the new blob's client has the correct perms CloudBlob blobFromUri = new CloudBlockBlob(PathUtility.addToQuery(this.blob.getStorageUri(), this.blob.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), blobFromUri.getServiceClient() .getCredentials().getClass().toString()); // create credentials from sas StorageCredentials creds = new StorageCredentialsSharedAccessSignature( this.blob.generateSharedAccessSignature(null, "readperm")); CloudBlobClient bClient = new CloudBlobClient(sasBlob.getServiceClient().getStorageUri(), creds); CloudBlockBlob blobFromClient = bClient.getContainerReference(this.blob.getContainer().getName()) .getBlockBlobReference(this.blob.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), blobFromClient.getServiceClient() .getCredentials().getClass().toString()); assertEquals(bClient, blobFromClient.getServiceClient()); }
CloudBlobClient bClient = new CloudBlobClient(this.container.getServiceClient().getStorageUri(), creds);
assertEquals(endpoint, client.getStorageUri()); assertEquals(endpoint.getPrimaryUri(), client.getEndpoint()); assertEquals(containerUri, container.getStorageUri()); assertEquals(containerUri.getPrimaryUri(), container.getUri()); assertEquals(endpoint, container.getServiceClient().getStorageUri()); assertEquals(endpoint, container.getServiceClient().getStorageUri()); assertEquals("", directory.getParent().getPrefix()); assertEquals(containerUri, directory.getContainer().getStorageUri()); assertEquals(endpoint, directory.getServiceClient().getStorageUri()); assertEquals(directoryUri, subdirectory.getParent().getStorageUri()); assertEquals(containerUri, subdirectory.getContainer().getStorageUri()); assertEquals(endpoint, subdirectory.getServiceClient().getStorageUri()); assertEquals(subdirectoryUri, blockBlob.getParent().getStorageUri()); assertEquals(containerUri, blockBlob.getContainer().getStorageUri()); assertEquals(endpoint, blockBlob.getServiceClient().getStorageUri()); assertEquals(subdirectoryUri, blockBlob.getParent().getStorageUri()); assertEquals(containerUri, blockBlob.getContainer().getStorageUri()); assertEquals(endpoint, blockBlob.getServiceClient().getStorageUri()); assertEquals(subdirectoryUri, pageBlob.getParent().getStorageUri()); assertEquals(containerUri, pageBlob.getContainer().getStorageUri()); assertEquals(endpoint, pageBlob.getServiceClient().getStorageUri());
private static void testContainerDownloadAttributes(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudBlobContainer container = BlobTestHelper.getRandomContainerReference(); MultiLocationTestHelper helper = new MultiLocationTestHelper(container.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); container.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); BlobRequestOptions options = new BlobRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { container.downloadAttributes(null, options, helper.operationContext); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } finally { helper.close(); } }
@Test public void testCloudStorageAccountClientMethods() throws URISyntaxException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount account = new CloudStorageAccount(cred, false); CloudBlobClient blob = account.createCloudBlobClient(); CloudQueueClient queue = account.createCloudQueueClient(); CloudTableClient table = account.createCloudTableClient(); CloudFileClient file = account.createCloudFileClient(); // check endpoints assertEquals("Blob endpoint doesn't match account", account.getBlobEndpoint(), blob.getEndpoint()); assertEquals("Queue endpoint doesn't match account", account.getQueueEndpoint(), queue.getEndpoint()); assertEquals("Table endpoint doesn't match account", account.getTableEndpoint(), table.getEndpoint()); assertEquals("File endpoint doesn't match account", account.getFileEndpoint(), file.getEndpoint()); // check storage uris assertEquals("Blob endpoint doesn't match account", account.getBlobStorageUri(), blob.getStorageUri()); assertEquals("Queue endpoint doesn't match account", account.getQueueStorageUri(), queue.getStorageUri()); assertEquals("Table endpoint doesn't match account", account.getTableStorageUri(), table.getStorageUri()); assertEquals("File endpoint doesn't match account", account.getFileStorageUri(), file.getStorageUri()); // check creds assertEquals("Blob creds don't match account", account.getCredentials(), blob.getCredentials()); assertEquals("Queue creds don't match account", account.getCredentials(), queue.getCredentials()); assertEquals("Table creds don't match account", account.getCredentials(), table.getCredentials()); assertEquals("File creds don't match account", account.getCredentials(), file.getCredentials()); }