.length(properties.getLength()); if (uri.getSecondaryUri() != null) { builder.secondaryUri(uri.getSecondaryUri().toString());
/** * Get the service client address from a complete Uri. * * @param addressUri * Complete address of the resource. * @param usePathStyleUris * a value indicating if the address is a path style uri. * @return the service client address from a complete Uri. * @throws URISyntaxException */ public static StorageUri getServiceClientBaseAddress(final StorageUri addressUri, final boolean usePathStyleUris) throws URISyntaxException { return new StorageUri(new URI(getServiceClientBaseAddress(addressUri.getPrimaryUri(), usePathStyleUris)), addressUri.getSecondaryUri() != null ? new URI(getServiceClientBaseAddress(addressUri.getSecondaryUri(), usePathStyleUris)) : null); }
/** * Get the service client address from a complete Uri. * * @param address * Complete address of the resource. * @param usePathStyleUris * a value indicating if the address is a path style uri. * @return the service client address from a complete Uri. * @throws URISyntaxException */ public static StorageUri getServiceClientBaseAddress(final StorageUri addressUri, final boolean usePathStyleUris) throws URISyntaxException { return new StorageUri(new URI(getServiceClientBaseAddress(addressUri.getPrimaryUri(), usePathStyleUris)), addressUri.getSecondaryUri() != null ? new URI(getServiceClientBaseAddress(addressUri.getSecondaryUri(), usePathStyleUris)) : null); }
/** * Strips the Query and Fragment from the uri. * * @param inUri * the uri to alter * @return the stripped uri. * @throws StorageException */ public static StorageUri stripURIQueryAndFragment(final StorageUri inUri) throws StorageException { return new StorageUri(stripSingleURIQueryAndFragment(inUri.getPrimaryUri()), stripSingleURIQueryAndFragment(inUri.getSecondaryUri())); }
/** * Strips the Query and Fragment from the uri. * * @param inUri * the uri to alter * @return the stripped uri. * @throws StorageException */ public static StorageUri stripURIQueryAndFragment(final StorageUri inUri) throws StorageException { return new StorageUri(stripSingleURIQueryAndFragment(inUri.getPrimaryUri()), stripSingleURIQueryAndFragment(inUri.getSecondaryUri())); }
/** * Appends a path to a list of URIs correctly using "/" as separator. * * @param uriList * The base Uri. * @param relativeOrAbslouteUri * The relative or absloute URI. * @return The appended Uri. * @throws URISyntaxException */ public static StorageUri appendPathToUri(final StorageUri uriList, final String relativeOrAbsoluteUri, final String separator) throws URISyntaxException { return new StorageUri(appendPathToSingleUri(uriList.getPrimaryUri(), relativeOrAbsoluteUri, separator), appendPathToSingleUri(uriList.getSecondaryUri(), relativeOrAbsoluteUri, separator)); }
/** * Appends a path to a list of URIs correctly using "/" as separator. * * @param uriList * The base Uri. * @param relativeOrAbsoluteUri * The relative or absolute URI. * @return The appended Uri. * @throws URISyntaxException */ public static StorageUri appendPathToUri(final StorageUri uriList, final String relativeOrAbsoluteUri, final String separator) throws URISyntaxException { return new StorageUri(appendPathToSingleUri(uriList.getPrimaryUri(), relativeOrAbsoluteUri, separator), appendPathToSingleUri(uriList.getSecondaryUri(), relativeOrAbsoluteUri, separator)); }
static StorageUri ensureTrailingSlash(StorageUri uri) throws URISyntaxException { URI primary = uri.getPrimaryUri(); URI secondary = uri.getSecondaryUri(); // Add a trailing slash to primary if it did not previously have one if (primary != null) { String primaryUri = primary.toString(); if (!primaryUri.isEmpty() && !primaryUri.substring(primaryUri.length() - 1).equals("/")) { primaryUri += "/"; primary = new URI(primaryUri); } } // Add a trailing slash to secondary if it did not previously have one if (secondary != null) { String secondaryUri = secondary.toString(); if (!secondaryUri.isEmpty() && !secondaryUri.substring(secondaryUri.length() - 1).equals("/")) { secondaryUri += "/"; secondary = new URI(secondaryUri); } } return new StorageUri(primary, secondary); }
/** * Transforms a resource URI into a shared access signature URI, by appending a shared access token and using the * specified operation context. * * @param resourceUri * A <code>StorageUri</code> object that represents the resource URI to be transformed. * @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 <code>StorageUri</code> object that represents the signature, including the resource URI and the * shared access token. * * @throws StorageException * If a storage service error occurred. * @throws URISyntaxException * If the resource URI is not properly formatted. */ @Override public StorageUri transformUri(StorageUri resourceUri, OperationContext opContext) throws URISyntaxException, StorageException { return new StorageUri(this.transformUri(resourceUri.getPrimaryUri(), opContext), this.transformUri( resourceUri.getSecondaryUri(), opContext)); } }
/** * Adds a queryString to an URI. * * @param resourceURI * the URI of the resource * @param queryString * the query string to add * @return an appended URI. * @throws URISyntaxException * if the resulting URI is invalid. * @throws StorageException */ public static StorageUri addToQuery(final StorageUri resourceURI, final String queryString) throws URISyntaxException, StorageException { return new StorageUri(addToSingleUriQuery(resourceURI.getPrimaryUri(), parseQueryString(queryString)), addToSingleUriQuery(resourceURI.getSecondaryUri(), parseQueryString(queryString))); }
/** * Adds a queryString to an URI. * * @param resourceURI * the URI of the resource * @param queryString * the query string to add * @return an appended URI. * @throws URISyntaxException * if the resulting URI is invalid. * @throws StorageException */ public static StorageUri addToQuery(final StorageUri resourceURI, final String queryString) throws URISyntaxException, StorageException { return new StorageUri(addToSingleUriQuery(resourceURI.getPrimaryUri(), parseQueryString(queryString)), addToSingleUriQuery(resourceURI.getSecondaryUri(), parseQueryString(queryString))); }
@Test public void testCloudStorageAccountDevStoreProxyUri() throws InvalidKeyException, URISyntaxException { CloudStorageAccount account = CloudStorageAccount .parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://ipv4.fiddler"); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
@Test public void testCloudStorageAccountDefaultStorageAccountWithHttp() throws URISyntaxException, InvalidKeyException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, false); assertEquals(cloudStorageAccount.getBlobEndpoint(), new URI(String.format("http://%s.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueEndpoint(), new URI(String.format("http://%s.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableEndpoint(), new URI(String.format("http://%s.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileEndpoint(), new URI(String.format("http://%s.file.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getBlobStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileStorageUri().getSecondaryUri(), new URI(String.format("http://%s-secondary.file.core.windows.net", ACCOUNT_NAME))); String cloudStorageAccountToStringWithSecrets = cloudStorageAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(cloudStorageAccountToStringWithSecrets); AccountsAreEqual(testAccount, cloudStorageAccount); }
@Test public void testCloudStorageAccountDefaultStorageAccountWithHttps() throws URISyntaxException, InvalidKeyException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); assertEquals(cloudStorageAccount.getBlobEndpoint(), new URI(String.format("https://%s.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueEndpoint(), new URI(String.format("https://%s.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableEndpoint(), new URI(String.format("https://%s.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileEndpoint(), new URI(String.format("https://%s.file.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getBlobStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.file.core.windows.net", ACCOUNT_NAME))); String cloudStorageAccountToStringWithSecrets = cloudStorageAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(cloudStorageAccountToStringWithSecrets); AccountsAreEqual(testAccount, cloudStorageAccount); }
@Test public void testCloudStorageAccountDevStore() throws URISyntaxException { // default CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); // proxy account = CloudStorageAccount.getDevelopmentStorageAccount(new URI("http://ipv4.fiddler")); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
@Test public void testCloudStorageAccountDefaultEndpointOverride() throws URISyntaxException, InvalidKeyException { CloudStorageAccount account = CloudStorageAccount .parse("DefaultEndpointsProtocol=http;BlobEndpoint=http://customdomain.com/;AccountName=asdf;AccountKey=123="); assertEquals(new URI("http://customdomain.com/"), account.getBlobEndpoint()); assertNull(account.getBlobStorageUri().getSecondaryUri()); }
@Test public void testCloudStorageAccountDevelopmentStorageAccount() throws InvalidKeyException, URISyntaxException { CloudStorageAccount devstoreAccount = CloudStorageAccount.getDevelopmentStorageAccount(); assertEquals(devstoreAccount.getBlobStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10000/devstoreaccount1")); assertEquals(devstoreAccount.getQueueStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10001/devstoreaccount1")); assertEquals(devstoreAccount.getTableStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10002/devstoreaccount1")); assertEquals(devstoreAccount.getBlobStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10000/devstoreaccount1-secondary")); assertEquals(devstoreAccount.getQueueStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10001/devstoreaccount1-secondary")); assertEquals(devstoreAccount.getTableStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10002/devstoreaccount1-secondary")); String devstoreAccountToStringWithSecrets = devstoreAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(devstoreAccountToStringWithSecrets); AccountsAreEqual(testAccount, devstoreAccount); // Following should not throw exception: CloudStorageAccount.parse(devstoreAccountToStringWithSecrets); }
@Test public void testDevelopmentStorageWithTwoUris() throws URISyntaxException { CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); URI primaryClientURI = account.getBlobStorageUri().getPrimaryUri(); URI primaryContainerURI = new URI(primaryClientURI.toString() + "/container"); URI secondaryClientURI = account.getBlobStorageUri().getSecondaryUri(); StorageUri singleURI = new StorageUri(primaryClientURI); assertTrue(primaryClientURI.equals(singleURI.getPrimaryUri())); assertNull(singleURI.getSecondaryUri()); StorageUri singleURI2 = new StorageUri(primaryClientURI); assertTrue(singleURI.equals(singleURI2)); StorageUri singleURI3 = new StorageUri(secondaryClientURI); assertFalse(singleURI.equals(singleURI3)); StorageUri multiURI = new StorageUri(primaryClientURI, secondaryClientURI); assertTrue(primaryClientURI.equals(multiURI.getPrimaryUri())); assertTrue(secondaryClientURI.equals(multiURI.getSecondaryUri())); assertFalse(multiURI.equals(singleURI)); StorageUri multiURI2 = new StorageUri(primaryClientURI, secondaryClientURI); assertTrue(multiURI.equals(multiURI2)); try { new StorageUri(primaryClientURI, primaryContainerURI); fail("StorageUri constructor should fail if both URIs do not point to the same resource"); } catch (IllegalArgumentException e) { assertEquals(SR.STORAGE_URI_MUST_MATCH, e.getMessage()); } StorageUri multiURI3 = new StorageUri(secondaryClientURI, primaryClientURI); assertFalse(multiURI.equals(multiURI3)); }
@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()); }
@Test public void testTableTypesWithStorageUri() throws URISyntaxException, StorageException { CloudTableClient tableClient = TestHelper.createCloudTableClient(); StorageUri endpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + TABLE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + TABLE_SERVICE + ENDPOINT_SUFFIX)); CloudTableClient client = new CloudTableClient(endpoint, tableClient.getCredentials()); assertEquals(endpoint, client.getStorageUri()); assertEquals(endpoint.getPrimaryUri(), client.getEndpoint()); StorageUri tableUri = new StorageUri(new URI(endpoint.getPrimaryUri() + "/table"), new URI( endpoint.getSecondaryUri() + "/table")); CloudTable table = client.getTableReference("table"); assertEquals(tableUri, table.getStorageUri()); assertEquals(tableUri.getPrimaryUri(), table.getUri()); assertEquals(endpoint, table.getServiceClient().getStorageUri()); table = new CloudTable(tableUri, client.getCredentials()); assertEquals(tableUri, table.getStorageUri()); assertEquals(tableUri.getPrimaryUri(), table.getUri()); assertEquals(endpoint, table.getServiceClient().getStorageUri()); } }