storageCredentials
specify an invalid account name.
*/
- public CloudStorageAccount(final StorageCredentials storageCredentials,
- final boolean useHttps) throws URISyntaxException {
+ public CloudStorageAccount(final StorageCredentials storageCredentials, final boolean useHttps)
+ throws URISyntaxException {
this (storageCredentials, useHttps, null);
}
@@ -582,20 +581,60 @@ public CloudStorageAccount(final StorageCredentials storageCredentials,
* @throws URISyntaxException
* If storageCredentials
specify an invalid account name.
*/
- public CloudStorageAccount(final StorageCredentials storageCredentials,
- final boolean useHttps, final String endpointSuffix) throws URISyntaxException {
+ public CloudStorageAccount(
+ final StorageCredentials storageCredentials, final boolean useHttps, final String endpointSuffix)
+ throws URISyntaxException {
+ this(storageCredentials, useHttps, endpointSuffix, null);
+ }
+
+ /**
+ * Creates an instance of the CloudStorageAccount
class using the specified
+ * account credentials.
+ *
+ * With this constructor, the
@@ -1175,6 +1130,46 @@ public StorageExtendedErrorInformation parseErrorDetails() {
public String generateSharedAccessSignature(final SharedAccessTablePolicy policy,
final String accessPolicyIdentifier, final String startPartitionKey, final String startRowKey,
final String endPartitionKey, final String endRowKey) throws InvalidKeyException, StorageException {
+
+ return generateSharedAccessSignature(policy, accessPolicyIdentifier,
+ startPartitionKey, startRowKey, endPartitionKey, endRowKey, null /* IP Range */, null /* Protocols */);
+ }
+
+ /**
+ * Creates a shared access signature for the table.
+ *
+ * @param policy
+ * A {@link SharedAccessTablePolicy} object which represents the access policy for the shared access
+ * signature.
+ * @param accessPolicyIdentifier
+ * A CloudStorageAccount
object is constructed using the
+ * given HTTP storage service endpoint suffix (if any, otherwise the default is used).
+ *
+ * The credentials provided when constructing the CloudStorageAccount
object
+ * are used to authenticate all further requests against resources that are accessed via
+ * the CloudStorageAccount
object or a client object created from it.
+ * A client object may be a {@link CloudBlobClient} object.
+ *
+ * @param storageCredentials
+ * A {@link StorageCredentials} object that represents the storage credentials
+ * to use to authenticate this account.
+ * @param useHttps
+ * true
to use HTTPS to connect to the storage service endpoints;
+ * otherwise, false
.
+ * @param endpointSuffix
+ * A String that represents the endpointSuffix to use, if any.
+ * @param accountName
+ * A String
that contains the account name. This will be used in place of a
+ * null
{@link StorageCredentials#getAccountName()}, but the two must match if
+ * both are not null
.
+ *
+ * @throws URISyntaxException
+ * If storageCredentials
specify an invalid account name.
+ */
+ public CloudStorageAccount(
+ final StorageCredentials storageCredentials, final boolean useHttps, final String endpointSuffix, String accountName)
+ throws URISyntaxException {
Utility.assertNotNull("storageCredentials", storageCredentials);
+ if (Utility.isNullOrEmpty(accountName)) {
+ accountName = storageCredentials.getAccountName();
+ }
+ else if (!Utility.isNullOrEmpty(storageCredentials.getAccountName()) &&
+ !accountName.equals(storageCredentials.getAccountName())) {
+
+ throw new IllegalArgumentException(SR.ACCOUNT_NAME_MISMATCH);
+ }
+
String protocol = useHttps ? Constants.HTTPS : Constants.HTTP;
this.credentials = storageCredentials;
- this.blobStorageUri = getDefaultStorageUri(protocol, storageCredentials.getAccountName(),
- getDNS(SR.BLOB, endpointSuffix));
- this.fileStorageUri = getDefaultStorageUri(protocol, storageCredentials.getAccountName(),
- getDNS(SR.FILE, endpointSuffix));
- this.queueStorageUri = getDefaultStorageUri(protocol, storageCredentials.getAccountName(),
- getDNS(SR.QUEUE, endpointSuffix));
- this.tableStorageUri = getDefaultStorageUri(protocol, storageCredentials.getAccountName(),
- getDNS(SR.TABLE, endpointSuffix));
+ this.blobStorageUri = getDefaultStorageUri(protocol, accountName, getDNS(SR.BLOB, endpointSuffix));
+ this.fileStorageUri = getDefaultStorageUri(protocol, accountName, getDNS(SR.FILE, endpointSuffix));
+ this.queueStorageUri = getDefaultStorageUri(protocol, accountName, getDNS(SR.QUEUE, endpointSuffix));
+ this.tableStorageUri = getDefaultStorageUri(protocol, accountName, getDNS(SR.TABLE, endpointSuffix));
this.endpointSuffix = endpointSuffix;
this.isBlobEndpointDefault = true;
@@ -726,7 +765,7 @@ public CloudStorageAccount(
this.tableStorageUri = tableStorageUri;
this.endpointSuffix = null;
}
-
+
/**
* Creates a new Analytics service client.
*
@@ -763,9 +802,6 @@ public CloudBlobClient createCloudBlobClient() {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
- if (!StorageCredentialsHelper.canCredentialsSignRequest(this.credentials)) {
- throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
- }
return new CloudBlobClient(this.getBlobStorageUri(), this.getCredentials());
}
@@ -784,9 +820,11 @@ public CloudFileClient createCloudFileClient() {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
- if (!StorageCredentialsHelper.canCredentialsSignRequest(this.credentials)) {
+ if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
+
throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
}
+
return new CloudFileClient(this.getFileStorageUri(), this.getCredentials());
}
@@ -804,9 +842,11 @@ public CloudQueueClient createCloudQueueClient() {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
- if (!StorageCredentialsHelper.canCredentialsSignRequest(this.credentials)) {
+ if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
+
throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
}
+
return new CloudQueueClient(this.getQueueStorageUri(), this.getCredentials());
}
@@ -824,9 +864,11 @@ public CloudTableClient createCloudTableClient() {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
- if (!StorageCredentialsHelper.canCredentialsSignRequest(this.credentials)) {
+ if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
+
throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
}
+
return new CloudTableClient(this.getTableStorageUri(), this.getCredentials());
}
@@ -837,10 +879,6 @@ public CloudTableClient createCloudTableClient() {
* @return A java.net.URI
object that represents the Blob endpoint associated with this account.
*/
public URI getBlobEndpoint() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
if (this.blobStorageUri == null) {
return null;
}
@@ -855,10 +893,6 @@ public URI getBlobEndpoint() {
* @return A {@link StorageUri} object that represents the Blob endpoint associated with this account.
*/
public StorageUri getBlobStorageUri() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
return this.blobStorageUri;
}
@@ -886,10 +920,6 @@ public String getEndpointSuffix() {
* @return A java.net.URI
object that represents the File endpoint associated with this account.
*/
public URI getFileEndpoint() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
if (this.fileStorageUri == null) {
return null;
}
@@ -904,10 +934,6 @@ public URI getFileEndpoint() {
* @return A {@link StorageUri} object that represents the File endpoint associated with this account.
*/
public StorageUri getFileStorageUri() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
return this.fileStorageUri;
}
@@ -917,10 +943,6 @@ public StorageUri getFileStorageUri() {
* @return A java.net.URI
object that represents the queue endpoint associated with this account.
*/
public URI getQueueEndpoint() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
if (this.queueStorageUri == null) {
return null;
}
@@ -934,10 +956,6 @@ public URI getQueueEndpoint() {
* @return A {@link StorageUri} object that represents the Queue endpoint associated with this account.
*/
public StorageUri getQueueStorageUri() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
return this.queueStorageUri;
}
@@ -947,10 +965,6 @@ public StorageUri getQueueStorageUri() {
* @return A {@link StorageUri} object that represents the Table endpoint associated with this account.
*/
public URI getTableEndpoint() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
if (this.tableStorageUri == null) {
return null;
}
@@ -964,12 +978,33 @@ public URI getTableEndpoint() {
* @return A java.net.URI
object that represents the Table endpoint associated with this account.
*/
public StorageUri getTableStorageUri() {
- if (this.getCredentials() instanceof StorageCredentialsSharedAccessSignature) {
- throw new IllegalArgumentException(SR.ENDPOINT_INFORMATION_UNAVAILABLE);
- }
-
return this.tableStorageUri;
}
+
+ /**
+ * Returns a shared access signature for the account.
+ *
+ * @param policy
+ * A {@link SharedAccessAccountPolicy} specifying the access policy for the shared access signature.
+ *
+ * @return The query string returned includes the leading question mark.
+ * @throws StorageException
+ * If a storage service error occurred.
+ * @throws InvalidKeyException
+ * If the key is invalid.
+ */
+ public String generateSharedAccessSignature(SharedAccessAccountPolicy policy)
+ throws InvalidKeyException, StorageException {
+ if (!StorageCredentialsHelper.canCredentialsSignRequest(this.getCredentials())) {
+ throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
+ }
+
+ final String sig = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForAccount(
+ this.credentials.getAccountName(), policy, this.getCredentials());
+ final UriQueryBuilder sasBuilder =
+ SharedAccessSignatureHelper.generateSharedAccessSignatureForAccount(policy, sig);
+ return sasBuilder.toString();
+ }
/**
* Returns a connection string for this storage account, without sensitive data.
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java
index e992042de..2a0208cff 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java
@@ -113,6 +113,11 @@ public static class AnalyticsConstants {
*/
public static final String METRICS_HOUR_PRIMARY_TRANSACTIONS_BLOB = "$MetricsHourPrimaryTransactionsBlob";
+ /**
+ * Constant for the file service primary location hourly metrics table.
+ */
+ public static final String METRICS_HOUR_PRIMARY_TRANSACTIONS_FILE = "$MetricsHourPrimaryTransactionsFile";
+
/**
* Constant for the table service primary location hourly metrics table.
*/
@@ -128,6 +133,11 @@ public static class AnalyticsConstants {
*/
public static final String METRICS_MINUTE_PRIMARY_TRANSACTIONS_BLOB = "$MetricsMinutePrimaryTransactionsBlob";
+ /**
+ * Constant for the file service primary location minute metrics table.
+ */
+ public static final String METRICS_MINUTE_PRIMARY_TRANSACTIONS_FILE = "$MetricsMinutePrimaryTransactionsFile";
+
/**
* Constant for the table service primary location minute metrics table.
*/
@@ -143,6 +153,11 @@ public static class AnalyticsConstants {
*/
public static final String METRICS_HOUR_SECONDARY_TRANSACTIONS_BLOB = "$MetricsHourSecondaryTransactionsBlob";
+ /**
+ * Constant for the file service secondary location hourly metrics table.
+ */
+ public static final String METRICS_HOUR_SECONDARY_TRANSACTIONS_FILE = "$MetricsHourSecondaryTransactionsFile";
+
/**
* Constant for the table service secondary location hourly metrics table.
*/
@@ -158,6 +173,11 @@ public static class AnalyticsConstants {
*/
public static final String METRICS_MINUTE_SECONDARY_TRANSACTIONS_BLOB = "$MetricsMinuteSecondaryTransactionsBlob";
+ /**
+ * Constant for the file service secondary location minute metrics table.
+ */
+ public static final String METRICS_MINUTE_SECONDARY_TRANSACTIONS_FILE = "$MetricsMinuteSecondaryTransactionsFile";
+
/**
* Constant for the table service secondary location minute metrics table.
*/
@@ -530,7 +550,7 @@ public static class HeaderConstants {
/**
* The current storage version header value.
*/
- public static final String TARGET_STORAGE_VERSION = "2015-02-21";
+ public static final String TARGET_STORAGE_VERSION = "2015-04-05";
/**
* The header that specifies the next visible time for a queue message.
@@ -550,7 +570,7 @@ public static class HeaderConstants {
/**
* Specifies the value to use for UserAgent header.
*/
- public static final String USER_AGENT_VERSION = "3.1.0";
+ public static final String USER_AGENT_VERSION = "4.0.0";
/**
* The default type for content-type and accept
@@ -562,6 +582,10 @@ public static class HeaderConstants {
* Defines constants for use with query strings.
*/
public static class QueryConstants {
+ /**
+ * The query component for the api version.
+ */
+ public static final String API_VERSION = "api-version";
/**
* Query component for SAS cache control.
@@ -627,11 +651,6 @@ public static class QueryConstants {
* Query component for resource type.
*/
public static final String RESOURCETYPE = "restype";
-
- /**
- * The query component for the api version.
- */
- public static final String API_VERSION = "api-version";
/**
* The query component for the SAS table name.
@@ -653,6 +672,11 @@ public static class QueryConstants {
*/
public static final String SIGNED_IDENTIFIER = "si";
+ /**
+ * The query component for the signed SAS IP address.
+ */
+ public static final String SIGNED_IP = "sip";
+
/**
* The query component for the signing SAS key.
*/
@@ -663,11 +687,26 @@ public static class QueryConstants {
*/
public static final String SIGNED_PERMISSIONS = "sp";
+ /**
+ * The query component for the signed SAS Internet protocols.
+ */
+ public static final String SIGNED_PROTOCOLS = "spr";
+
/**
* The query component for the signed SAS resource.
*/
public static final String SIGNED_RESOURCE = "sr";
+ /**
+ * The query component for the signed SAS resource type.
+ */
+ public static final String SIGNED_RESOURCE_TYPE = "srt";
+
+ /**
+ * The query component for the signed SAS service.
+ */
+ public static final String SIGNED_SERVICE = "ss";
+
/**
* The query component for the signed SAS start time.
*/
@@ -909,6 +948,11 @@ public static class QueryConstants {
*/
public static final String HTTPS = "https";
+ /**
+ * Specifies both HTTPS and HTTP.
+ */
+ public static final String HTTPS_HTTP = "https,http";
+
/**
* XML attribute for IDs.
*/
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/Credentials.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/Credentials.java
deleted file mode 100644
index de9a849f3..000000000
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/Credentials.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Copyright Microsoft Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- *
- */
-package com.microsoft.azure.storage;
-
-import com.microsoft.azure.storage.core.Base64;
-import com.microsoft.azure.storage.core.SR;
-import com.microsoft.azure.storage.core.Utility;
-
-/**
- * Represents the credentials used to sign a request against the storage services.
- *
- * @deprecated as of 3.0.0. Please use the equivalent methods on {@link StorageCredentialsAccountAndKey}.
- */
-@Deprecated
-public final class Credentials {
- /**
- * Stores the Account name for the credentials.
- */
- private String accountName;
-
- /**
- * Stores the StorageKey for the credentials.
- */
- private StorageKey key;
-
- /**
- * Stores the name of the access key to be used when signing the request.
- */
- private String keyName;
-
- /**
- * Creates an instance of the Credentials
class, using the specified storage account name and access
- * key; the specified access key is in the form of a byte array.
- *
- * @param accountName
- * A String
that represents the name of the storage account.
- *
- * @param key
- * An array of bytes that represent the account access key.
- *
- */
- public Credentials(final String accountName, final byte[] key) {
- if (Utility.isNullOrEmptyOrWhitespace(accountName)) {
- throw new IllegalArgumentException(SR.INVALID_ACCOUNT_NAME);
- }
-
- if (key == null || key.length == 0) {
- throw new IllegalArgumentException(SR.INVALID_KEY);
- }
-
- this.accountName = accountName;
- this.key = new StorageKey(key);
- }
-
- /**
- * Creates an instance of the Credentials
class, using the specified storage account name and access
- * key; the specified access key is stored as a Base64-encoded String
.
- *
- * @param accountName
- * A String
that represents the name of the storage account.
- *
- * @param key
- * A String
that represents the Base64-encoded account access key.
- *
- */
- public Credentials(final String accountName, final String key) {
- if (Utility.isNullOrEmptyOrWhitespace(accountName)) {
- throw new IllegalArgumentException(SR.INVALID_ACCOUNT_NAME);
- }
-
- if (Utility.isNullOrEmptyOrWhitespace(key) || !Base64.validateIsBase64String(key)) {
- throw new IllegalArgumentException(SR.INVALID_KEY);
- }
-
- this.accountName = accountName;
- this.key = new StorageKey(Base64.decode(key));
- }
-
- /**
- * Exports the value of the access key to a Base64-encoded string.
- *
- * @return A String
that represents the Base64-encoded access key.
- */
- public String exportBase64EncodedKey() {
- return this.getKey().getBase64EncodedKey();
- }
-
- /**
- * Exports the value of the access key to an array of bytes.
- *
- * @return A byte array that represents the access key.
- */
- public byte[] exportKey() {
- return this.getKey().getKey();
- }
-
- /**
- * Gets the account name to be used when signing the request.
- *
- * @return A String
that represents the account name to be used when signing the request.
- */
- public String getAccountName() {
- return this.accountName;
- }
-
- /**
- * Gets the name of the access key to be used when signing the request.
- * Internal use only.
- */
- public String getKeyName() {
- return this.keyName;
- }
-
- /**
- * Returns the access key to be used when signing the request.
- *
- * @return A String
that represents the access key to be used when signing the request.
- */
- public StorageKey getKey() {
- return this.key;
- }
-
- /**
- * Sets the account name to be used when signing the request.
- *
- * @param accountName
- * A String
that represents the account name being set.
- */
- protected void setAccountName(final String accountName) {
- this.accountName = accountName;
- }
-
- /**
- * Sets the access key to be used when signing the request.
- *
- * @param keyName
- * A String
that represents the name of the access key to be used when signing the request.
- */
- protected void setKey(final StorageKey key) {
- this.key = key;
- }
-}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/IPRange.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/IPRange.java
new file mode 100644
index 000000000..2ee6194db
--- /dev/null
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/IPRange.java
@@ -0,0 +1,113 @@
+/**
+ * Copyright Microsoft Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.microsoft.azure.storage;
+
+import java.net.Inet4Address;
+
+import com.microsoft.azure.storage.core.SR;
+import com.microsoft.azure.storage.core.Utility;
+
+/**
+ * A continuous range of IP addresses.
+ */
+public final class IPRange {
+ private String ipMin;
+ private String ipMax;
+
+ /**
+ * Creates an IP Range using the specified single IP address. The IP address must be IPv4.
+ *
+ * @param ip
+ * the single IP address
+ */
+ public IPRange(String ip) {
+ Utility.assertNotNull("ip", ip);
+ IPRange.validateIPAddress(ip);
+
+ this.ipMin = ip;
+ this.ipMax = ip;
+ }
+
+ /**
+ * Creates an IP Range using the specified minimum and maximum IP addresses. The IP addresses must be IPv4.
+ *
+ * @param mininimumIP
+ * the minimum IP address of the range
+ * @param maximumIP
+ * the maximum IP address of the range
+ */
+ public IPRange(String mininimumIP, String maximumIP) {
+ Utility.assertNotNull("mininimumIP", mininimumIP);
+ Utility.assertNotNull("maximumIP", maximumIP);
+
+ IPRange.validateIPAddress(mininimumIP);
+ IPRange.validateIPAddress(maximumIP);
+
+ this.ipMin = mininimumIP;
+ this.ipMax = maximumIP;
+ }
+
+ /**
+ * The minimum IP address for the range, inclusive.
+ * Will match {@link #getIpMax()} if this IPRange
represents a single IP address.
+ *
+ * @return The minimum IP address
+ */
+ public String getIpMin() {
+ return this.ipMin;
+ }
+
+ /**
+ * The maximum IP address for the range, inclusive.
+ * Will match {@link #getIpMin()} if this IPRange
represents a single IP address.
+ *
+ * @return The maximum IP address
+ */
+ public String getIpMax() {
+ return this.ipMax;
+ }
+
+ /**
+ * Output the single IP address or range of IP addresses.
+ *
+ * @return the single IP address or range of IP addresses formated as a String
+ */
+ @Override
+ public String toString() {
+ StringBuilder str = new StringBuilder(this.ipMin);
+ if (!this.ipMin.equals(this.ipMax)) {
+ str.append("-");
+ str.append(this.ipMax);
+ }
+
+ return str.toString();
+ }
+
+ /**
+ * Validate that the IP address is IPv4.
+ *
+ * @param ipAddress
+ * the IP address to validate
+ */
+ private static void validateIPAddress(String ipAddress) {
+ try {
+ @SuppressWarnings("unused")
+ Inet4Address address = (Inet4Address) Inet4Address.getByName(ipAddress);
+ }
+ catch (Exception ex) {
+ throw new IllegalArgumentException(String.format(SR.INVALID_IP_ADDRESS, ipAddress), ex);
+ }
+ }
+}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/ServiceClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/ServiceClient.java
index f5338be3f..341aa8348 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/ServiceClient.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/ServiceClient.java
@@ -76,7 +76,8 @@ protected StorageRequestSharedAccessAccountPermissions
.
+ *
+ * @param c
+ * The char
which represents this permission.
+ */
+ private SharedAccessAccountPermissions(char c) {
+ this.value = c;
+ }
+
+ /**
+ * Converts the given permissions to a String
.
+ *
+ * @param permissions
+ * The permissions to convert to a String
.
+ *
+ * @return A String
which represents the SharedAccessAccountPermissions
.
+ */
+ static String permissionsToString(EnumSetString
which represents the SharedAccessAccountPermissions
.
+ * @return A {@link EnumSetString
.
+ */
+ static EnumSetString
.
+ *
+ * @return A String
which represents the shared access permissions.
+ */
+ public String permissionsToString() {
+ return SharedAccessAccountPermissions.permissionsToString(this.getPermissions());
+ }
+
+ /**
+ * Converts this shared access policy's resource types to a String
.
+ *
+ * @return A String
which represents the shared access permissions.
+ */
+ public String resourceTypesToString() {
+ return SharedAccessAccountResourceType.resourceTypesToString(this.getResourceTypes());
+ }
+
+ /**
+ * Converts this shared access policy's services to a String
.
+ *
+ * @return A String
which represents the shared access permissions.
+ */
+ public String servicesToString() {
+ return SharedAccessAccountService.servicesToString(this.getServices());
+ }
+
+ /**
+ * Sets shared access permissions using the specified permissions String
.
+ *
+ * @param value
+ * A String
which represents the shared access permissions.
+ **/
+ public void setPermissionsFromString(final String value) {
+ this.setPermissions(SharedAccessAccountPermissions.permissionsFromString(value));
+ }
+
+ /**
+ * Sets shared access resource types using the specified resource types String
.
+ *
+ * @param value
+ * A String
which represents the shared access resource types.
+ **/
+ public void setResourceTypeFromString(final String value) {
+ this.setResourceTypes(SharedAccessAccountResourceType.resourceTypesFromString(value));
+ }
+
+ /**
+ * Sets shared access services using the specified services String
.
+ *
+ * @param value
+ * A String
which represents the shared access services.
+ **/
+ public void setServiceFromString(final String value) {
+ this.setServices(SharedAccessAccountService.servicesFromString(value));
+ }
+}
\ No newline at end of file
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/SharedAccessAccountResourceType.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/SharedAccessAccountResourceType.java
new file mode 100644
index 000000000..8195b18bf
--- /dev/null
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/SharedAccessAccountResourceType.java
@@ -0,0 +1,103 @@
+/**
+ * Copyright Microsoft Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.microsoft.azure.storage;
+
+import java.util.EnumSet;
+
+import com.microsoft.azure.storage.core.SR;
+
+/**
+ * Specifies the set of possible resource types for a shared access account policy.
+ */
+public enum SharedAccessAccountResourceType {
+ /**
+ * Permission to access service level APIs granted.
+ */
+ SERVICE('s'),
+
+ /**
+ * Permission to access container level APIs (Blob Containers, Tables, Queues, File Shares) granted.
+ */
+ CONTAINER('c'),
+
+ /**
+ * Permission to access object level APIs (Blobs, Table Entities, Queue Messages, Files) granted.
+ */
+ OBJECT('o');
+
+ char value;
+
+ /**
+ * Create a SharedAccessAccountResourceType
.
+ *
+ * @param c
+ * The char
which represents this resource type.
+ */
+ private SharedAccessAccountResourceType(char c) {
+ this.value = c;
+ }
+
+ /**
+ * Converts the given resource types to a String
.
+ *
+ * @param types
+ * The resource types to convert to a String
.
+ *
+ * @return A String
which represents the SharedAccessAccountResourceTypes
.
+ */
+ static String resourceTypesToString(EnumSetString
which represents the SharedAccessAccountResourceTypes
.
+ * @return A {@link EnumSetString
.
+ */
+ static EnumSetSharedAccessAccountService
.
+ *
+ * @param c
+ * The char
which represents this service.
+ */
+ private SharedAccessAccountService(char c) {
+ this.value = c;
+ }
+
+ /**
+ * Converts the given services to a String
.
+ *
+ * @param services
+ * The services to convert to a String
.
+ *
+ * @return A String
which represents the SharedAccessAccountServices
.
+ */
+ static String servicesToString(EnumSetString
which represents the SharedAccessAccountServices
.
+ * @return A {@link EnumSetString
.
+ */
+ static EnumSetSharedAccessPolicy
class.
- * */
+ */
public SharedAccessPolicy() {
// Empty Default Constructor.
}
-
+
/**
* Gets the expiry time for a shared access signature associated with this shared access policy.
*
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/SharedAccessProtocols.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/SharedAccessProtocols.java
new file mode 100644
index 000000000..b18bfae62
--- /dev/null
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/SharedAccessProtocols.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright Microsoft Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.microsoft.azure.storage;
+
+/**
+ * Specifies the set of possible permissions for a shared access protocol.
+ */
+public enum SharedAccessProtocols {
+ /**
+ * Permission to use SAS only through https granted.
+ */
+ HTTPS_ONLY(Constants.HTTPS),
+
+ /**
+ * Permission to use SAS only through https or http granted.
+ */
+ HTTPS_HTTP(Constants.HTTPS_HTTP);
+
+ private final String protocols;
+
+ private SharedAccessProtocols(String p) {
+ this.protocols = p;
+ }
+
+ @Override
+ public String toString() {
+ return this.protocols;
+ }
+}
\ No newline at end of file
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java
index 59459e2aa..3b65558da 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentials.java
@@ -51,14 +51,14 @@ public abstract class StorageCredentials {
*/
protected static StorageCredentials tryParseCredentials(final Mapboolean
representing whether this StorageCredentials
object only allows access via HTTPS.
+ */
+ private boolean httpsOnly = false;
+
+ /**
+ * Gets whether this StorageCredentials
object only allows access via HTTPS.
+ *
+ * @return A boolean
representing whether this StorageCredentials
+ * object only allows access via HTTPS.
+ */
+ public boolean isHttpsOnly() {
+ return this.httpsOnly;
+ }
/**
* Returns the associated account name for the credentials. This is null for anonymous and shared access signature
@@ -108,6 +126,16 @@ public static StorageCredentials tryParseCredentials(final String connectionStri
public String getAccountName() {
return null;
}
+
+ /**
+ * Sets whether this StorageCredentials
object only allows access via HTTPS.
+ * @param httpsOnly
+ * A boolean
representing whether this StorageCredentials
+ * object only allows access via HTTPS.
+ */
+ protected void setHttpsOnly(boolean httpsOnly) {
+ this.httpsOnly = httpsOnly;
+ }
/**
* Returns a String
that represents this instance.
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAccountAndKey.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAccountAndKey.java
index 3ac243376..709c8e259 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAccountAndKey.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAccountAndKey.java
@@ -15,6 +15,11 @@
package com.microsoft.azure.storage;
import java.net.URI;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
import com.microsoft.azure.storage.core.Base64;
import com.microsoft.azure.storage.core.SR;
@@ -27,10 +32,19 @@
public final class StorageCredentialsAccountAndKey extends StorageCredentials {
/**
- * The internal Credentials associated with the StorageCredentials.
+ * Stores the Account name for the credentials.
+ */
+ private String accountName;
+
+ /**
+ * Stores a reference to the hmacsha256 Mac.
+ */
+ private Mac hmacSha256;
+
+ /**
+ * Stores the key.
*/
- @SuppressWarnings("deprecation")
- private Credentials credentials;
+ private byte[] key;
/**
* Creates an instance of the StorageCredentialsAccountAndKey
class, using the specified storage
@@ -41,9 +55,17 @@ public final class StorageCredentialsAccountAndKey extends StorageCredentials {
* @param key
* An array of bytes that represent the account access key.
*/
- @SuppressWarnings("deprecation")
public StorageCredentialsAccountAndKey(final String accountName, final byte[] key) {
- this.credentials = new Credentials(accountName, key);
+ if (Utility.isNullOrEmptyOrWhitespace(accountName)) {
+ throw new IllegalArgumentException(SR.INVALID_ACCOUNT_NAME);
+ }
+
+ if (key == null || key.length == 0) {
+ throw new IllegalArgumentException(SR.INVALID_KEY);
+ }
+
+ this.accountName = accountName;
+ this.key = key;
}
/**
@@ -55,9 +77,8 @@ public StorageCredentialsAccountAndKey(final String accountName, final byte[] ke
* @param key
* A String
that represents the Base-64-encoded account access key.
*/
- @SuppressWarnings("deprecation")
public StorageCredentialsAccountAndKey(final String accountName, final String key) {
- this.credentials = new Credentials(accountName, key);
+ this(accountName, Base64.decode(key));
}
/**
@@ -65,10 +86,9 @@ public StorageCredentialsAccountAndKey(final String accountName, final String ke
*
* @return A String
that contains the account name.
*/
- @SuppressWarnings("deprecation")
@Override
public String getAccountName() {
- return this.credentials.getAccountName();
+ return this.accountName;
}
/**
@@ -76,9 +96,8 @@ public String getAccountName() {
*
* @return A String
that represents the Base64-encoded access key.
*/
- @SuppressWarnings("deprecation")
public String exportBase64EncodedKey() {
- return this.credentials.getKey().getBase64EncodedKey();
+ return Base64.encode(this.key);
}
/**
@@ -86,9 +105,9 @@ public String exportBase64EncodedKey() {
*
* @return A byte array that represents the access key.
*/
- @SuppressWarnings("deprecation")
public byte[] exportKey() {
- return this.credentials.getKey().getKey();
+ final byte[] copy = this.key.clone();
+ return copy;
}
/**
@@ -97,9 +116,8 @@ public byte[] exportKey() {
* @param accountName
* A String
that contains the account name.
*/
- @SuppressWarnings("deprecation")
public void setAccountName(String accountName) {
- this.credentials.setAccountName(accountName);
+ this.accountName = accountName;
}
/**
@@ -108,13 +126,8 @@ public void setAccountName(String accountName) {
* @param key
* A String
that represents the name of the access key to be used when signing the request.
*/
- @SuppressWarnings("deprecation")
- public void updateKey(final String key) {
- if (Utility.isNullOrEmptyOrWhitespace(key) || !Base64.validateIsBase64String(key)) {
- throw new IllegalArgumentException(SR.INVALID_KEY);
- }
-
- this.credentials.setKey(new StorageKey(Base64.decode(key)));
+ public synchronized void updateKey(final String key) {
+ this.updateKey(Base64.decode(key));
}
/**
@@ -123,49 +136,13 @@ public void updateKey(final String key) {
* @param key
* A String
that represents the name of the access key to be used when signing the request.
*/
- @SuppressWarnings("deprecation")
- public void updateKey(final byte[] key) {
+ public synchronized void updateKey(final byte[] key) {
if (key == null || key.length == 0) {
throw new IllegalArgumentException(SR.INVALID_KEY);
}
- this.credentials.setKey(new StorageKey(key));
- }
-
- /**
- * Gets the name of the key used by these credentials.
- * @deprecated as of 3.0.0. The key name property is only useful internally.
- */
- @Deprecated
- public String getAccountKeyName() {
- return this.credentials.getKeyName();
- }
-
- /**
- * Returns the internal credentials associated with the storage credentials.
- *
- * @return A Credentials
object that contains the internal credentials associated with this instance of
- * the StorageCredentialsAccountAndKey
class.
- * @deprecated as of 3.0.0. Please use {@link #getAccountName()}, {@link #exportKey()}, or
- * {@link #exportBase64EncodedKey()}
- */
- @Deprecated
- public Credentials getCredentials() {
- return this.credentials;
- }
-
- /**
- * Sets the credentials.
- *
- * @param credentials
- * A Credentials
object that represents the credentials to set for this instance of the
- * StorageCredentialsAccountAndKey
class.
- * @deprecated as of 3.0.0. Please use {@link #setAccountName(String)}, {@link #updateKey(String)}, or
- * {@link #updateKey(byte[])}
- */
- @Deprecated
- public void setCredentials(final Credentials credentials) {
- this.credentials = credentials;
+ this.key = key;
+ this.hmacSha256 = null;
}
/**
@@ -176,11 +153,10 @@ public void setCredentials(final Credentials credentials) {
*
* @return A String
that represents this object, optionally including sensitive data.
*/
- @SuppressWarnings("deprecation")
@Override
public String toString(final boolean exportSecrets) {
return String.format("%s=%s;%s=%s", CloudStorageAccount.ACCOUNT_NAME_NAME, this.getAccountName(),
- CloudStorageAccount.ACCOUNT_KEY_NAME, exportSecrets ? this.credentials.getKey().getBase64EncodedKey()
+ CloudStorageAccount.ACCOUNT_KEY_NAME, exportSecrets ? this.exportBase64EncodedKey()
: "[key hidden]");
}
@@ -193,4 +169,26 @@ public URI transformUri(URI resourceUri, OperationContext opContext) {
public StorageUri transformUri(StorageUri resourceUri, OperationContext opContext) {
return resourceUri;
}
+
+ /**
+ * Gets the HmacSha256 associated with the account key.
+ *
+ * @return A MAC
created with the account key.
+ *
+ * @throws InvalidKeyException
+ * If the key is not a valid storage key.
+ */
+ public synchronized Mac getHmac256() throws InvalidKeyException {
+ if (this.hmacSha256 == null) {
+ // Initializes the HMAC-SHA256 Mac and SecretKey.
+ try {
+ this.hmacSha256 = Mac.getInstance("HmacSHA256");
+ }
+ catch (final NoSuchAlgorithmException e) {
+ throw new IllegalArgumentException();
+ }
+ this.hmacSha256.init(new SecretKeySpec(this.key, "HmacSHA256"));
+ }
+ return this.hmacSha256;
+ }
}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAnonymous.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAnonymous.java
index 010ead369..be8961084 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAnonymous.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsAnonymous.java
@@ -20,7 +20,6 @@
* Represents credentials for anonymous access.
*/
public final class StorageCredentialsAnonymous extends StorageCredentials {
-
/**
* Stores the singleton instance of this class.
*/
@@ -38,8 +37,8 @@ protected static StorageCredentials getInstance() {
/**
* Enforces the singleton pattern via a private constructor.
*/
- protected StorageCredentialsAnonymous() {
- // Empty Default Ctor
+ private StorageCredentialsAnonymous() {
+ // Empty Default Ctor
}
/**
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsSharedAccessSignature.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsSharedAccessSignature.java
index 0ec3aaebf..0e79d565e 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsSharedAccessSignature.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/StorageCredentialsSharedAccessSignature.java
@@ -16,8 +16,10 @@
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Map;
import com.microsoft.azure.storage.core.PathUtility;
+import com.microsoft.azure.storage.core.SR;
/**
* Represents storage credentials for delegated access to Blob service resources via a shared access signature.
@@ -38,6 +40,20 @@ public final class StorageCredentialsSharedAccessSignature extends StorageCreden
*/
public StorageCredentialsSharedAccessSignature(final String token) {
this.token = token;
+
+ if (token == null) {
+ this.setHttpsOnly(false);
+ }
+ else {
+ try {
+ MapStorageKey
object that represents the storage key to use.
- * @param stringToSign
- * The UTF-8-encoded string to sign.
- *
- * @return A String
that contains the HMAC-SHA256-encoded signature.
- *
- * @throws IllegalArgumentException
- * If the string to sign is not a valid Base64-encoded string.
- * @throws InvalidKeyException
- * If the key is not a valid storage key.
- */
- public static synchronized String computeMacSha256(final StorageKey storageKey, final String stringToSign)
- throws InvalidKeyException {
- if (storageKey.hmacSha256 == null) {
- storageKey.initHmacSha256();
- }
-
- byte[] utf8Bytes = null;
- try {
- utf8Bytes = stringToSign.getBytes(Constants.UTF8_CHARSET);
- }
- catch (final UnsupportedEncodingException e) {
- throw new IllegalArgumentException(e);
- }
-
- return Base64.encode(storageKey.hmacSha256.doFinal(utf8Bytes));
- }
-
- /**
- * Computes a signature for the specified string using the HMAC-SHA512 algorithm.
- *
- * @param storageKey
- * A StorageKey
object that represents the storage key to use.
- * @param stringToSign
- * The UTF-8-encoded string to sign.
- *
- * @return A String
that contains the HMAC-SHA512-encoded signature.
- *
- * @throws IllegalArgumentException
- * If the string to sign is not a valid Base64-encoded string.
- * @throws InvalidKeyException
- * If the key is not a valid storage key.
- */
- public static synchronized String computeMacSha512(final StorageKey storageKey, final String stringToSign)
- throws InvalidKeyException {
- if (storageKey.hmacSha512 == null) {
- storageKey.initHmacSha512();
- }
-
- byte[] utf8Bytes = null;
- try {
- utf8Bytes = stringToSign.getBytes(Constants.UTF8_CHARSET);
- }
- catch (final UnsupportedEncodingException e) {
- throw new IllegalArgumentException(e);
- }
-
- return Base64.encode(storageKey.hmacSha512.doFinal(utf8Bytes));
- }
-
- /**
- * Stores a reference to the hmacsha256 Mac.
- */
- private Mac hmacSha256;
-
- /**
- * Stores a reference to the hmacsha512 Mac.
- */
- private Mac hmacSha512;
-
- /**
- * Stores a reference to the hmacsha256 SecretKey.
- */
- private SecretKey key256;
-
- /**
- * Stores a reference to the hmacsha512 SecretKey.
- */
- private SecretKey key512;
-
- /**
- * Stores the key.
- */
- private byte[] key;
-
- /**
- * Creates an instance of the StorageKey
class.
- *
- * @param key
- * An array of bytes that represent the storage key.
- */
- public StorageKey(final byte[] key) {
- this.setKey(key);
- }
-
- /**
- * Returns the Base64-encoded key.
- *
- * @return A String
that represents the Base64-encoded key.
- */
- public String getBase64EncodedKey() {
- return Base64.encode(this.key);
- }
-
- /**
- * Returns the key.
- *
- * @return A byte array that represents the key.
- */
- public byte[] getKey() {
- final byte[] copy = this.key.clone();
- return copy;
- }
-
- /**
- * Initializes the HMAC-SHA256 Mac and SecretKey.
- *
- * @throws InvalidKeyException
- * If the key is not a valid SecretKey according to specification.
- */
- private void initHmacSha256() throws InvalidKeyException {
- this.key256 = new SecretKeySpec(this.key, "HmacSHA256");
- try {
- this.hmacSha256 = Mac.getInstance("HmacSHA256");
- }
- catch (final NoSuchAlgorithmException e) {
- throw new IllegalArgumentException();
- }
- this.hmacSha256.init(this.key256);
- }
-
- /**
- * Initializes the HMAC-SHA256 Mac and SecretKey.
- *
- * @throws InvalidKeyException
- * If the key is not a valid SecretKey according to specification.
- */
- private void initHmacSha512() throws InvalidKeyException {
- this.key512 = new SecretKeySpec(this.key, "HmacSHA512");
- try {
- this.hmacSha512 = Mac.getInstance("HmacSHA512");
- }
- catch (final NoSuchAlgorithmException e) {
- throw new IllegalArgumentException();
- }
- this.hmacSha512.init(this.key512);
- }
-
- /**
- * Sets the key to be used, using the specified byte array as the key.
- *
- * This method is provided to support key rotation. This method is not thread-safe.
- *
- * @param key
- * A byte
array that represents the key being assigned.
- */
- public void setKey(final byte[] key) {
- this.key = key;
- this.hmacSha256 = null;
- this.hmacSha512 = null;
- this.key256 = null;
- this.key512 = null;
- }
-
- /**
- * Sets the key to be used, using the specified String
as the key.
- *
- * This method is provided to support key rotation. This method is not thread-safe.
- *
- * @param key
- * A String
that represents the key being assigned.
- */
- public void setKey(final String key) {
- this.key = Base64.decode(key);
- }
-}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/CloudAnalyticsClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/CloudAnalyticsClient.java
index 6033e786f..db7efd5d0 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/CloudAnalyticsClient.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/CloudAnalyticsClient.java
@@ -133,31 +133,44 @@ public CloudTable getHourMetricsTable(StorageService service, StorageLocation lo
switch (service) {
case BLOB:
if (location == StorageLocation.PRIMARY) {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_BLOB);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_BLOB);
}
else {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_BLOB);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_BLOB);
}
+
+ case FILE:
+ if (location == StorageLocation.PRIMARY) {
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_FILE);
+ }
+ else {
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_FILE);
+ }
+
case QUEUE:
if (location == StorageLocation.PRIMARY) {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_QUEUE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_QUEUE);
}
else {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_QUEUE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_QUEUE);
}
+
case TABLE:
if (location == StorageLocation.PRIMARY) {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_TABLE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_TABLE);
}
else {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_TABLE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_TABLE);
}
+
default:
throw new IllegalArgumentException(SR.INVALID_STORAGE_SERVICE);
}
@@ -199,30 +212,39 @@ public CloudTable getMinuteMetricsTable(StorageService service, StorageLocation
switch (service) {
case BLOB:
if (location == StorageLocation.PRIMARY) {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_BLOB);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_BLOB);
+ }
+ else {
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_BLOB);
+ }
+ case FILE:
+ if (location == StorageLocation.PRIMARY) {
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_FILE);
}
else {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_BLOB);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_FILE);
}
case QUEUE:
if (location == StorageLocation.PRIMARY) {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_QUEUE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_QUEUE);
}
else {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_QUEUE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_QUEUE);
}
case TABLE:
if (location == StorageLocation.PRIMARY) {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_TABLE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_TABLE);
}
else {
- return this.tableClient
- .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_TABLE);
+ return this.tableClient.getTableReference(
+ Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_TABLE);
}
default:
throw new IllegalArgumentException(SR.INVALID_STORAGE_SERVICE);
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/StorageService.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/StorageService.java
index 794bdff5d..abffcb0f5 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/StorageService.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/analytics/StorageService.java
@@ -22,6 +22,11 @@ public enum StorageService {
* Blob service.
*/
BLOB,
+
+ /**
+ * File service.
+ */
+ FILE,
/**
* Queue Service.
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudAppendBlob.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudAppendBlob.java
index 95d372632..16af8d792 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudAppendBlob.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudAppendBlob.java
@@ -146,24 +146,23 @@ public CloudAppendBlob(final StorageUri blobAbsoluteUri, final String snapshotID
throws StorageException {
super(BlobType.APPEND_BLOB, blobAbsoluteUri, snapshotID, credentials);
}
-
+
/**
- * Creates an instance of the CloudAppendBlob
class using the specified URI, snapshot ID, and cloud blob
- * client.
- *
- * @param blobAbsoluteUri
- * A {@link StorageUri} object which represents the absolute URI to the blob.
+ * Creates an instance of the CloudAppendBlob
class using the specified type, name, snapshot ID, and
+ * container.
+ *
+ * @param blobName
+ * Name of the blob.
* @param snapshotID
- * A String
which represents the snapshot version, if applicable.
- * @param client
- * A {@link CloudBlobContainer} object which represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
+ * A String
that represents the snapshot version, if applicable.
+ * @param container
+ * The reference to the parent container.
+ * @throws URISyntaxException
+ * If the resource URI is invalid.
*/
- protected CloudAppendBlob(final StorageUri blobAbsoluteUri, final String snapshotID, final CloudBlobClient client)
- throws StorageException {
- super(BlobType.APPEND_BLOB, blobAbsoluteUri, snapshotID, client);
+ protected CloudAppendBlob(String blobName, String snapshotID, CloudBlobContainer container)
+ throws URISyntaxException {
+ super(BlobType.APPEND_BLOB, blobName, snapshotID, container);
}
/**
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java
index 43e7abc51..3a0433d34 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java
@@ -34,8 +34,10 @@
import com.microsoft.azure.storage.AccessCondition;
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.DoesServiceRequest;
+import com.microsoft.azure.storage.IPRange;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.SharedAccessPolicy;
+import com.microsoft.azure.storage.SharedAccessProtocols;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
@@ -110,108 +112,33 @@ public abstract class CloudBlob implements ListBlobItem {
* Represents the blob client.
*/
protected CloudBlobClient blobServiceClient;
-
- /**
- * Creates an instance of the CloudBlob
class.
- *
- * @param type
- * A {@link BlobType} value which represents the type of the blob.
- */
- protected CloudBlob(final BlobType type) {
- this.properties = new BlobProperties(type);
- }
-
- /**
- * Creates an instance of the CloudBlob
class using the specified URI and cloud blob client.
- *
- * @param type
- * A {@link BlobType} value which represents the type of the blob.
- * @param uri
- * A {@link StorageUri} object that represents the URI to the blob, beginning with the container name.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- */
- protected CloudBlob(final BlobType type, final StorageUri uri, final CloudBlobClient client)
- throws StorageException {
- this(type);
- this.parseQueryAndVerify(uri, client == null ? null : client.getCredentials());
-
- // Override the client set in parseQueryAndVerify to make sure request options are propagated.
- if (client != null) {
- this.blobServiceClient = client;
- }
- }
-
- /**
- * Creates an instance of the CloudBlob
class using the specified URI, cloud blob client, and cloud
- * blob container.
- *
- * @param type
- * A {@link BlobType} value which represents the type of the blob.
- * @param uri
- * A {@link StorageUri} object that represents the URI to the blob, beginning with the container name.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- * @param container
- * A {@link CloudBlobContainer} object that represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
- */
- protected CloudBlob(final BlobType type, final StorageUri uri, final CloudBlobClient client,
- final CloudBlobContainer container) throws StorageException {
- this(type, uri, client);
- this.container = container;
- }
/**
- * Creates an instance of the CloudBlob
class using the specified URI, snapshot ID, and cloud blob
- * client.
+ * Creates an instance of the CloudBlob
class using the specified type, name, snapshot ID, and
+ * container.
*
* @param type
* A {@link BlobType} value which represents the type of the blob.
- * @param uri
- * A {@link StorageUri} object that represents the URI to the blob, beginning with the container name.
+ * @param blobName
+ * Name of the blob.
* @param snapshotID
* A String
that represents the snapshot version, if applicable.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- */
- protected CloudBlob(final BlobType type, final StorageUri uri, final String snapshotID, final CloudBlobClient client)
- throws StorageException {
- this(type, uri, client);
- if (snapshotID != null) {
- if (this.snapshotID != null) {
- throw new IllegalArgumentException(SR.SNAPSHOT_QUERY_OPTION_ALREADY_DEFINED);
- }
- else {
- this.snapshotID = snapshotID;
- }
- }
- }
-
- /**
- * Creates an instance of the CloudBlob
class using the specified URI and cloud blob client.
- *
- * @param type
- * A {@link BlobType} value which represents the type of the blob.
- * @param uri
- * A {@link StorageUri} object that represents the URI to the blob, beginning with the container name.
- * @param credentials
- * A {@link StorageCredentials} object used to authenticate access.
- *
- * @throws StorageException
- * If a storage service error occurred.
+ * @param container
+ * The reference to the parent container.
+ * @throws URISyntaxException
+ * If the resource URI is invalid.
*/
- protected CloudBlob(final BlobType type, final StorageUri uri, final StorageCredentials credentials)
- throws StorageException {
- this(type, uri, null /* snapshotID */, credentials);
+ protected CloudBlob(final BlobType type, String blobName, String snapshotID, CloudBlobContainer container)
+ throws URISyntaxException {
+ Utility.assertNotNullOrEmpty("blobName", blobName);
+ Utility.assertNotNull("container", container);
+
+ this.storageUri = PathUtility.appendPathToUri(container.getStorageUri(), blobName);
+ this.name = blobName;
+ this.blobServiceClient = container.getServiceClient();
+ this.container = container;
+ this.snapshotID = snapshotID;
+ this.properties = new BlobProperties(type);
}
/**
@@ -231,7 +158,7 @@ protected CloudBlob(final BlobType type, final StorageUri uri, final StorageCred
*/
protected CloudBlob(final BlobType type, final StorageUri uri, final String snapshotID,
final StorageCredentials credentials) throws StorageException {
- this(type);
+ this.properties = new BlobProperties(type);
this.parseQueryAndVerify(uri, credentials);
if (snapshotID != null) {
@@ -708,123 +635,6 @@ public String preProcessResponse(CloudBlob blob, CloudBlobClient client, Operati
return putRequest;
}
- /**
- * Requests the service to start copying a blob's contents, properties, and metadata to a new blob.
- *
- * @param sourceBlob
- * A CloudBlob
object that represents the source blob to copy.
- *
- * @return A String
which represents the copy ID associated with the copy operation.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- *
- * @deprecated as of 3.0.0. Use {@link CloudBlob#startCopy(URI)} instead.
- */
- @Deprecated
- @DoesServiceRequest
- public final String startCopyFromBlob(final CloudBlob sourceBlob) throws StorageException, URISyntaxException {
- return this.startCopyFromBlob(sourceBlob, null /* sourceAccessCondition */,
- null /* destinationAccessCondition */, null /* options */, null /* opContext */);
- }
-
- /**
- * Requests the service to start copying a blob's contents, properties, and metadata to a new blob, using the
- * specified access conditions, lease ID, request options, and operation context.
- *
- * @param sourceBlob
- * A CloudBlob
object that represents the source blob to copy.
- * @param sourceAccessCondition
- * An {@link AccessCondition} object that represents the access conditions for the source blob.
- * @param destinationAccessCondition
- * An {@link AccessCondition} object that represents the access conditions for the destination blob.
- * @param options
- * A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null
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 A String
which represents the copy ID associated with the copy operation.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- *
- * @deprecated as of 3.0.0. Use {@link CloudBlob#startCopy(
- * URI, AccessCondition, AccessCondition, BlobRequestOptions, OperationContext)} instead.
- */
- @Deprecated
- @DoesServiceRequest
- public final String startCopyFromBlob(final CloudBlob sourceBlob, final AccessCondition sourceAccessCondition,
- final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
- throws StorageException, URISyntaxException {
- Utility.assertNotNull("sourceBlob", sourceBlob);
- return this.startCopy(
- sourceBlob.getServiceClient().getCredentials().transformUri(sourceBlob.getQualifiedUri()),
- sourceAccessCondition, destinationAccessCondition, options, opContext);
- }
-
- /**
- * Requests the service to start copying a URI's contents, properties, and metadata to a new blob.
- *
- * @param source
- * A java.net.URI
The source URI. URIs for resources outside of Azure
- * may only be copied into block blobs.
- *
- * @return A String
which represents the copy ID associated with the copy operation.
- *
- * @throws StorageException
- * If a storage service error occurred.
- *
- * @deprecated as of 3.0.0. Use {@link CloudBlob#startCopy(URI)} instead.
- */
- @Deprecated
- @DoesServiceRequest
- public final String startCopyFromBlob(final URI source) throws StorageException {
- return this.startCopy(source, null /* sourceAccessCondition */, null /* destinationAccessCondition */,
- null /* options */, null /* opContext */);
- }
-
- /**
- * Requests the service to start copying a URI's contents, properties, and metadata to a new blob, using the
- * specified access conditions, lease ID, request options, and operation context.
- *
- * @param source
- * A java.net.URI
The source URI. URIs for resources outside of Azure
- * may only be copied into block blobs.
- * @param sourceAccessCondition
- * An {@link AccessCondition} object that represents the access conditions for the source.
- * @param destinationAccessCondition
- * An {@link AccessCondition} object that represents the access conditions for the destination.
- * @param options
- * A {@link BlobRequestOptions} object that specifies any additional options for the request.
- * Specifying null
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 A String
which represents the copy ID associated with the copy operation.
- *
- * @throws StorageException
- * If a storage service error occurred.
- *
- * @deprecated as of 3.0.0. Use {@link CloudBlob#startCopy(
- * URI, AccessCondition, AccessCondition, BlobRequestOptions, OperationContext)} instead.
- */
- @Deprecated
- @DoesServiceRequest
- public final String startCopyFromBlob(final URI source, final AccessCondition sourceAccessCondition,
- final AccessCondition destinationAccessCondition, BlobRequestOptions options, OperationContext opContext)
- throws StorageException {
- return this.startCopy(source, sourceAccessCondition, destinationAccessCondition, options, opContext);
- }
-
/**
* Requests the service to start copying a URI's contents, properties, and metadata to a new blob.
*
@@ -1035,7 +845,6 @@ public void signRequest(HttpURLConnection connection, CloudBlobClient client, Op
StorageRequest.signBlobQueueAndFileRequest(connection, client, 0L, context);
}
- @SuppressWarnings("deprecation")
@Override
public CloudBlob preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context)
throws Exception {
@@ -1046,13 +855,13 @@ public CloudBlob preProcessResponse(CloudBlob blob, CloudBlobClient client, Oper
CloudBlob snapshot = null;
final String snapshotTime = BlobResponse.getSnapshotTime(this.getConnection());
if (blob instanceof CloudBlockBlob) {
- snapshot = new CloudBlockBlob(blob.getStorageUri(), snapshotTime, client);
+ snapshot = new CloudBlockBlob(blob.getName(), snapshotTime, CloudBlob.this.getContainer());
}
else if (blob instanceof CloudPageBlob) {
- snapshot = new CloudPageBlob(blob.getStorageUri(), snapshotTime, client);
+ snapshot = new CloudPageBlob(blob.getName(), snapshotTime, CloudBlob.this.getContainer());
}
else if (blob instanceof CloudAppendBlob) {
- snapshot = new CloudAppendBlob(blob.getStorageUri(), snapshotTime, client);
+ snapshot = new CloudAppendBlob(blob.getName(), snapshotTime, CloudBlob.this.getContainer());
}
snapshot.setProperties(blob.properties);
@@ -2060,20 +1869,53 @@ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy,
return this.generateSharedAccessSignature(policy, null /* headers */, groupPolicyIdentifier);
}
+
+ /**
+ * Returns a shared access signature for the blob using the specified group policy identifier and operation context.
+ * Note this does not contain the leading "?".
+ *
+ * @param policy
+ * A SharedAccessPolicy
object that represents the access policy for the shared access
+ * signature.
+ * @param headers
+ * A {@link SharedAccessBlobHeaders}
object that represents the optional header values to
+ * set for a blob accessed with this shared access signature.
+ * @param groupPolicyIdentifier
+ * A String
that represents the container-level access policy.
+ *
+ * @return A String
that represents the shared access signature.
+ *
+ * @throws IllegalArgumentException
+ * If the credentials are invalid or the blob is a snapshot.
+ * @throws InvalidKeyException
+ * If the credentials are invalid.
+ * @throws StorageException
+ * If a storage service error occurred.
+ */
+ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy, final SharedAccessBlobHeaders headers,
+ final String groupPolicyIdentifier)
+ throws InvalidKeyException, StorageException {
+ return this.generateSharedAccessSignature(policy, headers, groupPolicyIdentifier,
+ null /* IP range */, null /* protocols */);
+ }
+
/**
* Returns a shared access signature for the blob using the specified group policy identifier and operation context.
* Note this does not contain the leading "?".
*
* @param policy
* A {@link SharedAccessPolicy}
object that represents the access policy for the shared
- * access
- * signature.
+ * access signature.
* @param headers
* A {@link SharedAccessBlobHeaders}
object that represents the optional header values to
* set for a blob accessed with this shared access signature.
* @param groupPolicyIdentifier
* A String
that represents the container-level access policy.
+ * @param ipRange
+ * A {@link IPRange} object containing the range of allowed IP addresses.
+ * @param protocols
+ * A {@link SharedAccessProtocols} representing the allowed Internet protocols.
*
* @return A String
that represents the shared access signature.
*
@@ -2084,25 +1926,26 @@ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy,
* @throws StorageException
* If a storage service error occurred.
*/
- public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy,
- final SharedAccessBlobHeaders headers, final String groupPolicyIdentifier) throws InvalidKeyException,
- StorageException {
+ public String generateSharedAccessSignature(
+ final SharedAccessBlobPolicy policy, final SharedAccessBlobHeaders headers,
+ final String groupPolicyIdentifier, final IPRange ipRange, final SharedAccessProtocols protocols)
+ throws InvalidKeyException, StorageException {
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.blobServiceClient.getCredentials())) {
throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
}
-
+
if (this.isSnapshot()) {
throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_FOR_SNAPSHOTS);
}
final String resourceName = this.getCanonicalName(true);
- final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(policy, headers,
- groupPolicyIdentifier, resourceName, this.blobServiceClient);
+ final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
+ policy, headers, groupPolicyIdentifier, resourceName, ipRange, protocols, this.blobServiceClient);
- final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(policy,
- headers, groupPolicyIdentifier, "b", signature);
+ final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(
+ policy, headers, groupPolicyIdentifier, "b", ipRange, protocols, signature);
return builder.toString();
}
@@ -2148,13 +1991,12 @@ String getCanonicalName(final boolean ignoreSnapshotTime) {
* @throws URISyntaxException
* If the resource URI is invalid.
*/
- @SuppressWarnings("deprecation")
@Override
public final CloudBlobContainer getContainer() throws StorageException, URISyntaxException {
if (this.container == null) {
final StorageUri containerURI = PathUtility.getContainerURI(this.getStorageUri(),
this.blobServiceClient.isUsePathStyleUris());
- this.container = new CloudBlobContainer(containerURI, this.blobServiceClient);
+ this.container = new CloudBlobContainer(containerURI, this.blobServiceClient.getCredentials());
}
return this.container;
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobClient.java
index 05841ca61..a01ddd021 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobClient.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobClient.java
@@ -128,7 +128,6 @@ public CloudBlobClient(final StorageUri storageUri, StorageCredentials credentia
* @see Naming and Referencing Containers, Blobs,
* and Metadata
*/
- @SuppressWarnings("deprecation")
public CloudBlobContainer getContainerReference(final String containerName) throws URISyntaxException,
StorageException {
return new CloudBlobContainer(containerName, this);
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobContainer.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobContainer.java
index 1d654d6b2..6ec136a0a 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobContainer.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlobContainer.java
@@ -31,12 +31,14 @@
import com.microsoft.azure.storage.AccessCondition;
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.DoesServiceRequest;
+import com.microsoft.azure.storage.IPRange;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.ResultContinuation;
import com.microsoft.azure.storage.ResultContinuationType;
import com.microsoft.azure.storage.ResultSegment;
import com.microsoft.azure.storage.SharedAccessPolicyHandler;
import com.microsoft.azure.storage.SharedAccessPolicySerializer;
+import com.microsoft.azure.storage.SharedAccessProtocols;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
@@ -75,10 +77,10 @@ static BlobContainerPermissions getContainerAcl(final String aclString) {
if (!Utility.isNullOrEmpty(aclString)) {
final String lowerAclString = aclString.toLowerCase();
- if ("container".equals(lowerAclString)) {
+ if (SR.CONTAINER.equals(lowerAclString)) {
accessType = BlobContainerPublicAccessType.CONTAINER;
}
- else if ("blob".equals(lowerAclString)) {
+ else if (SR.BLOB.equals(lowerAclString)) {
accessType = BlobContainerPublicAccessType.BLOB;
}
else {
@@ -196,10 +198,8 @@ public CloudBlobContainer(final StorageUri storageUri, final StorageCredentials
*
* @see Naming and Referencing Containers, Blobs,
* and Metadata
- * @deprecated as of 3.0.0. Please use {@link CloudBlobClient#getContainerReference(String)}
*/
- @Deprecated
- public CloudBlobContainer(final String containerName, final CloudBlobClient client) throws URISyntaxException,
+ protected CloudBlobContainer(final String containerName, final CloudBlobClient client) throws URISyntaxException,
StorageException {
Utility.assertNotNull("client", client);
Utility.assertNotNull("containerName", containerName);
@@ -208,52 +208,6 @@ public CloudBlobContainer(final String containerName, final CloudBlobClient clie
this.name = containerName;
this.blobServiceClient = client;
}
-
- /**
- * Creates an instance of the CloudBlobContainer
class using the specified URI and client.
- *
- * @param uri
- * A java.net.URI
object that represents the absolute URI of the container.
- * @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 is invalid.
- * @deprecated as of 3.0.0. Please use {@link CloudBlobContainer#CloudBlobContainer(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudBlobContainer(final URI uri, final CloudBlobClient client) throws URISyntaxException, StorageException {
- this(new StorageUri(uri), client);
- }
-
- /**
- * Creates an instance of the CloudBlobContainer
class using the specified URI and client.
- *
- * @param storageUri
- * A {@link StorageUri} object which represents the absolute URI of the container.
- * @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 is invalid.
- * @deprecated as of 3.0.0. Please use {@link CloudBlobContainer#CloudBlobContainer(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudBlobContainer(final StorageUri storageUri, final CloudBlobClient client) throws URISyntaxException,
- StorageException {
- this.parseQueryAndVerify(storageUri, client == null ? null : client.getCredentials());
-
- // Override the client set in parseQueryAndVerify to make sure request options are propagated.
- if (client != null) {
- this.blobServiceClient = client;
- }
- }
/**
* Creates the container.
@@ -434,15 +388,15 @@ public void delete(AccessCondition accessCondition, BlobRequestOptions options,
options.getRetryPolicyFactory(), opContext);
}
- private StorageRequestString
which represents the container-level access policy.
+ * @param ipRange
+ * A {@link IPRange} object containing the range of allowed IP addresses.
+ * @param protocols
+ * A {@link SharedAccessProtocols} representing the allowed Internet protocols.
+ *
+ * @return A String
which represents a shared access signature for the container.
+ *
+ * @throws StorageException
+ * If a storage service error occurred.
+ * @throws InvalidKeyException
+ * If the key is invalid.
+ */
+ public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy,
+ final String groupPolicyIdentifier, final IPRange ipRange, final SharedAccessProtocols protocols)
+ throws InvalidKeyException, StorageException {
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.blobServiceClient.getCredentials())) {
final String errorMessage = SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY;
throw new IllegalArgumentException(errorMessage);
}
-
+
final String resourceName = this.getSharedAccessCanonicalName();
- final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(policy,
- null /* SharedAccessBlobHeaders */, groupPolicyIdentifier, resourceName, this.blobServiceClient);
+ final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
+ policy, null /* SharedAccessBlobHeaders */, groupPolicyIdentifier, resourceName,
+ ipRange, protocols, this.blobServiceClient);
final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(policy,
- null /* SharedAccessBlobHeaders */, groupPolicyIdentifier, "c", signature);
+ null /* SharedAccessBlobHeaders */, groupPolicyIdentifier, "c", ipRange, protocols, signature);
return builder.toString();
}
@@ -880,13 +862,7 @@ public CloudAppendBlob getAppendBlobReference(final String blobName) throws URIS
*/
public CloudAppendBlob getAppendBlobReference(final String blobName, final String snapshotID)
throws URISyntaxException, StorageException {
- Utility.assertNotNullOrEmpty("blobName", blobName);
-
- final StorageUri address = PathUtility.appendPathToUri(this.storageUri, blobName);
-
- final CloudAppendBlob retBlob = new CloudAppendBlob(address, snapshotID, this.blobServiceClient);
- retBlob.setContainer(this);
- return retBlob;
+ return new CloudAppendBlob(blobName, snapshotID, this);
}
/**
@@ -922,16 +898,9 @@ public CloudBlockBlob getBlockBlobReference(final String blobName) throws URISyn
* @throws URISyntaxException
* If the resource URI is invalid.
*/
- @SuppressWarnings("deprecation")
public CloudBlockBlob getBlockBlobReference(final String blobName, final String snapshotID)
throws URISyntaxException, StorageException {
- Utility.assertNotNullOrEmpty("blobName", blobName);
-
- final StorageUri address = PathUtility.appendPathToUri(this.storageUri, blobName);
-
- final CloudBlockBlob retBlob = new CloudBlockBlob(address, snapshotID, this.blobServiceClient);
- retBlob.setContainer(this);
- return retBlob;
+ return new CloudBlockBlob(blobName, snapshotID, this);
}
/**
@@ -1019,16 +988,9 @@ public CloudPageBlob getPageBlobReference(final String blobName) throws URISynta
* @throws URISyntaxException
* If the resource URI is invalid.
*/
- @SuppressWarnings("deprecation")
public CloudPageBlob getPageBlobReference(final String blobName, final String snapshotID)
throws URISyntaxException, StorageException {
- Utility.assertNotNullOrEmpty("blobName", blobName);
-
- final StorageUri address = PathUtility.appendPathToUri(this.storageUri, blobName);
-
- final CloudPageBlob retBlob = new CloudPageBlob(address, snapshotID, this.blobServiceClient);
- retBlob.setContainer(this);
- return retBlob;
+ return new CloudPageBlob(blobName, snapshotID, this);
}
/**
@@ -1611,8 +1573,8 @@ private StorageRequestCloudBlockBlob
class using the specified absolute URI and storage service
- * client.
- *
- * @param blobAbsoluteUri
- * A java.net.URI
object that represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudBlockBlob#CloudBlockBlob(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudBlockBlob(final URI blobAbsoluteUri, final CloudBlobClient client) throws StorageException {
- this(new StorageUri(blobAbsoluteUri), client);
- }
-
- /**
- * Creates an instance of the CloudBlockBlob
class using the specified absolute StorageUri and storage
- * service client.
- *
- * @param blobAbsoluteUri
- * A {@link StorageUri} object that represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudBlockBlob#CloudBlockBlob(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudBlockBlob(final StorageUri blobAbsoluteUri, final CloudBlobClient client) throws StorageException {
- super(BlobType.BLOCK_BLOB, blobAbsoluteUri, client);
- }
-
- /**
- * Creates an instance of the CloudBlockBlob
class using the specified absolute URI, storage service
- * client and container.
- *
- * @param blobAbsoluteUri
- * A java.net.URI
object that represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- * @param container
- * A {@link CloudBlobContainer} object that represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudBlockBlob#CloudBlockBlob(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudBlockBlob(final URI blobAbsoluteUri, final CloudBlobClient client, final CloudBlobContainer container)
- throws StorageException {
- this(new StorageUri(blobAbsoluteUri), client, container);
- }
-
- /**
- * Creates an instance of the CloudBlockBlob
class using the specified absolute StorageUri, storage
- * service client and container.
- *
- * @param blobAbsoluteUri
- * A {@link StorageUri} object that represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- * @param container
- * A {@link CloudBlobContainer} object that represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudBlockBlob#CloudBlockBlob(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudBlockBlob(final StorageUri blobAbsoluteUri, final CloudBlobClient client,
- final CloudBlobContainer container) throws StorageException {
- super(BlobType.BLOCK_BLOB, blobAbsoluteUri, client, container);
- }
-
- /**
- * Creates an instance of the CloudBlockBlob
class using the specified absolute URI, snapshot ID, and
- * storage service client.
- *
- * @param blobAbsoluteUri
- * A java.net.URI
object that represents the absolute URI to the blob.
- * @param snapshotID
- * A String
that represents the snapshot version, if applicable.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudBlockBlob#CloudBlockBlob(URI, String, StorageCredentials)}
- */
- @Deprecated
- public CloudBlockBlob(final URI blobAbsoluteUri, final String snapshotID, final CloudBlobClient client)
- throws StorageException {
- this(new StorageUri(blobAbsoluteUri), snapshotID, client);
- }
-
+
/**
- * Creates an instance of the CloudBlockBlob
class using the specified absolute StorageUri, snapshot
- * ID, and storage service client.
- *
- * @param blobAbsoluteUri
- * A {@link StorageUri} object that represents the absolute URI to the blob.
+ * Creates an instance of the CloudBlockBlob
class using the specified type, name, snapshot ID, and
+ * container.
+ *
+ * @param blobName
+ * Name of the blob.
* @param snapshotID
* A String
that represents the snapshot version, if applicable.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudBlockBlob#CloudBlockBlob(StorageUri, String, StorageCredentials)}
+ * @param container
+ * The reference to the parent container.
+ * @throws URISyntaxException
+ * If the resource URI is invalid.
*/
- @Deprecated
- public CloudBlockBlob(final StorageUri blobAbsoluteUri, final String snapshotID, final CloudBlobClient client)
- throws StorageException {
- super(BlobType.BLOCK_BLOB, blobAbsoluteUri, snapshotID, client);
+ protected CloudBlockBlob(String blobName, String snapshotID, CloudBlobContainer container)
+ throws URISyntaxException {
+ super(BlobType.BLOCK_BLOB, blobName, snapshotID, container);
}
/**
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudPageBlob.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudPageBlob.java
index ddf859671..b435f650c 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudPageBlob.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudPageBlob.java
@@ -145,123 +145,23 @@ public CloudPageBlob(final StorageUri blobAbsoluteUri, final String snapshotID,
throws StorageException {
super(BlobType.PAGE_BLOB, blobAbsoluteUri, snapshotID, credentials);
}
-
- /**
- * Creates an instance of the CloudPageBlob
class using the specified URI and cloud blob client.
- *
- * @param blobAbsoluteUri
- * A java.net.URI
object which represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudPageBlob#CloudPageBlob(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudPageBlob(final URI blobAbsoluteUri, final CloudBlobClient client) throws StorageException {
- this(new StorageUri(blobAbsoluteUri), client);
- }
-
- /**
- * Creates an instance of the CloudPageBlob
class using the specified URI and cloud blob client.
- *
- * @param blobAbsoluteUri
- * A {@link StorageUri} object which represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudPageBlob#CloudPageBlob(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudPageBlob(final StorageUri blobAbsoluteUri, final CloudBlobClient client) throws StorageException {
- super(BlobType.PAGE_BLOB, blobAbsoluteUri, client);
- }
-
- /**
- * Creates an instance of the CloudPageBlob
class using the specified URI, cloud blob client, and cloud
- * blob container.
- *
- * @param blobAbsoluteUri
- * A java.net.URI
object which represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- * @param container
- * A {@link CloudBlobContainer} object which represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudPageBlob#CloudPageBlob(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudPageBlob(final URI blobAbsoluteUri, final CloudBlobClient client, final CloudBlobContainer container)
- throws StorageException {
- this(new StorageUri(blobAbsoluteUri), client, container);
- }
-
- /**
- * Creates an instance of the CloudPageBlob
class using the specified URI, cloud blob client, and cloud
- * blob container.
- *
- * @param blobAbsoluteUri
- * A {@link StorageUri} object which represents the absolute URI to the blob.
- * @param client
- * A {@link CloudBlobClient} object that specifies the endpoint for the Blob service.
- * @param container
- * A {@link CloudBlobContainer} object which represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudPageBlob#CloudPageBlob(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudPageBlob(final StorageUri blobAbsoluteUri, final CloudBlobClient client,
- final CloudBlobContainer container) throws StorageException {
- super(BlobType.PAGE_BLOB, blobAbsoluteUri, client, container);
- }
-
- /**
- * Creates an instance of the CloudPageBlob
class using the specified URI, snapshot ID, and cloud blob
- * client.
- *
- * @param blobAbsoluteUri
- * A java.net.URI
object which represents the absolute URI to the blob.
- * @param snapshotID
- * A String
which represents the snapshot version, if applicable.
- * @param client
- * A {@link CloudBlobContainer} object which represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudPageBlob#CloudPageBlob(URI, String, StorageCredentials)}
- */
- @Deprecated
- public CloudPageBlob(final URI blobAbsoluteUri, final String snapshotID, final CloudBlobClient client)
- throws StorageException {
- this(new StorageUri(blobAbsoluteUri), snapshotID, client);
- }
-
+
/**
- * Creates an instance of the CloudPageBlob
class using the specified URI, snapshot ID, and cloud blob
- * client.
- *
- * @param blobAbsoluteUri
- * A {@link StorageUri} object which represents the absolute URI to the blob.
+ * Creates an instance of the CloudPageBlob
class using the specified type, name, snapshot ID, and
+ * container.
+ *
+ * @param blobName
+ * Name of the blob.
* @param snapshotID
- * A String
which represents the snapshot version, if applicable.
- * @param client
- * A {@link CloudBlobContainer} object which represents the container to use for the blob.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @deprecated as of 3.0.0. Please use {@link CloudPageBlob#CloudPageBlob(StorageUri, String, StorageCredentials)}
+ * A String
that represents the snapshot version, if applicable.
+ * @param container
+ * The reference to the parent container.
+ * @throws URISyntaxException
+ * If the resource URI is invalid.
*/
- @Deprecated
- public CloudPageBlob(final StorageUri blobAbsoluteUri, final String snapshotID, final CloudBlobClient client)
- throws StorageException {
- super(BlobType.PAGE_BLOB, blobAbsoluteUri, snapshotID, client);
+ protected CloudPageBlob(String blobName, String snapshotID, CloudBlobContainer container)
+ throws URISyntaxException {
+ super(BlobType.PAGE_BLOB, blobName, snapshotID, container);
}
/**
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPermissions.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPermissions.java
index d9d46a05e..3b0088822 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPermissions.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPermissions.java
@@ -23,13 +23,23 @@ public enum SharedAccessBlobPermissions {
*/
READ,
+ /**
+ * Specifies Add access granted.
+ */
+ ADD,
+
+ /**
+ * Specifies Create access granted.
+ */
+ CREATE,
+
/**
* Specifies Write access granted.
*/
WRITE,
/**
- * Specifies Delete access granted for blobs.
+ * Specifies Delete access granted.
*/
DELETE,
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPolicy.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPolicy.java
index d1ecfa0c8..631daf43a 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPolicy.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/SharedAccessBlobPolicy.java
@@ -18,7 +18,6 @@
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.SharedAccessPolicy;
-import com.microsoft.azure.storage.blob.SharedAccessBlobPermissions;
/**
* Represents a shared access policy, which specifies the start time, expiry time, and permissions for a shared access
@@ -29,7 +28,7 @@ public final class SharedAccessBlobPolicy extends SharedAccessPolicy {
* The permissions for a shared access signature associated with this shared access policy.
*/
private EnumSetString
that represents the shared access permissions in the "rwdl" format,
+ * @return A String
that represents the shared access permissions in the "racwdl" format,
* which is described at {@link #setPermissionsFromString(String)}.
*/
@Override
@@ -63,13 +62,21 @@ public String permissionsToString() {
return Constants.EMPTY_STRING;
}
- // The service supports a fixed order => rwdl
+ // The service supports a fixed order => racwdl
final StringBuilder builder = new StringBuilder();
if (this.permissions.contains(SharedAccessBlobPermissions.READ)) {
builder.append("r");
}
+ if (this.permissions.contains(SharedAccessBlobPermissions.ADD)) {
+ builder.append("a");
+ }
+
+ if (this.permissions.contains(SharedAccessBlobPermissions.CREATE)) {
+ builder.append("c");
+ }
+
if (this.permissions.contains(SharedAccessBlobPermissions.WRITE)) {
builder.append("w");
}
@@ -90,36 +97,50 @@ public String permissionsToString() {
*
* @param value
* A String
that represents the shared access permissions. The string must contain one or
- * more of the following values. Note they must be lowercase, and the order that they are specified must
- * be in the order of "rwdl".
+ * more of the following values. Note they must all be lowercase.
*
- *
*/
+ @Override
public void setPermissionsFromString(final String value) {
- EnumSetd
: Delete access.l
: List access.r
: Read access.a
: Add access.c
: Create access.w
: Write access.d
: Delete access.l
: List access.false
*/
public static boolean canCredentialsSignRequest(final StorageCredentials creds) {
- if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
- return true;
- }
- else {
- return false;
- }
+ return creds.getClass().equals(StorageCredentialsAccountAndKey.class);
+ }
+
+ /**
+ * RESERVED, for internal use only. Gets a value indicating whether a
+ * client can be generated under the Shared Key or Shared Access Signature
+ * authentication schemes using the specified credentials.
+ * @return true
if a client can be generated with these
+ * credentials; otherwise, false
+ */
+ public static boolean canCredentialsGenerateClient(final StorageCredentials creds) {
+ return canCredentialsSignRequest(creds) || creds.getClass().equals(StorageCredentialsSharedAccessSignature.class);
}
/**
@@ -56,35 +63,22 @@ public static boolean canCredentialsSignRequest(final StorageCredentials creds)
* @throws InvalidKeyException
* If the key is not a valid Base64-encoded string.
*/
- public static String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException {
+ public static synchronized String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException {
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
- return StorageKey.computeMacSha256(((StorageCredentialsAccountAndKey) creds).getCredentials().getKey(),
- value);
+ byte[] utf8Bytes = null;
+ try {
+ utf8Bytes = value.getBytes(Constants.UTF8_CHARSET);
+ }
+ catch (final UnsupportedEncodingException e) {
+ throw new IllegalArgumentException(e);
+ }
+ return Base64.encode(((StorageCredentialsAccountAndKey) creds).getHmac256().doFinal(utf8Bytes));
}
else {
return null;
}
}
- /**
- * Signs a request under the Shared Key authentication scheme.
- *
- * @param request
- * An HttpURLConnection
object that represents the request to sign.
- * @param contentLength
- * The length of the content written to the output stream. If unknown, specify -1.
- *
- * @throws InvalidKeyException
- * If the given key is invalid.
- * @throws StorageException
- * If a storage service error occurred.
- */
- public static void signBlobAndQueueRequest(final StorageCredentials creds,
- final java.net.HttpURLConnection request, final long contentLength) throws InvalidKeyException,
- StorageException {
- signBlobQueueAndFileRequest(creds, request, contentLength, null);
- }
-
/**
* Signs a request using the specified operation context under the Shared Key authentication scheme.
*
@@ -108,29 +102,20 @@ public static void signBlobQueueAndFileRequest(final StorageCredentials creds,
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
opContext = opContext == null ? new OperationContext() : opContext;
- BaseRequest.signRequestForBlobAndQueue(
- request, (StorageCredentialsAccountAndKey) creds, contentLength, opContext);
- }
- }
+ request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime());
+ final Canonicalizer canonicalizer = CanonicalizerFactory.getBlobQueueFileCanonicalizer(request);
- /**
- * Signs a request under the Shared Key authentication scheme.
- *
- * @param request
- * An HttpURLConnection
object that represents the request to sign.
- * @param contentLength
- * The length of the content written to the output stream. If unknown, specify -1.
- *
- * @throws InvalidKeyException
- * If the given key is invalid.
- * @throws StorageException
- * If a storage service error occurred.
- */
- public static void signTableRequest(final StorageCredentials creds, final java.net.HttpURLConnection request,
- final long contentLength) throws InvalidKeyException, StorageException {
- signTableRequest(creds, request, contentLength, null);
- }
+ final String stringToSign = canonicalizer.canonicalize(request, creds.getAccountName(), contentLength);
+
+ final String computedBase64Signature = StorageCredentialsHelper.computeHmac256(creds, stringToSign);
+ Logger.trace(opContext, LogConstants.SIGNING, stringToSign);
+
+ request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION,
+ String.format("%s %s:%s", "SharedKey", creds.getAccountName(), computedBase64Signature));
+ }
+ }
+
/**
* Signs a request using the specified operation context under the Shared Key authentication scheme.
*
@@ -152,8 +137,18 @@ public static void signTableRequest(final StorageCredentials creds, final java.n
final long contentLength, OperationContext opContext) throws InvalidKeyException, StorageException {
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
opContext = opContext == null ? new OperationContext() : opContext;
- BaseRequest.signRequestForTableSharedKey(request,
- (StorageCredentialsAccountAndKey) creds, contentLength, opContext);
+ request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime());
+
+ final Canonicalizer canonicalizer = CanonicalizerFactory.getTableCanonicalizer(request);
+
+ final String stringToSign = canonicalizer.canonicalize(request, creds.getAccountName(), contentLength);
+
+ final String computedBase64Signature = StorageCredentialsHelper.computeHmac256(creds, stringToSign);
+
+ Logger.trace(opContext, LogConstants.SIGNING, stringToSign);
+
+ request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION,
+ String.format("%s %s:%s", "SharedKey", creds.getAccountName(), computedBase64Signature));
}
}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/Utility.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/Utility.java
index 5d8a28f27..857020da4 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/Utility.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/Utility.java
@@ -54,10 +54,6 @@
import com.microsoft.azure.storage.RequestOptions;
import com.microsoft.azure.storage.ResultContinuation;
import com.microsoft.azure.storage.ResultContinuationType;
-import com.microsoft.azure.storage.StorageCredentials;
-import com.microsoft.azure.storage.StorageCredentialsAccountAndKey;
-import com.microsoft.azure.storage.StorageCredentialsAnonymous;
-import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.azure.storage.StorageErrorCode;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
import com.microsoft.azure.storage.StorageException;
@@ -222,42 +218,6 @@ public static StreamMd5AndLength analyzeStream(final InputStream sourceStream, l
return retVal;
}
- /**
- * Returns a value that indicates whether the specified credentials are equal.
- *
- * @param thisCred
- * An object derived from {@link StorageCredentials} that represents the first set of credentials being
- * compared for equality.
- * @param thatCred
- * An object derived from StorageCredentials
that represents the second set of credentials
- * being compared for equality.
- *
- * @return true
if the credentials are equal; otherwise, false
.
- */
- public static boolean areCredentialsEqual(final StorageCredentials thisCred, final StorageCredentials thatCred) {
- if (thisCred == thatCred) {
- return true;
- }
-
- if (thisCred == null || thatCred == null || thisCred.getClass() != thatCred.getClass()) {
- return false;
- }
-
- if (thisCred instanceof StorageCredentialsAccountAndKey) {
- return ((StorageCredentialsAccountAndKey) thisCred).toString(true).equals(
- ((StorageCredentialsAccountAndKey) thatCred).toString(true));
- }
- else if (thisCred instanceof StorageCredentialsSharedAccessSignature) {
- return ((StorageCredentialsSharedAccessSignature) thisCred).getToken().equals(
- ((StorageCredentialsSharedAccessSignature) thatCred).getToken());
- }
- else if (thisCred instanceof StorageCredentialsAnonymous) {
- return true;
- }
-
- return thisCred.equals(thatCred);
- }
-
/**
* Asserts a continuation token is of the specified type.
*
@@ -488,24 +448,6 @@ public static StorageException generateNewUnexpectedStorageException(final Excep
return exceptionRef;
}
- /**
- * Returns a byte array that represents the data of a long
value.
- *
- * @param value
- * The value from which the byte array will be returned.
- *
- * @return A byte array that represents the data of the specified long
value.
- */
- public static byte[] getBytesFromLong(final long value) {
- final byte[] tempArray = new byte[8];
-
- for (int m = 0; m < 8; m++) {
- tempArray[7 - m] = (byte) ((value >> (8 * m)) & 0xFF);
- }
-
- return tempArray;
- }
-
/**
* Returns the current GMT date/time String using the RFC1123 pattern.
*
@@ -615,22 +557,6 @@ public static XMLStreamWriter createXMLStreamWriter(StringWriter outWriter) thro
return xmlOutputFactory.createXMLStreamWriter(outWriter);
}
- /**
- * Returns a XMLStreamWriter
with the specified OutputStream
and charset.
- *
- * @param outStream
- * The OutputStream
to use to create the XMLStreamWriter
instance.
- * @param charset
- * The charset to use to create the XMLStreamWriter
instance.
- * @return A XMLStreamWriter
instance
- *
- * @throws XMLStreamException
- */
- public static XMLStreamWriter createXMLStreamWriter(OutputStream outStream, String charset)
- throws XMLStreamException {
- return xmlOutputFactory.createXMLStreamWriter(outStream, charset);
- }
-
/**
* Creates an instance of the IOException
class using the specified exception.
*
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java
index 19093a93b..c8b894c83 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFile.java
@@ -36,7 +36,9 @@
import com.microsoft.azure.storage.AccessCondition;
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.DoesServiceRequest;
+import com.microsoft.azure.storage.IPRange;
import com.microsoft.azure.storage.OperationContext;
+import com.microsoft.azure.storage.SharedAccessProtocols;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.azure.storage.StorageErrorCode;
@@ -65,7 +67,7 @@
/**
* Represents a Microsoft Azure File.
*/
-public class CloudFile implements ListFileItem {
+public final class CloudFile implements ListFileItem {
/**
* Holds the number of bytes to buffer when writing to a {@link FileOutputStream}.
*/
@@ -119,8 +121,10 @@ public class CloudFile implements ListFileItem {
*
* @throws StorageException
* If a storage service error occurred.
+ * @throws URISyntaxException
+ * If the resource URI is invalid.
*/
- public CloudFile(final URI fileAbsoluteUri) throws StorageException {
+ public CloudFile(final URI fileAbsoluteUri) throws StorageException, URISyntaxException {
this(new StorageUri(fileAbsoluteUri));
}
@@ -132,9 +136,11 @@ public CloudFile(final URI fileAbsoluteUri) throws StorageException {
*
* @throws StorageException
* If a storage service error occurred.
+ * @throws URISyntaxException
+ * If the resource URI is invalid.
*/
- public CloudFile(final StorageUri fileAbsoluteUri) throws StorageException {
- this(fileAbsoluteUri, (StorageCredentials)null);
+ public CloudFile(final StorageUri fileAbsoluteUri) throws StorageException, URISyntaxException {
+ this(fileAbsoluteUri, null);
}
/**
@@ -168,95 +174,6 @@ public CloudFile(final URI fileAbsoluteUri, final StorageCredentials credentials
public CloudFile(final StorageUri fileAbsoluteUri, final StorageCredentials credentials) throws StorageException {
this.parseQueryAndVerify(fileAbsoluteUri, credentials);
}
-
- /**
- * Creates an instance of the CloudFile
class using the specified absolute URI and storage service
- * client.
- *
- * @param fileAbsoluteUri
- * A java.net.URI
object that represents the absolute URI to the file.
- * @param client
- * A {@link CloudFileClient} object that specifies the endpoint for the file service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFile#CloudFile(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudFile(final URI fileAbsoluteUri, final CloudFileClient client) throws StorageException,
- URISyntaxException {
- this(new StorageUri(fileAbsoluteUri), client);
- }
-
- /**
- * Creates an instance of the CloudFile
class using the specified URI and storage service client.
- *
- * @param fileAbsoluteUri
- * A {@link StorageUri} object that represents the absolute URI to the file.
- * @param client
- * A {@link CloudFileClient} object that specifies the endpoint for the file service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFile#CloudFile(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudFile(final StorageUri fileAbsoluteUri, final CloudFileClient client) throws StorageException,
- URISyntaxException {
- this.parseQueryAndVerify(fileAbsoluteUri, client == null ? null : client.getCredentials());
-
- // Override the client set in parseQueryAndVerify to make sure request options are propagated.
- if (client != null) {
- this.fileServiceClient = client;
- }
- }
-
- /**
- * Creates an instance of the CloudFile
class using the specified absolute URI, storage service
- * client and share.
- *
- * @param fileAbsoluteUri
- * A java.net.URI
object that represents the absolute URI to the file.
- * @param client
- * A {@link CloudFileClient} object that specifies the endpoint for the file service.
- * @param share
- * A {@link CloudFileShare} object that represents the share to use for the file.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFile#CloudFile(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudFile(final URI fileAbsoluteUri, final CloudFileClient client, final CloudFileShare share)
- throws StorageException, URISyntaxException {
- this(new StorageUri(fileAbsoluteUri), client, share);
- }
-
- /**
- * Creates an instance of the CloudFile
class using the specified absolute StorageUri, storage
- * service client and share.
- *
- * @param fileAbsoluteUri
- * A {@link StorageUri} object that represents the absolute URI to the file.
- * @param client
- * A {@link CloudFileClient} object that specifies the endpoint for the file service.
- * @param share
- * A {@link CloudFileShare} object that represents the share to use for the file.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFile#CloudFile(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudFile(final StorageUri fileAbsoluteUri, final CloudFileClient client, final CloudFileShare share)
- throws StorageException, URISyntaxException {
- this(fileAbsoluteUri, client);
- this.share = share;
- }
/**
* Creates an instance of the CloudFile
class by copying values from another cloud file.
@@ -281,6 +198,28 @@ public CloudFile(final CloudFile otherFile) {
this.setStreamMinimumReadSizeInBytes(otherFile.getStreamMinimumReadSizeInBytes());
this.setStreamWriteSizeInBytes(otherFile.getStreamWriteSizeInBytes());
}
+
+ /**
+ * Creates an instance of the CloudFile
class using the specified address, share,
+ * and client.
+ *
+ * @param uri
+ * A {@link StorageUri} that represents the file directory's address.
+ * @param fileName
+ * A String
that represents the name of the file.
+ * @param share
+ * A {@link CloudFileShare} object that represents the associated file share.
+ */
+ protected CloudFile(final StorageUri uri, final String fileName, final CloudFileShare share) {
+ Utility.assertNotNull("uri", uri);
+ Utility.assertNotNull("fileName", fileName);
+ Utility.assertNotNull("share", share);
+
+ this.name = fileName;
+ this.fileServiceClient = share.getServiceClient();
+ this.share = share;
+ this.storageUri = uri;
+ }
/**
* Aborts an ongoing Azure File copy operation.
@@ -1744,18 +1683,55 @@ public String generateSharedAccessSignature(final SharedAccessFilePolicy policy,
* @throws StorageException
* If a storage service error occurred.
*/
- public String generateSharedAccessSignature(final SharedAccessFilePolicy policy,
- final SharedAccessFileHeaders headers, final String groupPolicyIdentifier)
+ public String generateSharedAccessSignature(
+ final SharedAccessFilePolicy policy, final SharedAccessFileHeaders headers, final String groupPolicyIdentifier)
throws InvalidKeyException, StorageException {
+
+ return this.generateSharedAccessSignature(policy, headers, groupPolicyIdentifier,
+ null /* IP range */, null /* protocols */);
+ }
+
+ /**
+ * Returns a shared access signature for the file using the specified group policy identifier and
+ * shared access file headers. Note this does not contain the leading "?".
+ *
+ * @param policy
+ * A {@link SharedAccessFilePolicy}
object that represents the access policy for the shared
+ * access signature.
+ * @param headers
+ * A {@link SharedAccessFileHeaders}
object that represents the optional header values to
+ * set for a file accessed with this shared access signature.
+ * @param groupPolicyIdentifier
+ * A String
that represents the share-level access policy.
+ * @param ipRange
+ * A {@link IPRange} object containing the range of allowed IP addresses.
+ * @param protocols
+ * A {@link SharedAccessProtocols} representing the allowed Internet protocols.
+ *
+ * @return A String
that represents the shared access signature.
+ *
+ * @throws IllegalArgumentException
+ * If the credentials are invalid.
+ * @throws InvalidKeyException
+ * If the credentials are invalid.
+ * @throws StorageException
+ * If a storage service error occurred.
+ */
+ public String generateSharedAccessSignature(
+ final SharedAccessFilePolicy policy, final SharedAccessFileHeaders headers,
+ final String groupPolicyIdentifier, final IPRange ipRange, final SharedAccessProtocols protocols)
+ throws InvalidKeyException, StorageException {
+
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.fileServiceClient.getCredentials())) {
throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
}
final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
- policy, headers, groupPolicyIdentifier, this.getCanonicalName(), this.fileServiceClient);
+ policy, headers, groupPolicyIdentifier, this.getCanonicalName(),
+ ipRange, protocols, this.fileServiceClient);
final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(
- policy, headers, groupPolicyIdentifier, "f", signature);
+ policy, headers, groupPolicyIdentifier, "f", ipRange, protocols, signature);
return builder.toString();
}
@@ -2753,13 +2729,12 @@ protected void updateLengthFromResponse(HttpURLConnection request) {
* @throws URISyntaxException
* If the resource URI is invalid.
*/
- @SuppressWarnings("deprecation")
@Override
public final CloudFileShare getShare() throws StorageException, URISyntaxException {
if (this.share == null) {
final StorageUri shareUri = PathUtility.getShareURI(this.getStorageUri(),
this.fileServiceClient.isUsePathStyleUris());
- this.share = new CloudFileShare(shareUri, this.fileServiceClient);
+ this.share = new CloudFileShare(shareUri, this.fileServiceClient.getCredentials());
}
return this.share;
@@ -2793,7 +2768,6 @@ public final String getName() {
* @throws URISyntaxException
* If the resource URI is invalid.
*/
- @SuppressWarnings("deprecation")
@Override
public final CloudFileDirectory getParent() throws URISyntaxException, StorageException {
if (this.parent == null) {
@@ -2801,7 +2775,7 @@ public final CloudFileDirectory getParent() throws URISyntaxException, StorageEx
if (parentName != null) {
StorageUri parentURI = PathUtility.appendPathToUri(this.share.getStorageUri(), parentName);
- this.parent = new CloudFileDirectory(parentURI, this.getServiceClient());
+ this.parent = new CloudFileDirectory(parentURI, this.getServiceClient().getCredentials());
}
}
return this.parent;
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java
index 60ebcc78c..f5bac5295 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java
@@ -98,7 +98,6 @@ public CloudFileClient(StorageUri storageUri, StorageCredentials credentials) {
* @see Naming and Referencing Shares,
* Directories, Files, and Metadata
*/
- @SuppressWarnings("deprecation")
public CloudFileShare getShareReference(final String shareName) throws URISyntaxException, StorageException {
Utility.assertNotNullOrEmpty("shareName", shareName);
return new CloudFileShare(shareName, this);
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java
index 16937dfde..9c10fe995 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileDirectory.java
@@ -140,45 +140,6 @@ public CloudFileDirectory(final StorageUri directoryAbsoluteUri, final StorageCr
this.parseQueryAndVerify(directoryAbsoluteUri, credentials);
}
- /**
- * Creates an instance of the CloudFileDirectory
class using an absolute URI to the directory.
- *
- * @param directoryAbsoluteUri
- * A {@link URI} that represents the file directory's address.
- * @param client
- * A {@link CloudFileClient} object that represents the associated service client.
- * @throws StorageException
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFileDirectory#CloudFileDirectory(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudFileDirectory(final URI directoryAbsoluteUri, final CloudFileClient client) throws StorageException,
- URISyntaxException {
- this(new StorageUri(directoryAbsoluteUri), client);
- }
-
- /**
- * Creates an instance of the CloudFileDirectory
class using an absolute URI to the directory.
- *
- * @param directoryAbsoluteUri
- * A {@link StorageUri} that represents the file directory's address.
- * @param client
- * A {@link CloudFileClient} object that represents the associated service client.
- * @throws StorageException
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFileDirectory#CloudFileDirectory(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudFileDirectory(final StorageUri directoryAbsoluteUri, final CloudFileClient client)
- throws StorageException, URISyntaxException {
- this.parseQueryAndVerify(directoryAbsoluteUri, client == null ? null : client.getCredentials());
-
- // Override the client set in parseQueryAndVerify to make sure request options are propagated.
- if (client != null) {
- this.fileServiceClient = client;
- }
- }
-
/**
* Creates an instance of the CloudFileDirectory
class using the specified address, share,
* and client.
@@ -935,13 +896,11 @@ public ResultSegmentCloudFileShare
class using the specified URI and client.
- *
- * @param uri
- * A java.net.URI
object that represents the absolute URI of the share.
- * @param client
- * A {@link CloudFileClient} object that represents the associated service client, and that specifies the
- * endpoint for the File service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFileShare#CloudFileShare(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudFileShare(final URI uri, final CloudFileClient client) throws StorageException, URISyntaxException {
- this(new StorageUri(uri), client);
- }
-
- /**
- * Creates an instance of the CloudFileShare
class using the specified URI and client.
- *
- * @param storageUri
- * A {@link StorageUri} object which represents the absolute URI of the share.
- * @param client
- * A {@link CloudFileClient} object that represents the associated service client, and that specifies the
- * endpoint for the File service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * @deprecated as of 3.0.0. Please use {@link CloudFileShare#CloudFileShare(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudFileShare(final StorageUri storageUri, final CloudFileClient client) throws StorageException,
- URISyntaxException {
- this.parseQueryAndVerify(storageUri, client == null ? null : client.getCredentials());
-
- // Override the client set in parseQueryAndVerify to make sure request options are propagated.
- if (client != null) {
- this.fileServiceClient = client;
- }
- }
-
/**
* Creates the share.
*
@@ -393,15 +349,17 @@ public void delete(AccessCondition accessCondition, FileRequestOptions options,
options.getRetryPolicyFactory(), opContext);
}
- private StorageRequestString
which represents the share-level access policy.
+ * @param ipRange
+ * A {@link IPRange} object containing the range of allowed IP addresses.
+ * @param protocols
+ * A {@link SharedAccessProtocols} representing the allowed Internet protocols.
+ *
+ * @return A String
which represents a shared access signature for the share.
+ *
+ * @throws StorageException
+ * If a storage service error occurred.
+ * @throws InvalidKeyException
+ * If the key is invalid.
+ */
+ public String generateSharedAccessSignature(
+ final SharedAccessFilePolicy policy, final String groupPolicyIdentifier, final IPRange ipRange,
+ final SharedAccessProtocols protocols)
+ throws InvalidKeyException, StorageException {
+
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.fileServiceClient.getCredentials())) {
final String errorMessage = SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY;
throw new IllegalArgumentException(errorMessage);
@@ -890,11 +877,12 @@ public String generateSharedAccessSignature(final SharedAccessFilePolicy policy,
final String resourceName = this.getSharedAccessCanonicalName();
- final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(policy,
- null /* SharedAccessHeaders */, groupPolicyIdentifier, resourceName, this.fileServiceClient);
+ final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
+ policy, null /* SharedAccessHeaders */, groupPolicyIdentifier, resourceName,
+ ipRange, protocols, this.fileServiceClient);
- final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(policy,
- null /* SharedAccessHeaders */, groupPolicyIdentifier, "s", signature);
+ final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(
+ policy, null /* SharedAccessHeaders */, groupPolicyIdentifier, "s", ipRange, protocols, signature);
return builder.toString();
}
@@ -1187,9 +1175,8 @@ public Void preProcessResponse(CloudFileShare share, CloudFileClient client,
* @throws StorageException
* @throws URISyntaxException
*/
- @SuppressWarnings("deprecation")
public CloudFileDirectory getRootDirectoryReference() throws StorageException, URISyntaxException {
- return new CloudFileDirectory(this.storageUri, this.fileServiceClient);
+ return new CloudFileDirectory(this.storageUri, "", this);
}
/**
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileServiceProperties.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileServiceProperties.java
index 1bd712670..0e0fe1fe9 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileServiceProperties.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileServiceProperties.java
@@ -15,6 +15,7 @@
package com.microsoft.azure.storage.file;
import com.microsoft.azure.storage.CorsProperties;
+import com.microsoft.azure.storage.MetricsProperties;
import com.microsoft.azure.storage.ServiceProperties;
/**
@@ -37,11 +38,9 @@ public FileServiceProperties() {
* The ServiceProperties
to use
*/
FileServiceProperties(ServiceProperties properties) {
- serviceProperties = properties;
- serviceProperties.setHourMetrics(null);
- serviceProperties.setMinuteMetrics(null);
- serviceProperties.setLogging(null);
- serviceProperties.setDefaultServiceVersion(null);
+ this.serviceProperties = properties;
+ this.serviceProperties.setLogging(null);
+ this.serviceProperties.setDefaultServiceVersion(null);
}
/**
@@ -50,7 +49,7 @@ public FileServiceProperties() {
* @return A {@link CorsProperties} object which represents the CORS properties.
*/
public CorsProperties getCors() {
- return serviceProperties.getCors();
+ return this.serviceProperties.getCors();
}
/**
@@ -60,15 +59,53 @@ public CorsProperties getCors() {
* A {@link CorsProperties} object which represents the CORS properties.
*/
public void setCors(CorsProperties cors) {
- serviceProperties.setCors(cors);
+ this.serviceProperties.setCors(cors);
}
+ /**
+ * Gets the hour metrics properties.
+ *
+ * @return A {@link MetricsProperties} object which represents the hour metrics properties.
+ */
+ public MetricsProperties getHourMetrics() {
+ return this.serviceProperties.getHourMetrics();
+ }
+
+ /**
+ * Sets the hour metrics properties.
+ *
+ * @param metrics
+ * A {@link MetricsProperties} object which represents the hour metrics properties.
+ */
+ public void setHourMetrics(final MetricsProperties metrics) {
+ this.serviceProperties.setHourMetrics(metrics);
+ }
+
+ /**
+ * Gets the minute metrics properties.
+ *
+ * @return A {@link MetricsProperties} object which represents the minute metrics properties.
+ */
+ public MetricsProperties getMinuteMetrics() {
+ return this.serviceProperties.getMinuteMetrics();
+ }
+
+ /**
+ * Sets the minute metrics properties.
+ *
+ * @param metrics
+ * A {@link MetricsProperties} object which represents the minute metrics properties.
+ */
+ public void setMinuteMetrics(final MetricsProperties metrics) {
+ this.serviceProperties.setMinuteMetrics(metrics);
+ }
+
/**
* Gets the ServiceProperties
for use by the service.
*
* @return The ServiceProperties
*/
ServiceProperties getServiceProperties() {
- return serviceProperties;
+ return this.serviceProperties;
}
-}
+}
\ No newline at end of file
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePermissions.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePermissions.java
index 414349b38..3c8d14707 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePermissions.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePermissions.java
@@ -23,13 +23,18 @@ public enum SharedAccessFilePermissions {
*/
READ,
+ /**
+ * Specifies Create access granted.
+ */
+ CREATE,
+
/**
* Specifies Write access granted.
*/
WRITE,
/**
- * Specifies Delete access granted for files.
+ * Specifies Delete access granted.
*/
DELETE,
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePolicy.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePolicy.java
index 0e0468da9..e1995f3f4 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePolicy.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/file/SharedAccessFilePolicy.java
@@ -53,7 +53,7 @@ public void setPermissions(final EnumSetString
that represents the shared access permissions in the "rwdl" format,
+ * @return A String
that represents the shared access permissions in the "rcwdl" format,
* which is described at {@link #setPermissionsFromString(String)}.
*/
@Override
@@ -62,13 +62,17 @@ public String permissionsToString() {
return Constants.EMPTY_STRING;
}
- // The service supports a fixed order => rwdl
+ // The service supports a fixed order => rcwdl
final StringBuilder builder = new StringBuilder();
if (this.permissions.contains(SharedAccessFilePermissions.READ)) {
builder.append("r");
}
+ if (this.permissions.contains(SharedAccessFilePermissions.CREATE)) {
+ builder.append("c");
+ }
+
if (this.permissions.contains(SharedAccessFilePermissions.WRITE)) {
builder.append("w");
}
@@ -89,13 +93,13 @@ public String permissionsToString() {
*
* @param value
* A String
that represents the shared access permissions. The string must contain one or
- * more of the following values. Note they must be lowercase, and the order that they are specified must
- * be in the order of "rwdl".
+ * more of the following values. Note they must all be lowercase.
*
- *
*/
public void setPermissionsFromString(final String value) {
@@ -105,6 +109,9 @@ public void setPermissionsFromString(final String value) {
case 'r':
initial.add(SharedAccessFilePermissions.READ);
break;
+ case 'c':
+ initial.add(SharedAccessFilePermissions.CREATE);
+ break;
case 'w':
initial.add(SharedAccessFilePermissions.WRITE);
break;
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueue.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueue.java
index 561615413..75c65d5a7 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueue.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueue.java
@@ -30,9 +30,11 @@
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.DoesServiceRequest;
+import com.microsoft.azure.storage.IPRange;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.SharedAccessPolicyHandler;
import com.microsoft.azure.storage.SharedAccessPolicySerializer;
+import com.microsoft.azure.storage.SharedAccessProtocols;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
@@ -184,10 +186,8 @@ public CloudQueue(final StorageUri uri, final StorageCredentials credentials) th
* @throws StorageException
* If a storage service error occurred.
* @see Naming Queues and Metadata
- * @deprecated as of 3.0.0. Please use {@link CloudQueueClient#getQueueReference(String)}
*/
- @Deprecated
- public CloudQueue(final String queueName, final CloudQueueClient client) throws URISyntaxException,
+ protected CloudQueue(final String queueName, final CloudQueueClient client) throws URISyntaxException,
StorageException {
Utility.assertNotNull("client", client);
Utility.assertNotNull("queueName", queueName);
@@ -198,53 +198,6 @@ public CloudQueue(final String queueName, final CloudQueueClient client) throws
this.shouldEncodeMessage = true;
}
- /**
- * Creates an instance of the d
: Delete access.l
: List access.r
: Read access.c
: Create access.w
: Write access.d
: Delete access.l
: List access.CloudQueue
class using the specified queue URI and client. If the
- * URI
contains a SAS token, the service client must be null
.
- *
- * @param uri
- * A java.net.URI
object that represents the absolute URI of the queue.
- * @param client
- * A {@link CloudQueueClient} object that represents the associated service client, and that specifies
- * the endpoint for the Queue service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * If the resource URI is invalid.
- * @deprecated as of 3.0.0. Please use {@link CloudQueue#CloudQueue(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudQueue(final URI uri, final CloudQueueClient client) throws URISyntaxException, StorageException {
- this(new StorageUri(uri, null), client);
- }
-
- /**
- * Creates an instance of the CloudQueue
class using the specified queue URI and client.
- *
- * @param uri
- * A StorageUri
object that represents the absolute URI of the queue.
- * @param client
- * A {@link CloudQueueClient} object that represents the associated service client, and that specifies
- * the endpoint for the Queue service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * If the resource URI is invalid.
- * @deprecated as of 3.0.0. Please use {@link CloudQueue#CloudQueue(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudQueue(final StorageUri uri, final CloudQueueClient client) throws URISyntaxException, StorageException {
- this.shouldEncodeMessage = true;
- this.parseQueryAndVerify(uri, client == null ? null : client.getCredentials());
-
- // Override the client set in parseQueryAndVerify to make sure request options are propagated.
- if (client != null) {
- this.queueServiceClient = client;
- }
- }
-
/**
* Adds a message to the back of the queue.
*
@@ -1762,7 +1715,9 @@ public QueuePermissions postProcessResponse(HttpURLConnection connection, CloudQ
* The access policy for the shared access signature.
* @param groupPolicyIdentifier
* A queue-level access policy.
+ *
* @return A shared access signature for the queue.
+ *
* @throws InvalidKeyException
* If an invalid key was passed.
* @throws StorageException
@@ -1773,6 +1728,35 @@ public QueuePermissions postProcessResponse(HttpURLConnection connection, CloudQ
public String generateSharedAccessSignature(final SharedAccessQueuePolicy policy, final String groupPolicyIdentifier)
throws InvalidKeyException, StorageException {
+ return this.generateSharedAccessSignature(policy, groupPolicyIdentifier, null /* IP range */, null /* protocols */);
+ }
+
+ /**
+ * Returns a shared access signature for the queue.
+ *
+ * @param policy
+ * The access policy for the shared access signature.
+ * @param groupPolicyIdentifier
+ * A queue-level access policy.
+ * @param ipRange
+ * A {@link IPRange} object containing the range of allowed IP addresses.
+ * @param protocols
+ * A {@link SharedAccessProtocols} representing the allowed Internet protocols.
+ *
+ * @return A shared access signature for the queue.
+ *
+ * @throws InvalidKeyException
+ * If an invalid key was passed.
+ * @throws StorageException
+ * If a storage service error occurred.
+ * @throws IllegalArgumentException
+ * If an unexpected value is passed.
+ */
+ public String generateSharedAccessSignature(
+ final SharedAccessQueuePolicy policy, final String groupPolicyIdentifier, final IPRange ipRange,
+ final SharedAccessProtocols protocols)
+ throws InvalidKeyException, StorageException {
+
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.queueServiceClient.getCredentials())) {
final String errorMessage = SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY;
throw new IllegalArgumentException(errorMessage);
@@ -1780,11 +1764,11 @@ public String generateSharedAccessSignature(final SharedAccessQueuePolicy policy
final String resourceName = this.getSharedAccessCanonicalName();
- final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForQueue(policy,
- groupPolicyIdentifier, resourceName, this.queueServiceClient);
+ final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForQueue(
+ policy, groupPolicyIdentifier, resourceName, ipRange, protocols, this.queueServiceClient);
- final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForQueue(policy,
- groupPolicyIdentifier, signature);
+ final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForQueue(
+ policy, groupPolicyIdentifier, ipRange, protocols, signature);
return builder.toString();
}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueueClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueueClient.java
index 893fe4b18..7b6212788 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueueClient.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/queue/CloudQueueClient.java
@@ -99,7 +99,6 @@ public CloudQueueClient(final StorageUri baseUri, final StorageCredentials crede
* If a storage service error occurred.
* @see Naming Queues and Metadata
*/
- @SuppressWarnings("deprecation")
public CloudQueue getQueueReference(final String queueName) throws URISyntaxException, StorageException {
return new CloudQueue(queueName, this);
}
@@ -277,8 +276,9 @@ public HttpURLConnection buildRequest(CloudQueueClient client, Void parentObject
throws Exception {
listingContext.setMarker(segmentedRequest.getToken() != null ? segmentedRequest.getToken()
.getNextMarker() : null);
- return QueueRequest.list(client.getStorageUri().getUri(this.getCurrentLocation()), options, context,
- listingContext, detailsIncluded);
+ return QueueRequest.list(
+ credentials.transformUri(client.getStorageUri().getUri(this.getCurrentLocation())),
+ options, context, listingContext, detailsIncluded);
}
@Override
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTable.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTable.java
index ca9b493fc..3611960e7 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTable.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTable.java
@@ -29,11 +29,13 @@
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.DoesServiceRequest;
+import com.microsoft.azure.storage.IPRange;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.ResultContinuation;
import com.microsoft.azure.storage.ResultSegment;
import com.microsoft.azure.storage.SharedAccessPolicyHandler;
import com.microsoft.azure.storage.SharedAccessPolicySerializer;
+import com.microsoft.azure.storage.SharedAccessProtocols;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
@@ -182,10 +184,8 @@ public CloudTable(final StorageUri uri, final StorageCredentials credentials) th
* If a storage service error occurred.
* @see Understanding the Table Service Data
* Model
- * @deprecated as of 3.0.0. Please use {@link CloudTableClient#getTableReference(String)}
*/
- @Deprecated
- public CloudTable(final String tableName, final CloudTableClient client) throws URISyntaxException,
+ protected CloudTable(final String tableName, final CloudTableClient client) throws URISyntaxException,
StorageException {
Utility.assertNotNull("client", client);
Utility.assertNotNull("tableName", tableName);
@@ -195,51 +195,6 @@ public CloudTable(final String tableName, final CloudTableClient client) throws
this.tableServiceClient = client;
}
- /**
- * Creates an instance of the CloudTable
class using the specified table URI and client.
- *
- * @param uri
- * A java.net.URI
object that represents the absolute URI of the table.
- * @param client
- * A {@link CloudTableClient} object that represents the associated service client, and that specifies
- * the endpoint for the Table service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * If the resource URI is invalid.
- * @deprecated as of 3.0.0. Please use {@link CloudTable#CloudTable(URI, StorageCredentials)}
- */
- @Deprecated
- public CloudTable(final URI uri, final CloudTableClient client) throws URISyntaxException, StorageException {
- this(new StorageUri(uri, null), client);
- }
-
- /**
- * Creates an instance of the CloudTable
class using the specified table StorageUri and client.
- *
- * @param uri
- * A {@link StorageUri} object that represents the absolute StorageUri of the table.
- * @param client
- * A {@link CloudTableClient} object that represents the associated service client, and that specifies
- * the endpoint for the Table service.
- *
- * @throws StorageException
- * If a storage service error occurred.
- * @throws URISyntaxException
- * If the resource URI is invalid.
- * @deprecated as of 3.0.0. Please use {@link CloudTable#CloudTable(StorageUri, StorageCredentials)}
- */
- @Deprecated
- public CloudTable(final StorageUri uri, final CloudTableClient client) throws URISyntaxException, StorageException {
- this.parseQueryAndVerify(uri, client == null ? null : client.getCredentials());
-
- // Override the client set in parseQueryAndVerify to make sure request options are propagated.
- if (client != null) {
- this.tableServiceClient = client;
- }
- }
-
/**
* Creates the table in the storage service with default request options.
* String
which represents a table-level access policy.
+ * @param startPartitionKey
+ * A String
which represents the starting partition key.
+ * @param startRowKey
+ * A String
which represents the starting row key.
+ * @param endPartitionKey
+ * A String
which represents the ending partition key.
+ * @param endRowKey
+ * A String
which represents the ending end key.
+ * @param ipRange
+ * A {@link IPRange} object containing the range of allowed IP addresses.
+ * @param protocols
+ * A {@link SharedAccessProtocols} representing the allowed Internet protocols.
+ *
+ * @return A String
containing the shared access signature for the table.
+ *
+ * @throws InvalidKeyException
+ * If an invalid key was passed.
+ * @throws StorageException
+ * If a storage service error occurred.
+ * @throws IllegalArgumentException
+ * If an unexpected value is passed.
+ */
+ public String generateSharedAccessSignature(
+ final SharedAccessTablePolicy policy, final String accessPolicyIdentifier, final String startPartitionKey,
+ final String startRowKey, final String endPartitionKey, final String endRowKey, final IPRange ipRange,
+ final SharedAccessProtocols protocols)
+ throws InvalidKeyException, StorageException {
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.tableServiceClient.getCredentials())) {
throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
@@ -1182,13 +1177,13 @@ public String generateSharedAccessSignature(final SharedAccessTablePolicy policy
final String resourceName = this.getSharedAccessCanonicalName();
- final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForTable(policy,
- accessPolicyIdentifier, resourceName, startPartitionKey, startRowKey, endPartitionKey, endRowKey,
- this.tableServiceClient);
+ final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForTable(
+ policy, accessPolicyIdentifier, resourceName, ipRange, protocols,
+ startPartitionKey, startRowKey, endPartitionKey, endRowKey, this.tableServiceClient);
- final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForTable(policy,
- startPartitionKey, startRowKey, endPartitionKey, endRowKey, accessPolicyIdentifier, this.name,
- signature);
+ final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForTable(
+ policy, startPartitionKey, startRowKey, endPartitionKey, endRowKey, accessPolicyIdentifier,
+ ipRange, protocols, this.name, signature);
return builder.toString();
}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTableClient.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTableClient.java
index 20d1ed9a4..d2db48afb 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTableClient.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/CloudTableClient.java
@@ -35,8 +35,6 @@
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.StorageExtendedErrorInformation;
import com.microsoft.azure.storage.StorageUri;
-import com.microsoft.azure.storage.blob.BlobRequestOptions;
-import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.core.ExecutionEngine;
import com.microsoft.azure.storage.core.LazySegmentedIterable;
import com.microsoft.azure.storage.core.SR;
@@ -132,9 +130,7 @@ public CloudTableClient(final StorageUri baseUri, StorageCredentials credentials
* @see Understanding the Table Service Data
* Model
*/
- @SuppressWarnings("deprecation")
public CloudTable getTableReference(final String tableName) throws URISyntaxException, StorageException {
- Utility.assertNotNullOrEmpty("tableName", tableName);
return new CloudTable(tableName, this);
}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/DeserializationHelper.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/DeserializationHelper.java
deleted file mode 100644
index 74630f8b5..000000000
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/DeserializationHelper.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * Copyright Microsoft Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.microsoft.azure.storage.table;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import com.microsoft.azure.storage.Constants;
-
-/**
- * RESERVED FOR INTERNAL USE. An internal helper class used to parse objects from responses.
- */
-final class DeserializationHelper {
- // see use below for more explanation
- private final static String ENTITY_EXPANSION_EXCEPTION_MESSAGE = "(.|\n)*Message: JAXP00010001: The parser has encountered more than \"\\d+\" entity expansions in this document; this is the limit imposed by the JDK\\.";
-
- private static XMLInputFactory xmlif;
-
- static {
- setupXMLInputFactory();
- }
-
- /**
- * Sets this class's XMLInputFactory
instance to a new factory instance and sets the appropriate
- * properties on it. This is not synchronized so multiple threads executing this will cause multiple factories to be
- * created, but this is okay as it does not matter for the reader which factory creates it as they are functionally
- * identical.
- */
- public static void setupXMLInputFactory() {
- final XMLInputFactory xmlif = XMLInputFactory.newInstance();
- xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
- xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
- // set the IS_COALESCING property to true , if application desires to
- // get whole text data as one event.
- xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
- DeserializationHelper.xmlif = xmlif;
- }
-
- /**
- * Tests whether the provided exception is an entity expansion exception.
- *
- * Some versions of Java cause an exception to be incorrectly thrown when more XMLStreamReaders have been
- * created by a single factory than the entity expansion limit property (default 64000). The default form of this
- * exception is: "ParseError at [row,col]:[1,1]\n
- * Message: JAXP00010001: The parser has encountered more than
- * \"64000\" entity expansions in this document; this is the limit imposed by the JDK."
- *
- * @param e
- * the XMLStreamException
to test
- * @return
- * true if entity expansion exception, false otherwise
- */
- public static boolean isEntityExpansionLimitException(XMLStreamException e) {
- return e.getMessage() != null && e.getMessage().matches(ENTITY_EXPANSION_EXCEPTION_MESSAGE);
- }
-
- /**
- * Creates an XML stream reader from the specified input stream.
- *
- * Some versions of Java cause an exception to be incorrectly thrown when more XMLStreamReaders have been
- * created by a single factory than the entity expansion limit property (default 64000). This model catches
- * that exception, creates a new factory with the appropriate settings, and then retries the reader creation.
- *
- * @param reader
- * An InputStreamReader
object that represents the input reader to use as the source.
- *
- * @return A java.xml.stream.XMLStreamReader
object that represents the XML stream reader created from
- * the specified input stream.
- *
- * @throws XMLStreamException
- * If the XML stream reader could not be created.
- * @see https://bugs.openjdk.java.net/browse/JDK-8028111
- */
- public static XMLStreamReader createXMLStreamReaderFromReader(final Reader reader) throws XMLStreamException {
- while (true) {
- try {
- return xmlif.createXMLStreamReader(reader);
- }
- catch (XMLStreamException e) {
- if (isEntityExpansionLimitException(e)) {
- setupXMLInputFactory();
- }
- else {
- throw e;
- }
- }
- }
- }
-
- /**
- * Creates an XML stream reader from the specified input stream.
- *
- * Some versions of Java cause an exception to be incorrectly thrown when more XMLStreamReaders have been
- * created by a single factory than the entity expansion limit property (default 64000). This model catches
- * that exception, creates a new factory with the appropriate settings, and then retries the reader creation.
- *
- * @param streamRef
- * An InputStream
object that represents the input stream to use as the source.
- *
- * @return A java.xml.stream.XMLStreamReader
object that represents the XML stream reader created from
- * the specified input stream.
- *
- * @throws XMLStreamException
- * If the XML stream reader could not be created.
- *
- * @see https://bugs.openjdk.java.net/browse/JDK-8028111
- */
- public static XMLStreamReader createXMLStreamReaderFromStream(final InputStream streamRef)
- throws XMLStreamException {
- while (true) {
- try {
- return xmlif.createXMLStreamReader(streamRef, Constants.UTF8_CHARSET);
- }
- catch (XMLStreamException e) {
- if (isEntityExpansionLimitException(e)) {
- setupXMLInputFactory();
- }
- else {
- throw e;
- }
- }
- }
- }
-
- /**
- * Reads character data for the specified XML element from an XML stream reader. This method will read start events,
- * characters, and end events from a stream.
- *
- * @param xmlr
- * An XMLStreamReader
object that represents the source XML stream reader.
- *
- * @param elementName
- * A String
that represents XML element name.
- *
- * @return A String
that represents the character data for the specified element.
- *
- * @throws XMLStreamException
- * If an XML stream failure occurs.
- */
- public static String readElementFromXMLReader(final XMLStreamReader xmlr, final String elementName)
- throws XMLStreamException {
- return readElementFromXMLReader(xmlr, elementName, true);
- }
-
- /**
- * Reads character data for the specified XML element from an XML stream reader. This method will read start events,
- * characters, and end events from a stream.
- *
- * @param xmlr
- * An XMLStreamReader
object that represents the source XML stream reader.
- *
- * @param elementName
- * A String
that represents XML element name.
- * @param returnNullOnEmpty
- * If true, returns null when a empty string is read, otherwise EmptyString ("") is returned.
- *
- * @return A String
that represents the character data for the specified element.
- *
- * @throws XMLStreamException
- * If an XML stream failure occurs.
- */
- public static String readElementFromXMLReader(final XMLStreamReader xmlr, final String elementName,
- boolean returnNullOnEmpty) throws XMLStreamException {
- xmlr.require(XMLStreamConstants.START_ELEMENT, null, elementName);
- int eventType = xmlr.next();
- final StringBuilder retVal = new StringBuilder();
-
- if (eventType == XMLStreamConstants.CHARACTERS) {
- // This do while is in case the XMLStreamReader does not have
- // the IS_COALESCING property set
- // to true which may result in text being read in multiple events
- // If we ensure all xmlreaders have this property we can optimize
- // the StringBuilder and while loop
- // away
- do {
- retVal.append(xmlr.getText());
- eventType = xmlr.next();
-
- } while (eventType == XMLStreamConstants.CHARACTERS);
- }
-
- xmlr.require(XMLStreamConstants.END_ELEMENT, null, elementName);
- if (retVal.length() == 0) {
- return returnNullOnEmpty ? null : Constants.EMPTY_STRING;
- }
- else {
- return retVal.toString();
- }
- }
-
- /**
- * Private Default Ctor
- */
- private DeserializationHelper() {
- // No op
- }
-}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/DynamicTableEntity.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/DynamicTableEntity.java
index 6af9ddb75..451d78ec7 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/DynamicTableEntity.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/DynamicTableEntity.java
@@ -15,7 +15,6 @@
package com.microsoft.azure.storage.table;
-import java.util.Date;
import java.util.HashMap;
import com.microsoft.azure.storage.OperationContext;
@@ -91,36 +90,8 @@ public DynamicTableEntity(String partitionKey, String rowKey, final HashMapString
which represents the row key of the {@link DynamicTableEntity} to be initialized.
- * @param etag
- * A String
which represents the ETag of the {@link DynamicTableEntity} to be initialized.
- * @param timestamp
- * A java.util.Date
object which represents the timestamp of the {@link DynamicTableEntity} to be initialized.
- * @param properties
- * A java.util.HashMap
containing a map of String
property names to
- * {@link EntityProperty} data typed values to store in the new {@link DynamicTableEntity}.
- * @deprecated as of 3.0.0. The timestamp property is read-only, set by the service only. Please use
- * {@link DynamicTableEntity#DynamicTableEntity(String, String, String, HashMap)} instead.
- */
- @Deprecated
- public DynamicTableEntity(String partitionKey, String rowKey, Date timestamp, String etag,
- final HashMapString
containing the entity associated with an operation in
- * AtomPub format.
+ * Json format.
*
* @param operation
* A {@link TableOperation} containing the entity to write to the returned String
.
@@ -448,15 +444,13 @@ private static void writeMIMEContentType(final OutputStreamWriter outWriter, fin
* An {@link OperationContext} object for tracking the current operation. Specify null
to
* safely ignore operation context.
* @return
- * A String
containing the entity associated with the operation in AtomPub format
+ * A String
containing the entity associated with the operation in Json format
* @throws StorageException
* if a Storage error occurs.
- * @throws XMLStreamException
- * if an error occurs creating or writing to the output string.
* @throws IOException
*/
private static String writeStringForOperation(final TableOperation operation, TablePayloadFormat format,
- final OperationContext opContext) throws StorageException, XMLStreamException, IOException {
+ final OperationContext opContext) throws StorageException, IOException {
Utility.assertNotNull("entity", operation.getEntity());
final StringWriter outWriter = new StringWriter();
@@ -466,12 +460,8 @@ private static String writeStringForOperation(final TableOperation operation, Ta
return outWriter.toString();
}
- @SuppressWarnings("deprecation")
private static String generateAcceptHeaderValue(TablePayloadFormat payloadFormat) {
- if (payloadFormat == TablePayloadFormat.AtomPub) {
- return TableConstants.HeaderConstants.ATOM_ACCEPT_TYPE;
- }
- else if (payloadFormat == TablePayloadFormat.JsonFullMetadata) {
+ if (payloadFormat == TablePayloadFormat.JsonFullMetadata) {
return TableConstants.HeaderConstants.JSON_FULL_METADATA_ACCEPT_TYPE;
}
else if (payloadFormat == TablePayloadFormat.Json) {
@@ -482,16 +472,6 @@ else if (payloadFormat == TablePayloadFormat.Json) {
}
}
- @SuppressWarnings("deprecation")
- private static String generateContentTypeHeaderValue(TablePayloadFormat payloadFormat) {
- if (payloadFormat == TablePayloadFormat.AtomPub) {
- return TableConstants.HeaderConstants.ATOM_CONTENT_TYPE;
- }
- else {
- return TableConstants.HeaderConstants.JSON_CONTENT_TYPE;
- }
- }
-
/**
* Reserved for internal use. A static factory method that generates a {@link StorageException} for invalid MIME
* responses.
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/ODataConstants.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/ODataConstants.java
index 17e710bae..28e3ba89a 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/ODataConstants.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/ODataConstants.java
@@ -20,131 +20,11 @@
*/
final class ODataConstants {
- /**
- * The String
representation of the Atom namespace.
- */
- public static final String ATOM_NS = "http://www.w3.org/2005/Atom";
-
- /**
- * The String
representation of the OData Data namespace.
- */
- public static final String DATA_SERVICES_NS = "http://schemas.microsoft.com/ado/2007/08/dataservices";
-
- /**
- * The String
representation of the OData Metadata namespace.
- */
- public static final String DATA_SERVICES_METADATA_NS = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
-
- /**
- * The String
representation of the Atom namespace in brackets.
- */
- public static final String BRACKETED_ATOM_NS = "{" + ATOM_NS + "}"; // default
-
- /**
- * The String
representation of the OData Data namespace in brackets.
- */
- public static final String BRACKETED_DATA_SERVICES_NS = "{" + DATA_SERVICES_NS + "}"; // d:
-
- /**
- * The String
representation of the OData Metadata namespace in brackets.
- */
- public static final String BRACKETED_DATA_SERVICES_METADATA_NS = "{" + DATA_SERVICES_METADATA_NS + "}"; // m:
-
- /**
- * The String
representation of the Atom Entry feed element name.
- */
- public static final String FEED = "feed";
-
- /**
- * The String
representation of the Atom Entry title element name.
- */
- public static final String TITLE = "title";
-
- /**
- * The String
representation of the Atom Entry id element name.
- */
- public static final String ID = "id";
-
- /**
- * The String
representation of the Atom Entry updated element name.
- */
- public static final String UPDATED = "updated";
-
- /**
- * The String
representation of the Atom Entry link element name.
- */
- public static final String LINK = "link";
-
- /**
- * The String
representation of the Atom Entry author element name.
- */
- public static final String AUTHOR = "author";
-
- /**
- * The String
representation of the Atom Entry name element name.
- */
- public static final String NAME = "name";
-
- /**
- * The String
representation of the Atom Entry entry element name.
- */
- public static final String ENTRY = "entry";
-
- /**
- * The String
representation of the Atom Entry category element name.
- */
- public static final String CATEGORY = "category";
-
- /**
- * The String
representation of the Atom Entry content element name.
- */
- public static final String CONTENT = "content";
-
- /**
- * The String
representation of the OData Metadata properties element name.
- */
- public static final String PROPERTIES = "properties";
-
/**
* The String
representation of the Atom Entry etag element name.
*/
public static final String ETAG = "etag";
- /**
- * The String
representation of the type attribute name.
- */
- public static final String TYPE = "type";
-
- /**
- * The String
representation of the term element name.
- */
- public static final String TERM = "term";
-
- /**
- * The String
representation of scheme.
- */
- public static final String SCHEME = "scheme";
-
- /**
- * The String
representation of href.
- */
- public static final String HREF = "href";
-
- /**
- * The String
representation of rel.
- */
- public static final String REL = "rel";
-
- /**
- * The String
representation of the null attribute name.
- */
- public static final String NULL = "null";
-
- /**
- * The String
representation of the content type attribute value to send.
- */
- public static final String ODATA_CONTENT_TYPE = "application/xml";
-
/**
* The String
representation of the JSON annotation prefix
*/
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/QueryTableOperation.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/QueryTableOperation.java
index 691ebff80..279ff2737 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/QueryTableOperation.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/QueryTableOperation.java
@@ -19,8 +19,6 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
-import javax.xml.stream.XMLStreamException;
-
import com.fasterxml.jackson.core.JsonParseException;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.StorageException;
@@ -127,8 +125,6 @@ protected Class extends TableEntity> getClazzType() {
* @return
* The {@link TableResult} representing the result of the query operation.
*
- * @throws XMLStreamException
- * if an error occurs accessing the {@link InputStream} with AtomPub.
* @throws InstantiationException
* if an error occurs in object construction.
* @throws IllegalAccessException
@@ -142,8 +138,8 @@ protected Class extends TableEntity> getClazzType() {
*/
@Override
protected TableResult parseResponse(final InputStream inStream, final int httpStatusCode, String etagFromHeader,
- final OperationContext opContext, final TableRequestOptions options) throws XMLStreamException,
- InstantiationException, IllegalAccessException, StorageException, JsonParseException, IOException {
+ final OperationContext opContext, final TableRequestOptions options) throws InstantiationException,
+ IllegalAccessException, StorageException, JsonParseException, IOException {
TableResult res = TableDeserializer.parseSingleOpResponse(inStream, options, httpStatusCode,
this.getClazzType(), this.getResolver(), opContext);
res.setEtag(etagFromHeader);
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/SharedAccessTablePolicy.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/SharedAccessTablePolicy.java
index 5525ade6e..c32b537f7 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/SharedAccessTablePolicy.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/SharedAccessTablePolicy.java
@@ -119,7 +119,7 @@ public void setPermissionsFromString(final String value) {
retSet.add(SharedAccessTablePermissions.DELETE);
break;
default:
- throw new IllegalArgumentException(String.format(SR.PERMISSIONS_COULD_NOT_BE_PARSED, value));
+ throw new IllegalArgumentException(String.format(SR.ENUM_COULD_NOT_BE_PARSED, "Permissions", value));
}
}
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableBatchOperation.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableBatchOperation.java
index fef130177..2148fbb43 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableBatchOperation.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableBatchOperation.java
@@ -25,8 +25,6 @@
import java.util.ArrayList;
import java.util.UUID;
-import javax.xml.stream.XMLStreamException;
-
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
@@ -561,11 +559,6 @@ public StorageExtendedErrorInformation parseErrorDetails() {
StorageException translatedException = StorageException.translateClientException(e);
throw translatedException;
}
- catch (XMLStreamException e) {
- // The request was not even made. There was an error while trying to read the batch contents. Just throw.
- StorageException translatedException = StorageException.translateClientException(e);
- throw translatedException;
- }
}
/**
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableConstants.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableConstants.java
index ae4613357..502df5140 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableConstants.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableConstants.java
@@ -55,32 +55,6 @@ public static class ErrorConstants {
* The constants used in HTML header fields for Table service requests.
*/
public static class HeaderConstants {
- /**
- * The Accept header value to send.
- *
- * @deprecated use {@link AtomAcceptType}
- */
- @Deprecated
- public static final String ACCEPT_TYPE = "application/atom+xml,application/xml";
-
- /**
- * The Accept header value to send for AtomPub.
- */
- public static final String ATOM_ACCEPT_TYPE = "application/atom+xml,application/atomsvc+xml,application/xml";
-
- /**
- * The Content-Type header value to send for AtomPub.
- */
- public static final String ATOM_CONTENT_TYPE = "application/atom+xml";
-
- /**
- * The Content-Type header value to send for single operations.
- *
- * @deprecated use {@link AtomContentType}
- */
- @Deprecated
- public static final String ATOMPUB_TYPE = "application/atom+xml";
-
/**
* The Content-ID header value to send for batch operations.
*/
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableDeserializer.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableDeserializer.java
index 8d4912860..312e1535d 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableDeserializer.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableDeserializer.java
@@ -23,10 +23,6 @@
import java.util.HashMap;
import java.util.Map.Entry;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
@@ -35,6 +31,7 @@
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.StorageErrorCodeStrings;
import com.microsoft.azure.storage.StorageException;
+import com.microsoft.azure.storage.core.JsonUtilities;
import com.microsoft.azure.storage.core.SR;
/**
@@ -50,12 +47,10 @@ final class TableDeserializer {
/**
* Reserved for internal use. Parses the operation response as a collection of entities. Reads entity data from the
* specified input stream using the specified class type and optionally projects each entity result with the
- * specified resolver into an {@link ODataPayload} containing a collection of {@link TableResult} objects. .
+ * specified resolver into an {@link ODataPayload} containing a collection of {@link TableResult} objects.
*
* @param inStream
* The InputStream
to read the data to parse from.
- * @param format
- * The {@link TablePayloadFormat} to use for parsing.
* @param clazzType
* The class type T
implementing {@link TableEntity} for the entities returned. Set to
* null
to ignore the returned entities and copy only response properties into the
@@ -75,51 +70,111 @@ final class TableDeserializer {
* if an error occurs while constructing the result.
* @throws IllegalAccessException
* if an error occurs in reflection while parsing the result.
- * @throws XMLStreamException
- * if an error occurs while accessing the stream with AtomPub.
* @throws StorageException
* if a storage service error occurs.
* @throws IOException
- * if an error occurs while accessing the stream with Json.
+ * if an error occurs while accessing the stream.
* @throws JsonParseException
* if an error occurs while parsing the stream.
*/
- @SuppressWarnings("deprecation")
+ @SuppressWarnings("unchecked")
static JsonParser
using the specified class type and optionally projects the entity result with the
+ * specified resolver into a {@link TableResult} object.
*
- * @param inStream
- * The InputStream
to read the data to parse from.
- * @param format
- * The {@link TablePayloadFormat} to use for parsing.
- * @param options
- * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
- * settings for the operation.
+ * @param parser
+ * The JsonParser
to read the data to parse from.
* @param httpStatusCode
* The HTTP status code returned with the operation response.
* @param clazzType
- * The class type T
implementing {@link TableEntity} for the entities returned. Set to
- * null
to ignore the returned entities and copy only response properties into the
- * {@link TableResult} objects.
+ * The class type T
implementing {@link TableEntity} for the entity returned. Set to
+ * null
to ignore the returned entity and copy only response properties into the
+ * {@link TableResult} object.
* @param resolver
- * An {@link EntityResolver} instance to project the entities into instances of type R
. Set
- * to null
to return the entities as instances of the class type T
.
+ * An {@link EntityResolver} instance to project the entity into an instance of type R
. Set
+ * to null
to return the entitys as instance of the class type T
.
+ * @param options
+ * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
+ * settings for the operation.
* @param opContext
* An {@link OperationContext} object used to track the execution of the operation.
* @return
@@ -128,28 +183,28 @@ static InputStream
to read the data to parse from.
- * @param clazzType
- * The class type T
implementing {@link TableEntity} for the entities returned. Set to
- * null
to ignore the returned entities and copy only response properties into the
- * {@link TableResult} objects.
- * @param resolver
- * An {@link EntityResolver} instance to project the entities into instances of type R
. Set
- * to null
to return the entities as instances of the class type T
.
- * @param options
- * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
- * settings for the operation.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- * @return
- * An {@link ODataPayload} containing a collection of {@link TableResult} objects with the parsed operation
- * response.
- * @throws InstantiationException
- * if an error occurs while constructing the result.
- * @throws IllegalAccessException
- * if an error occurs in reflection while parsing the result.
- * @throws StorageException
- * if a storage service error occurs.
- * @throws IOException
- * if an error occurs while accessing the stream.
- * @throws JsonParseException
- * if an error occurs while parsing the stream.
- */
- @SuppressWarnings("unchecked")
- private static JsonParser
using the specified class type and optionally projects the entity result with the
- * specified resolver into a {@link TableResult} object.
- *
- * @param parser
- * The JsonParser
to read the data to parse from.
- * @param httpStatusCode
- * The HTTP status code returned with the operation response.
- * @param clazzType
- * The class type T
implementing {@link TableEntity} for the entity returned. Set to
- * null
to ignore the returned entity and copy only response properties into the
- * {@link TableResult} object.
- * @param resolver
- * An {@link EntityResolver} instance to project the entity into an instance of type R
. Set
- * to null
to return the entitys as instance of the class type T
.
- * @param options
- * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
- * settings for the operation.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- * @return
- * A {@link TableResult} object with the parsed operation response.
- * @throws InstantiationException
- * if an error occurs while constructing the result.
- * @throws IllegalAccessException
- * if an error occurs in reflection while parsing the result.
- * @throws StorageException
- * if a storage service error occurs.
- * @throws IOException
- * if an error occurs while accessing the stream.
- * @throws JsonParseException
- * if an error occurs while parsing the stream.
- */
- private static XMLStreamReader
on the input stream.
- * @param clazzType
- * The class type T
implementing {@link TableEntity} for the entity returned. Set to
- * null
to ignore the returned entity and copy only response properties into the
- * {@link TableResult} object.
- * @param resolver
- * An {@link EntityResolver} instance to project the entity into an instance of type R
. Set
- * to null
to return the entity as an instance of the class type T
.
- * @param options
- * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
- * settings for the operation.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- * @return
- * A {@link TableResult} containing the parsed entity result of the operation.
- *
- * @throws XMLStreamException
- * if an error occurs while accessing the stream.
- * @throws InstantiationException
- * if an error occurs while constructing the result.
- * @throws IllegalAccessException
- * if an error occurs in reflection while parsing the result.
- * @throws StorageException
- * if a storage service error occurs.
- */
- @SuppressWarnings("deprecation")
- private static InputStream
to read the data to parse from.
- * @param clazzType
- * The class type T
implementing {@link TableEntity} for the entities returned. Set to
- * null
to ignore the returned entities and copy only response properties into the
- * {@link TableResult} objects.
- * @param resolver
- * An {@link EntityResolver} instance to project the entities into instances of type R
. Set
- * to null
to return the entities as instances of the class type T
.
- * @param options
- * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
- * settings for the operation.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- * @return
- * An {@link ODataPayload} containing a collection of {@link TableResult} objects with the parsed operation
- * response.
- *
- * @throws XMLStreamException
- * if an error occurs while accessing the stream.
- * @throws InstantiationException
- * if an error occurs while constructing the result.
- * @throws IllegalAccessException
- * if an error occurs in reflection while parsing the result.
- * @throws StorageException
- * if a storage service error occurs.
- */
- @SuppressWarnings("unchecked")
- private static XMLStreamReader
using the specified class type and optionally projects the entity result with the
- * specified resolver into a {@link TableResult} object.
- *
- * @param xmlr
- * The XMLStreamReader
to read the data to parse from.
- * @param httpStatusCode
- * The HTTP status code returned with the operation response.
- * @param clazzType
- * The class type T
implementing {@link TableEntity} for the entity returned. Set to
- * null
to ignore the returned entity and copy only response properties into the
- * {@link TableResult} object.
- * @param resolver
- * An {@link EntityResolver} instance to project the entity into an instance of type R
. Set
- * to null
to return the entities as instance of the class type T
.
- * @param options
- * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
- * settings for the operation.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- * @return
- * A {@link TableResult} object with the parsed operation response.
- *
- * @throws XMLStreamException
- * if an error occurs while accessing the stream.
- * @throws InstantiationException
- * if an error occurs while constructing the result.
- * @throws IllegalAccessException
- * if an error occurs in reflection while parsing the result.
- * @throws StorageException
- * if a storage service error occurs.
- */
- private static String
property names to {@link EntityProperty} data typed values.
- *
- * @param xmlr
- * The XMLStreamReader
to read the data from.
- * @param options
- * A {@link TableRequestOptions} object that specifies execution options such as retry policy and timeout
- * settings for the operation.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- *
- * @return
- * A java.util.HashMap
containing a map of String
property names to
- * {@link EntityProperty} data typed values found in the entity data.
- * @throws XMLStreamException
- * if an error occurs accessing the stream.
- */
- private static HashMapjava.util.Date
which specifies the Timestamp value to set for the entity.
- * @deprecated as of 3.0.0. The timestamp property is a read-only property, set by the service only.
*/
- @Deprecated
public void setTimestamp(Date timeStamp);
/**
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableEntitySerializer.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableEntitySerializer.java
index 7de22252e..1e9c48492 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableEntitySerializer.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableEntitySerializer.java
@@ -17,17 +17,12 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
-import java.util.Date;
import java.util.HashMap;
import java.util.Map.Entry;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.OperationContext;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.core.Utility;
@@ -42,7 +37,8 @@ final class TableEntitySerializer {
private static JsonFactory jsonFactory = new JsonFactory();
/**
- * Reserved for internal use. Writes an entity to the stream, leaving the stream open for additional writing.
+ * Reserved for internal use. Writes an entity to the stream as a JSON resource, leaving the stream open
+ * for additional writing.
*
* @param outStream
* The OutputStream
to write the entity to.
@@ -55,27 +51,29 @@ final class TableEntitySerializer {
* true
and a reference to an entity within a table when
false
.
* @param opContext
* An {@link OperationContext} object used to track the execution of the operation.
- * @throws XMLStreamException
- * if an error occurs while accessing the stream with AtomPub.
+ *
* @throws StorageException
* if a Storage service error occurs.
* @throws IOException
- * if an error occurs while accessing the stream with Json.
+ * if an error occurs while accessing the stream.
*/
- @SuppressWarnings("deprecation")
static void writeSingleEntityToStream(final OutputStream outStream, final TablePayloadFormat format,
final TableEntity entity, final boolean isTableEntry, final OperationContext opContext)
- throws XMLStreamException, StorageException, IOException {
- if (format == TablePayloadFormat.AtomPub) {
- writeSingleAtomEntity(outStream, entity, isTableEntry, opContext);
+ throws StorageException, IOException {
+ JsonGenerator generator = jsonFactory.createGenerator(outStream);
+
+ try {
+ // write to stream
+ writeJsonEntity(generator, format, entity, isTableEntry, opContext);
}
- else {
- writeSingleJsonEntity(outStream, format, entity, isTableEntry, opContext);
+ finally {
+ generator.close();
}
}
/**
- * Reserved for internal use. Writes an entity to the stream, leaving the stream open for additional writing.
+ * Reserved for internal use. Writes an entity to the stream as a JSON resource, leaving the stream open
+ * for additional writing.
*
* @param strWriter
* The StringWriter
to write the entity to.
@@ -88,207 +86,28 @@ static void writeSingleEntityToStream(final OutputStream outStream, final TableP
* true
and a reference to an entity within a table when
false
.
* @param opContext
* An {@link OperationContext} object used to track the execution of the operation.
- * @throws XMLStreamException
- * if an error occurs while accessing the stream with AtomPub.
+ *
* @throws StorageException
* if a Storage service error occurs.
* @throws IOException
- * if an error occurs while accessing the stream with Json.
+ * if an error occurs while accessing the stream.
*/
- @SuppressWarnings("deprecation")
static void writeSingleEntityToString(final StringWriter strWriter, final TablePayloadFormat format,
final TableEntity entity, final boolean isTableEntry, final OperationContext opContext)
- throws XMLStreamException, StorageException, IOException {
- if (format == TablePayloadFormat.AtomPub) {
- writeSingleAtomEntity(strWriter, entity, isTableEntry, opContext);
- }
- else {
- writeSingleJsonEntity(strWriter, format, entity, isTableEntry, opContext);
- }
- }
-
- /**
- * Reserved for internal use. Writes an entity to the stream as an AtomPub Entry Resource, leaving the stream open
- * for additional writing.
- *
- * @param entity
- * The instance implementing {@link TableEntity} to write to the output stream.
- * @param isTableEntry
- * A flag indicating the entity is a reference to a table at the top level of the storage service when
- * true
and a reference to an entity within a table when
false
.
- * @param xmlw
- * The XMLStreamWriter
to write the entity to.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- *
- * @throws XMLStreamException
- * if an error occurs accessing the stream.
- * @throws StorageException
- * if a Storage service error occurs.
- */
- @SuppressWarnings("deprecation")
- private static void writeAtomEntity(final TableEntity entity, final boolean isTableEntry,
- final XMLStreamWriter xmlw, final OperationContext opContext) throws XMLStreamException, StorageException {
- HashMapOutputStream
as a complete XML
- * document.
- *
- * @param outStream
- * The OutputStream
to write the entity to.
- * @param entity
- * The instance implementing {@link TableEntity} to write to the output stream.
- * @param isTableEntry
- * A flag indicating the entity is a reference to a table at the top level of the storage service when
- * true
and a reference to an entity within a table when
false
.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- * @throws XMLStreamException
- * if an error occurs creating or accessing the stream.
- * @throws StorageException
- * if a Storage service error occurs.
- */
- private static void writeSingleAtomEntity(final OutputStream outStream, final TableEntity entity,
- final boolean isTableEntry, final OperationContext opContext) throws XMLStreamException, StorageException {
- XMLStreamWriter xmlw = Utility.createXMLStreamWriter(outStream, Constants.UTF8_CHARSET);
-
- // default is UTF8
- xmlw.writeStartDocument(Constants.UTF8_CHARSET, "1.0");
-
- writeAtomEntity(entity, isTableEntry, xmlw, opContext);
-
- // end doc
- xmlw.writeEndDocument();
- xmlw.flush();
- }
-
- /**
- * Reserved for internal use. Writes a single entity to the specified OutputStream
as a complete XML
- * document.
- *
- * @param entity
- * The instance implementing {@link TableEntity} to write to the output stream.
- * @param isTableEntry
- * A flag indicating the entity is a reference to a table at the top level of the storage service when
- * true
and a reference to an entity within a table when
false
.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- * @param outStream
- * The OutputStream
to write the entity to.
- *
- * @throws XMLStreamException
- * if an error occurs creating or accessing the stream.
- * @throws StorageException
- * if a Storage service error occurs.
- */
- private static void writeSingleAtomEntity(final StringWriter strWriter, final TableEntity entity,
- final boolean isTableEntry, final OperationContext opContext) throws XMLStreamException, StorageException {
- final XMLStreamWriter xmlw = Utility.createXMLStreamWriter(strWriter);
-
- // default is UTF8
- xmlw.writeStartDocument(Constants.UTF8_CHARSET, "1.0");
-
- writeAtomEntity(entity, isTableEntry, xmlw, opContext);
-
- // end doc
- xmlw.writeEndDocument();
- xmlw.flush();
- }
-
- /**
- * Reserved for internal use. Writes an entity to the specified JsonGenerator
as an JSON resource
+ * Reserved for internal use. Writes an entity to the specified JsonGenerator
as a JSON resource
*
* @param generator
* The JsonGenerator
to write the entity to.
@@ -376,76 +195,6 @@ else if (currProp.getEdmType() == EdmType.DOUBLE && currProp.getIsNull() == fals
generator.writeEndObject();
}
- /**
- * Reserved for internal use. Writes an entity to the stream as an JSON resource, leaving the stream open
- * for additional writing.
- *
- * @param outStream
- * The OutputStream
to write the entity to.
- * @param format
- * The {@link TablePayloadFormat} to use for parsing.
- * @param entity
- * The instance implementing {@link TableEntity} to write to the output stream.
- * @param isTableEntry
- * A flag indicating the entity is a reference to a table at the top level of the storage service when
- * true
and a reference to an entity within a table when
false
.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- *
- * @throws StorageException
- * if a Storage service error occurs.
- * @throws IOException
- * if an error occurs while accessing the stream.
- */
- private static void writeSingleJsonEntity(final OutputStream outStream, TablePayloadFormat format,
- final TableEntity entity, final boolean isTableEntry, final OperationContext opContext)
- throws StorageException, IOException {
- JsonGenerator generator = jsonFactory.createGenerator(outStream);
-
- try {
- // write to stream
- writeJsonEntity(generator, format, entity, isTableEntry, opContext);
- }
- finally {
- generator.close();
- }
- }
-
- /**
- * Reserved for internal use. Writes an entity to the stream as an JSON resource, leaving the stream open
- * for additional writing.
- *
- * @param strWriter
- * The StringWriter
to write the entity to.
- * @param format
- * The {@link TablePayloadFormat} to use for parsing.
- * @param entity
- * The instance implementing {@link TableEntity} to write to the output stream.
- * @param isTableEntry
- * A flag indicating the entity is a reference to a table at the top level of the storage service when
- * true
and a reference to an entity within a table when
false
.
- * @param opContext
- * An {@link OperationContext} object used to track the execution of the operation.
- *
- * @throws StorageException
- * if a Storage service error occurs.
- * @throws IOException
- * if an error occurs while accessing the stream.
- */
- private static void writeSingleJsonEntity(final StringWriter strWriter, TablePayloadFormat format,
- final TableEntity entity, final boolean isTableEntry, final OperationContext opContext)
- throws StorageException, IOException {
- JsonGenerator generator = jsonFactory.createGenerator(strWriter);
-
- try {
- // write to stream
- writeJsonEntity(generator, format, entity, isTableEntry, opContext);
- }
- finally {
- generator.close();
- }
- }
-
private static void writeJsonProperty(JsonGenerator generator, EntrytimeStamp
value for the entity.
+ * Sets the timeStamp
value for the entity. Note that the timestamp property is a read-only property,
+ * set by the service only.
*
* @param timeStamp
* A java.util.Date
containing the timeStamp
value for the entity.
- * @deprecated as of 3.0.0. The timestamp property is a read-only property, set by the service only.
*/
- @Deprecated
@Override
public void setTimestamp(final Date timeStamp) {
this.timeStamp = timeStamp;
diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableStorageErrorDeserializer.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableStorageErrorDeserializer.java
index 7f9fbfb00..85317004d 100644
--- a/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableStorageErrorDeserializer.java
+++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/table/TableStorageErrorDeserializer.java
@@ -20,17 +20,13 @@
import java.io.Reader;
import java.util.HashMap;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.microsoft.azure.storage.Constants;
import com.microsoft.azure.storage.StorageExtendedErrorInformation;
-import com.microsoft.azure.storage.core.SR;
+import com.microsoft.azure.storage.core.JsonUtilities;
import com.microsoft.azure.storage.core.StorageRequest;
/***
@@ -38,46 +34,6 @@
*/
final class TableStorageErrorDeserializer {
- /**
- * Gets the Extended Error information.
- *
- * @return the Extended Error information.
- *
- * @param reader
- * the input stream to read error details from.
- * @param format
- * The {@link TablePayloadFormat} to use for parsing
- * @throws XMLStreamException
- * if an error occurs while accessing the stream with AtomPub.
- * @throws IOException
- * if an error occurs while accessing the stream with Json.
- * @throws JsonParseException
- * if an error occurs while parsing the stream.
- */
- @SuppressWarnings("deprecation")
- public static StorageExtendedErrorInformation getExtendedErrorInformation(final Reader reader,
- final TablePayloadFormat format) throws JsonParseException, IOException, XMLStreamException {
- if (format == TablePayloadFormat.AtomPub) {
- XMLStreamReader xmlr = DeserializationHelper.createXMLStreamReaderFromReader(reader);
- try {
- return parseAtomResponse(xmlr);
- }
- finally {
- xmlr.close();
- }
- }
- else {
- JsonFactory jsonFactory = new JsonFactory();
- JsonParser parser = jsonFactory.createParser(reader);
- try {
- return parseJsonResponse(parser);
- }
- finally {
- parser.close();
- }
- }
- }
-
/**
* Parse the table extended error information from the response body.
*
@@ -86,245 +42,138 @@ public static StorageExtendedErrorInformation getExtendedErrorInformation(final
* @return The {@link StorageExtendedErrorInformation} parsed from the body or null if parsing fails or the request
* contains no body.
*/
- @SuppressWarnings({"deprecation" })
public static StorageExtendedErrorInformation parseErrorDetails(StorageRequest