/** * Creates an instance of the <code>CloudQueue</code> class using the specified name and client. * * @param queueName * The name of the queue, which must adhere to queue naming rules. The queue name should not include any * path separator characters (/). * Queue names must be lowercase, between 3-63 characters long and must start with a letter or number. * Queue names may contain only letters, numbers, and the dash (-) character. * @param client * A {@link CloudQueueClient} object that represents the associated service client, and that specifies * the endpoint for the Queue service. * @throws URISyntaxException * If the resource URI constructed based on the queueName is invalid. * @throws StorageException * If a storage service error occurred. * @see <a href="http://msdn.microsoft.com/en-us/library/azure/dd179349.aspx">Naming Queues and Metadata</a> */ protected CloudQueue(final String queueName, final CloudQueueClient client) throws URISyntaxException, StorageException { Utility.assertNotNull("client", client); Utility.assertNotNull("queueName", queueName); this.storageUri = PathUtility.appendPathToUri(client.getStorageUri(), queueName); this.name = queueName; this.queueServiceClient = client; this.shouldEncodeMessage = true; }
/** * Creates an instance of the <code>CloudQueue</code> class using the specified name and client. * * @param queueName * The name of the queue, which must adhere to queue naming rules. The queue name should not include any * path separator characters (/). * Queue names must be lowercase, between 3-63 characters long and must start with a letter or number. * Queue names may contain only letters, numbers, and the dash (-) character. * @param client * A {@link CloudQueueClient} object that represents the associated service client, and that specifies * the endpoint for the Queue service. * @throws URISyntaxException * If the resource URI constructed based on the queueName is invalid. * @throws StorageException * If a storage service error occurred. * @see <a href="http://msdn.microsoft.com/en-us/library/azure/dd179349.aspx">Naming Queues and Metadata</a> */ protected CloudQueue(final String queueName, final CloudQueueClient client) throws URISyntaxException, StorageException { Utility.assertNotNull("client", client); Utility.assertNotNull("queueName", queueName); this.storageUri = PathUtility.appendPathToUri(client.getStorageUri(), queueName); this.name = queueName; this.queueServiceClient = client; this.shouldEncodeMessage = true; }
final ListingContext listingContext = new ListingContext(prefix, maxResults); final StorageRequest<CloudQueueClient, Void, ResultSegment<CloudQueue>> getRequest = new StorageRequest<CloudQueueClient, Void, ResultSegment<CloudQueue>>( options, this.getStorageUri()) {
final ListingContext listingContext = new ListingContext(prefix, maxResults); final StorageRequest<CloudQueueClient, Void, ResultSegment<CloudQueue>> getRequest = new StorageRequest<CloudQueueClient, Void, ResultSegment<CloudQueue>>( options, this.getStorageUri()) {
@Override public HttpURLConnection buildRequest(CloudQueueClient client, Void parentObject, OperationContext context) throws Exception { listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken() .getNextMarker() : null); return QueueRequest.list( credentials.transformUri(client.getStorageUri().getUri(this.getCurrentLocation())), options, context, listingContext, detailsIncluded); }
@Override public HttpURLConnection buildRequest(CloudQueueClient client, Void parentObject, OperationContext context) throws Exception { listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken() .getNextMarker() : null); return QueueRequest.list( credentials.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 public void testQueueTypesWithStorageUri() throws URISyntaxException, StorageException { CloudQueueClient queueClient = TestHelper.createCloudQueueClient(); StorageUri endpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + QUEUE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + QUEUE_SERVICE + ENDPOINT_SUFFIX)); CloudQueueClient client = new CloudQueueClient(endpoint, queueClient.getCredentials()); assertEquals(endpoint, client.getStorageUri()); assertEquals(endpoint.getPrimaryUri(), client.getEndpoint()); StorageUri queueUri = new StorageUri(new URI(endpoint.getPrimaryUri() + "/queue"), new URI( endpoint.getSecondaryUri() + "/queue")); CloudQueue queue = client.getQueueReference("queue"); assertEquals(queueUri, queue.getStorageUri()); assertEquals(queueUri.getPrimaryUri(), queue.getUri()); assertEquals(endpoint, queue.getServiceClient().getStorageUri()); queue = new CloudQueue(queueUri, client.getCredentials()); assertEquals(queueUri, queue.getStorageUri()); assertEquals(queueUri.getPrimaryUri(), queue.getUri()); assertEquals(endpoint, queue.getServiceClient().getStorageUri()); }
private static void testQueueDownloadAttributes(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudQueueClient client = TestHelper.createCloudQueueClient(); CloudQueue queue = client.getQueueReference(QueueTestHelper.generateRandomQueueName()); MultiLocationTestHelper helper = new MultiLocationTestHelper(queue.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); queue.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); QueueRequestOptions options = new QueueRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { queue.downloadAttributes(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()); }