From 5a65fb23df43d94795696b44860bdec17533cdcc Mon Sep 17 00:00:00 2001 From: veudayab Date: Thu, 9 May 2013 13:19:42 -0700 Subject: [PATCH 01/17] Test commit --- .../windowsazure/services/blob/client/BlobTestBase.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java index cba0245c4270..a2cc575d3a7b 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java @@ -30,7 +30,7 @@ */ public class BlobTestBase { public static boolean USE_DEV_FABRIC = false; - public static final String CLOUD_ACCOUNT_HTTP = "DefaultEndpointsProtocol=https;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; + public static final String CLOUD_ACCOUNT_HTTP = "DefaultEndpointsProtocol=http;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; public static final String CLOUD_ACCOUNT_HTTPS = "DefaultEndpointsProtocol=https;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; protected static CloudStorageAccount httpAcc; @@ -45,8 +45,9 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK } else { String cloudAccount = CLOUD_ACCOUNT_HTTP; - cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("blob.accountName")); - cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("blob.accountKey")); + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", "jaidb3"); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", + "+qjm/8MjakncuZwpjNfYtaKDHrJH3zkQAKDywuTNh9hdb3ETcQ4wweVdX3nzFsXsWkI5la8EZg04PIbPkWrWBQ=="); httpAcc = CloudStorageAccount.parse(cloudAccount); } From e4d4e21b47ed19b306a2c5573afb9c1d3f393583 Mon Sep 17 00:00:00 2001 From: veudayab Date: Thu, 9 May 2013 13:24:04 -0700 Subject: [PATCH 02/17] Include HttpURLConnection in the executor task to drain the response after every request --- .../services/blob/client/CloudBlob.java | 19 ++++++++++++++- .../services/blob/client/CloudBlobClient.java | 1 + .../blob/client/CloudBlobContainer.java | 15 ++++++++++++ .../services/blob/client/CloudBlockBlob.java | 4 ++++ .../services/blob/client/CloudPageBlob.java | 3 +++ .../storage/AccessPolicyResponseBase.java | 6 ----- .../services/core/storage/utils/Utility.java | 9 +++++-- .../utils/implementation/ExecutionEngine.java | 21 +++++++++++++++- .../implementation/StorageOperation.java | 24 +++++++++++++++++-- .../services/queue/client/CloudQueue.java | 15 ++++++++++++ .../queue/client/CloudQueueClient.java | 1 + .../services/table/client/CloudTable.java | 2 ++ .../table/client/CloudTableClient.java | 19 ++++++--------- .../table/client/QueryTableOperation.java | 10 +++----- .../table/client/TableBatchOperation.java | 23 ++++++++---------- .../services/table/client/TableOperation.java | 13 +++++----- 16 files changed, 134 insertions(+), 51 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java index 84e345591cc5..10193bc590c6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java @@ -295,7 +295,7 @@ public String execute(final CloudBlobClient client, final CloudBlob blob, final final HttpURLConnection request = BlobRequest.lease(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), LeaseAction.ACQUIRE, leaseTimeInSeconds, proposedLeaseId, null, accessCondition, blobOptions, opContext); - + this.setConnection(request); client.getCredentials().signRequest(request, 0L); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -407,6 +407,7 @@ public Long execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.lease(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), LeaseAction.BREAK, null, null, breakPeriodInSeconds, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -540,6 +541,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.copyFrom(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), source.toString(), blob.snapshotID, sourceAccessCondition, destinationAccessCondition, blobOptions, opContext); + this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); client.getCredentials().signRequest(request, 0); @@ -620,6 +622,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.abortCopy(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), copyId, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0); @@ -695,6 +698,7 @@ public CloudBlob execute(final CloudBlobClient client, final CloudBlob blob, final HttpURLConnection request = BlobRequest.snapshot(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -784,6 +788,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.delete(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), blob.snapshotID, deleteSnapshotsOption, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -875,6 +880,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlob blob, final final HttpURLConnection request = BlobRequest.delete(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), blob.snapshotID, deleteSnapshotsOption, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -959,6 +965,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.get(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), blob.snapshotID, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); final InputStream streamRef = ExecutionEngine.getInputStream(request, opContext, this.getResult()); @@ -1137,6 +1144,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.getProperties(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), blob.snapshotID, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -1290,6 +1298,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.get(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), blob.snapshotID, blobOffset, length, accessCondition, blobOptions, opContext); + this.setConnection(request); if (blobOptions.getUseTransactionalContentMD5()) { request.setRequestProperty(Constants.HeaderConstants.RANGE_GET_CONTENT_MD5, "true"); @@ -1430,6 +1439,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlob blob, final final HttpURLConnection request = BlobRequest.getProperties(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), blob.snapshotID, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -1917,6 +1927,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.lease(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), LeaseAction.RELEASE, null, null, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -1997,6 +2008,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.lease(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), LeaseAction.RENEW, null, null, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -2086,6 +2098,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.lease(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), LeaseAction.CHANGE, null, proposedLeaseId, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -2213,6 +2226,7 @@ public Long execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.lease(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), LeaseAction.BREAK, null, null, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -2351,6 +2365,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.put(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), blob.properties, blob.properties.getBlobType(), 0, accessCondition, blobOptions, opContext); + this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); @@ -2436,6 +2451,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.setMetadata(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), accessCondition, blobOptions, opContext); + this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); client.getCredentials().signRequest(request, 0L); @@ -2510,6 +2526,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.setProperties(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), blob.properties, null, accessCondition, blobOptions, opContext); + this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); client.getCredentials().signRequest(request, 0L); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java index c000b97c98ed..4a85876d6c98 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java @@ -385,6 +385,7 @@ ResultSegment listContainersCore(final String prefix, final HttpURLConnection listContainerRequest = ContainerRequest.list(this.getEndpoint(), options.getTimeoutIntervalInMs(), listingContext, detailsIncluded, opContext); + taskReference.setConnection(listContainerRequest); this.getCredentials().signRequest(listContainerRequest, -1L); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java index b1d1a7a6c8db..0465a0e5d034 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java @@ -220,6 +220,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final OperationContext opContext) throws Exception { final HttpURLConnection request = ContainerRequest.create(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); ContainerRequest.addMetadata(request, container.metadata, opContext); client.getCredentials().signRequest(request, 0L); @@ -294,6 +295,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlobContainer co final OperationContext opContext) throws Exception { final HttpURLConnection request = ContainerRequest.create(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); ContainerRequest.addMetadata(request, container.metadata, opContext); client.getCredentials().signRequest(request, 0L); @@ -387,6 +389,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final HttpURLConnection request = ContainerRequest.delete(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -457,6 +460,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlobContainer co final HttpURLConnection request = ContainerRequest.delete(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -530,6 +534,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final OperationContext opContext) throws Exception { final HttpURLConnection request = ContainerRequest.getProperties(container.uri, this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -607,6 +612,7 @@ public BlobContainerPermissions execute(final CloudBlobClient client, final Clou final HttpURLConnection request = ContainerRequest.getAcl(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -686,6 +692,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlobContainer co final OperationContext opContext) throws Exception { final HttpURLConnection request = ContainerRequest.getProperties(container.uri, this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -1105,6 +1112,7 @@ ResultSegment listBlobsCore(final String prefix, final boolean use final HttpURLConnection listBlobsRequest = BlobRequest.list(this.getTransformedAddress(), options.getTimeoutIntervalInMs(), listingContext, options, opContext); + taskReference.setConnection(listBlobsRequest); this.blobServiceClient.getCredentials().signRequest(listBlobsRequest, -1L); @@ -1529,6 +1537,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final HttpURLConnection request = ContainerRequest.setMetadata(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); ContainerRequest.addMetadata(request, container.metadata, opContext); client.getCredentials().signRequest(request, 0L); @@ -1603,6 +1612,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final HttpURLConnection request = ContainerRequest.setAcl(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), permissions.getPublicAccess(), opContext); + this.setConnection(request); final StringWriter outBuffer = new StringWriter(); @@ -1707,6 +1717,7 @@ public String execute(final CloudBlobClient client, final CloudBlobContainer con final HttpURLConnection request = ContainerRequest.lease(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), LeaseAction.ACQUIRE, leaseTimeInSeconds, proposedLeaseId, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -1789,6 +1800,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final HttpURLConnection request = ContainerRequest.lease(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), LeaseAction.RENEW, null, null, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -1871,6 +1883,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final HttpURLConnection request = ContainerRequest.lease(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), LeaseAction.RELEASE, null, null, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -1956,6 +1969,7 @@ public Long execute(final CloudBlobClient client, final CloudBlobContainer conta final HttpURLConnection request = ContainerRequest.lease(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), LeaseAction.BREAK, null, null, breakPeriodInSeconds, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); @@ -2048,6 +2062,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta final HttpURLConnection request = ContainerRequest.lease(container.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), LeaseAction.CHANGE, null, proposedLeaseId, null, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, 0L); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java index 9ee73d83c1d1..91ad867eac9b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java @@ -184,6 +184,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.putBlockList(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), blob.properties, accessCondition, blobOptions, opContext); + this.setConnection(request); + BlobRequest.addMetadata(request, blob.metadata, opContext); // Potential optimization, we can write this stream outside of @@ -290,6 +292,7 @@ public ArrayList execute(final CloudBlobClient client, final CloudBl final HttpURLConnection request = BlobRequest.getBlockList(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), blob.snapshotID, blockListingFilter, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -615,6 +618,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.putBlock(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), blockId, accessCondition, blobOptions, opContext); + this.setConnection(request); if (blobOptions.getUseTransactionalContentMD5()) { request.setRequestProperty(Constants.HeaderConstants.CONTENT_MD5, md5); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java index d81af25c6267..90ef8038334a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java @@ -267,6 +267,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.put(blob.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), blob.properties, BlobType.PAGE_BLOB, length, accessCondition, blobOptions, opContext); + this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); @@ -349,6 +350,7 @@ public ArrayList execute(final CloudBlobClient client, final CloudBlo final HttpURLConnection request = BlobRequest.getPageRanges(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), blob.snapshotID, accessCondition, blobOptions, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -471,6 +473,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op final HttpURLConnection request = BlobRequest.putPage(blob.getTransformedAddress(opContext), blobOptions.getTimeoutIntervalInMs(), pageProperties, accessCondition, blobOptions, opContext); + this.setConnection(request); if (pageProperties.getPageOperation() == PageOperationType.UPDATE) { if (blobOptions.getUseTransactionalContentMD5()) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AccessPolicyResponseBase.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AccessPolicyResponseBase.java index 7d03cb86b677..a1c748afcad1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AccessPolicyResponseBase.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AccessPolicyResponseBase.java @@ -94,15 +94,9 @@ public void parseResponse() throws XMLStreamException, ParseException { if (eventType == XMLStreamConstants.START_ELEMENT && name.equals(Constants.SIGNED_IDENTIFIERS_ELEMENT)) { this.readPolicies(xmlr); - } - else if (eventType == XMLStreamConstants.END_ELEMENT - && name.equals(Constants.SIGNED_IDENTIFIERS_ELEMENT)) { break; } } - else if (eventType == XMLStreamConstants.END_DOCUMENT) { - break; - } } this.isParsed = true; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/Utility.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/Utility.java index 37c099517e7d..54e66cd05b83 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/Utility.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/Utility.java @@ -1015,7 +1015,10 @@ public static StreamMd5AndLength writeToOutputStream(final InputStream sourceStr count = sourceStream.read(retrievedBuff, 0, nextCopy); while (nextCopy > 0 && count != -1) { - outStream.write(retrievedBuff, 0, count); + if (outStream != null) { + outStream.write(retrievedBuff, 0, count); + } + if (calculateMD5) { opContext.getIntermediateMD5().update(retrievedBuff, 0, count); } @@ -1029,7 +1032,9 @@ public static StreamMd5AndLength writeToOutputStream(final InputStream sourceStr count = sourceStream.read(retrievedBuff, 0, nextCopy); } - outStream.flush(); + if (outStream != null) { + outStream.flush(); + } if (calculateMD5) { retVal.setDigest(opContext.getIntermediateMD5()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/ExecutionEngine.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/ExecutionEngine.java index 9d3ad41e569a..9e60f511677b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/ExecutionEngine.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/ExecutionEngine.java @@ -36,6 +36,7 @@ import com.microsoft.windowsazure.services.core.storage.SendingRequestEvent; import com.microsoft.windowsazure.services.core.storage.StorageErrorCodeStrings; import com.microsoft.windowsazure.services.core.storage.StorageException; +import com.microsoft.windowsazure.services.core.storage.utils.Utility; import com.microsoft.windowsazure.services.table.client.TableServiceException; /** @@ -113,7 +114,25 @@ public static RESULT_TYPE executeWithRet opContext.setClientTimeInMs(new Date().getTime() - startTime); if (!task.isNonExceptionedRetryableFailure()) { - // Success return result, the rest of the return paths throw. + // Success return result and drain the input stream. + HttpURLConnection request = task.getConnection(); + if ((task.getResult().getStatusCode() >= 200) && (task.getResult().getStatusCode() < 300)) { + if (request != null) { + InputStream inStream = request.getInputStream(); + try { + Utility.writeToOutputStream(inStream, null, -1, false, false, task.getResult(), null); + } + // At this point, we already have a result / exception to return to the user. + // This is just an optimization to improve socket reuse. + catch (final IOException ex) { + } + catch (StorageException e) { + } + finally { + inStream.close(); + } + } + } return result; } else { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java index 803bbdfa5481..a18d41dc19dd 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java @@ -39,7 +39,7 @@ public abstract class StorageOperation { private StorageException exceptionReference; /** - * A flag to indicate a failure which did not result in an exceptin, i.e a 400 class status code. + * A flag to indicate a failure which did not result in an exception, i.e a 400 class status code. */ private boolean nonExceptionedRetryableFailure; @@ -53,6 +53,11 @@ public abstract class StorageOperation { */ private RequestResult result; + /** + * Holds the url connection for the operation. + */ + private HttpURLConnection connection; + /** * Default Ctor. */ @@ -106,6 +111,13 @@ public final RequestResult getResult() { return this.result; } + /** + * @return the URL connection + */ + public final HttpURLConnection getConnection() { + return this.connection; + } + /** * Resets the operation status flags between operations. */ @@ -126,7 +138,7 @@ public final boolean isNonExceptionedRetryableFailure() { } /** - * Returns either the held exception from the operation if it is set, othwerwise the translated exception. + * Returns either the held exception from the operation if it is set, otherwise the translated exception. * * @param request * the reference to the HttpURLConnection for the operation. @@ -174,4 +186,12 @@ protected final void setRequestOptions(final RequestOptions requestOptions) { public final void setResult(final RequestResult result) { this.result = result; } + + /** + * @param connection + * the connection to set + */ + public final void setConnection(final HttpURLConnection connection) { + this.connection = connection; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java index c29f1067844c..15b646e33651 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java @@ -213,6 +213,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final HttpURLConnection request = QueueRequest.putMessage(queue.getMessageRequestAddress(opContext), this.getRequestOptions().getTimeoutIntervalInMs(), initialVisibilityDelayInSeconds, timeToLiveInSeconds, opContext); + this.setConnection(request); final byte[] messageBytes = QueueRequest.generateMessageRequestBody(stringToSend); @@ -283,6 +284,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final HttpURLConnection request = QueueRequest.clearMessages(queue.getMessageRequestAddress(opContext), this.getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -347,6 +349,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final throws Exception { final HttpURLConnection request = QueueRequest.create(queue.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); QueueRequest.addMetadata(request, queue.metadata, opContext); client.getCredentials().signRequest(request, 0L); @@ -420,6 +423,7 @@ public Boolean execute(final CloudQueueClient client, final CloudQueue queue, final OperationContext opContext) throws Exception { final HttpURLConnection request = QueueRequest.create(queue.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); QueueRequest.addMetadata(request, queue.metadata, opContext); client.getCredentials().signRequest(request, 0L); @@ -506,6 +510,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final throws Exception { final HttpURLConnection request = QueueRequest.delete(queue.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -577,6 +582,7 @@ public Boolean execute(final CloudQueueClient client, final CloudQueue queue, final OperationContext opContext) throws Exception { final HttpURLConnection request = QueueRequest.delete(queue.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -664,6 +670,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final HttpURLConnection request = QueueRequest.deleteMessage(queue.getIndividualMessageAddress( messageId, opContext), this.getRequestOptions().getTimeoutIntervalInMs(), messagePopReceipt, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -730,6 +737,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final HttpURLConnection request = QueueRequest.downloadAttributes( queue.getTransformedAddress(opContext), this.getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -803,6 +811,7 @@ public Boolean execute(final CloudQueueClient client, final CloudQueue queue, final HttpURLConnection request = QueueRequest.downloadAttributes( queue.getTransformedAddress(opContext), this.getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -1018,6 +1027,7 @@ public ArrayList execute(final CloudQueueClient client, final final HttpURLConnection request = QueueRequest.peekMessages(queue.getMessageRequestAddress(opContext), this.getRequestOptions().getTimeoutIntervalInMs(), numberOfMessages, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -1152,6 +1162,7 @@ public ArrayList execute(final CloudQueueClient client, final final HttpURLConnection request = QueueRequest.retrieveMessages( queue.getMessageRequestAddress(opContext), this.getRequestOptions().getTimeoutIntervalInMs(), numberOfMessages, visibilityTimeoutInSeconds, opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); @@ -1280,6 +1291,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final HttpURLConnection request = QueueRequest.updateMessage(queue.getIndividualMessageAddress( message.getId(), opContext), this.getRequestOptions().getTimeoutIntervalInMs(), message .getPopReceipt(), visibilityTimeoutInSeconds, opContext); + this.setConnection(request); if (messageUpdateFields.contains(MessageUpdateFields.CONTENT)) { final byte[] messageBytes = QueueRequest.generateMessageRequestBody(stringToSend); @@ -1362,6 +1374,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final HttpURLConnection request = QueueRequest.setMetadata(queue.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); QueueRequest.addMetadata(request, queue.metadata, opContext); client.getCredentials().signRequest(request, 0L); @@ -1435,6 +1448,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final HttpURLConnection request = QueueRequest.setAcl(queue.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); final StringWriter outBuffer = new StringWriter(); @@ -1512,6 +1526,7 @@ public QueuePermissions execute(final CloudQueueClient client, final CloudQueue final HttpURLConnection request = QueueRequest.getAcl(queue.getTransformedAddress(opContext), this .getRequestOptions().getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequest(request, -1L); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java index addec40b3b9c..7f1f12938aa0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java @@ -224,6 +224,7 @@ ResultSegment listQueuesCore(final String prefix, final QueueListing final HttpURLConnection listQueueRequest = QueueRequest.list(this.getEndpoint(), options.getTimeoutIntervalInMs(), listingContext, detailsIncluded, opContext); + taskReference.setConnection(listQueueRequest); this.getCredentials().signRequest(listQueueRequest, -1L); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java index f13eac657acf..47dc6bce8f9c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java @@ -483,6 +483,7 @@ public Void execute(final CloudTableClient client, final CloudTable table, final final HttpURLConnection request = TableRequest.setAcl(table.uri, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); final StringWriter outBuffer = new StringWriter(); @@ -561,6 +562,7 @@ public TablePermissions execute(final CloudTableClient client, final CloudTable final HttpURLConnection request = TableRequest.getAcl(table.uri, tableName, this.getRequestOptions() .getTimeoutIntervalInMs(), opContext); + this.setConnection(request); client.getCredentials().signRequestLite(request, -1L, opContext); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java index 26a506cc39a6..8a240fe9bb9d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java @@ -797,9 +797,9 @@ protected ResultSegment executeQuerySegmentedCore( final HttpURLConnection queryRequest = TableRequest.query(this.getTransformedEndPoint(opContext), queryToExecute.getSourceTableName(), null/* identity */, options.getTimeoutIntervalInMs(), queryToExecute.generateQueryBuilder(), continuationToken, options, opContext); + taskReference.setConnection(queryRequest); this.getCredentials().signRequestLite(queryRequest, -1L, opContext); - ExecutionEngine.processRequest(queryRequest, opContext, taskReference.getResult()); if (taskReference.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { @@ -812,18 +812,13 @@ protected ResultSegment executeQuerySegmentedCore( InputStream inStream = queryRequest.getInputStream(); - try { - if (resolver == null) { - clazzResponse = (ODataPayload) AtomPubParser.parseResponse(inStream, queryToExecute.getClazzType(), - null, opContext); - } - else { - resolvedResponse = (ODataPayload) AtomPubParser.parseResponse(inStream, - queryToExecute.getClazzType(), resolver, opContext); - } + if (resolver == null) { + clazzResponse = (ODataPayload) AtomPubParser.parseResponse(inStream, queryToExecute.getClazzType(), + null, opContext); } - finally { - inStream.close(); + else { + resolvedResponse = (ODataPayload) AtomPubParser.parseResponse(inStream, queryToExecute.getClazzType(), + resolver, opContext); } final ResultContinuation nextToken = TableResponse.getTableContinuationFromResponse(queryRequest); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java index 14c130540b18..e92207cd4ae4 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java @@ -186,6 +186,7 @@ public TableResult execute(final CloudTableClient client, final QueryTableOperat tableName, generateRequestIdentity(isTableEntry, operation.getPartitionKey(), false), options.getTimeoutIntervalInMs(), null/* Query Builder */, null/* Continuation Token */, options, opContext); + this.setConnection(request); client.getCredentials().signRequestLite(request, -1L, opContext); @@ -197,13 +198,8 @@ tableName, generateRequestIdentity(isTableEntry, operation.getPartitionKey(), fa final XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(inStream); TableResult res = null; - try { - res = AtomPubParser.parseSingleOpResponse(xmlr, this.getResult().getStatusCode(), - operation.getClazzType(), operation.getResolver(), opContext); - } - finally { - inStream.close(); - } + res = AtomPubParser.parseSingleOpResponse(xmlr, this.getResult().getStatusCode(), + operation.getClazzType(), operation.getResolver(), opContext); return res; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java index a2e814a92e00..90b773477e55 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java @@ -393,6 +393,7 @@ public ArrayList execute(final CloudTableClient client, final Table final HttpURLConnection request = TableRequest.batch(client.getTransformedEndPoint(opContext), options.getTimeoutIntervalInMs(), batchID, null, options, opContext); + this.setConnection(request); client.getCredentials().signRequestLite(request, -1L, opContext); @@ -401,22 +402,18 @@ public ArrayList execute(final CloudTableClient client, final Table final InputStream streamRef = ExecutionEngine.getInputStream(request, opContext, this.getResult()); ArrayList responseParts = null; - try { - final String contentType = request.getHeaderField(Constants.HeaderConstants.CONTENT_TYPE); - - final String[] headerVals = contentType.split("multipart/mixed; boundary="); - if (headerVals == null || headerVals.length != 2) { - throw new StorageException(StorageErrorCodeStrings.OUT_OF_RANGE_INPUT, - "An incorrect Content-type was returned from the server.", - Constants.HeaderConstants.HTTP_UNUSED_306, null, null); - } - responseParts = MimeHelper.readBatchResponseStream(streamRef, headerVals[1], opContext); - } - finally { - streamRef.close(); + final String contentType = request.getHeaderField(Constants.HeaderConstants.CONTENT_TYPE); + + final String[] headerVals = contentType.split("multipart/mixed; boundary="); + if (headerVals == null || headerVals.length != 2) { + throw new StorageException(StorageErrorCodeStrings.OUT_OF_RANGE_INPUT, + "An incorrect Content-type was returned from the server.", + Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } + responseParts = MimeHelper.readBatchResponseStream(streamRef, headerVals[1], opContext); + ExecutionEngine.getResponseCode(this.getResult(), request, opContext); if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_ACCEPTED) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java index 65987567691c..72d385e1996a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java @@ -259,6 +259,7 @@ public TableResult execute(final CloudTableClient client, final TableOperation o final HttpURLConnection request = TableRequest.delete(client.getTransformedEndPoint(opContext), tableName, generateRequestIdentity(isTableEntry, tableIdentity, false), operation.getEntity() .getEtag(), options.getTimeoutIntervalInMs(), null, options, opContext); + this.setConnection(request); client.getCredentials().signRequestLite(request, -1L, opContext); @@ -327,6 +328,7 @@ public TableResult execute(final CloudTableClient client, final TableOperation o tableName, generateRequestIdentity(isTableEntry, tableIdentity, false), operation.opType != TableOperationType.INSERT ? operation.getEntity().getEtag() : null, operation.opType.getUpdateType(), options.getTimeoutIntervalInMs(), null, options, opContext); + this.setConnection(request); client.getCredentials().signRequestLite(request, -1L, opContext); @@ -348,13 +350,8 @@ tableName, generateRequestIdentity(isTableEntry, tableIdentity, false), InputStream inStream = request.getInputStream(); TableResult res = null; - try { - final XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(inStream); - res = operation.parseResponse(xmlr, this.getResult().getStatusCode(), null, opContext); - } - finally { - inStream.close(); - } + final XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(inStream); + res = operation.parseResponse(xmlr, this.getResult().getStatusCode(), null, opContext); return res; } @@ -413,6 +410,7 @@ public TableResult execute(final CloudTableClient client, final TableOperation o final HttpURLConnection request = TableRequest.merge(client.getTransformedEndPoint(opContext), tableName, generateRequestIdentity(false, null, false), operation.getEntity().getEtag(), options.getTimeoutIntervalInMs(), null, options, opContext); + this.setConnection(request); client.getCredentials().signRequestLite(request, -1L, opContext); @@ -479,6 +477,7 @@ public TableResult execute(final CloudTableClient client, final TableOperation o final HttpURLConnection request = TableRequest.update(client.getTransformedEndPoint(opContext), tableName, generateRequestIdentity(false, null, false), operation.getEntity().getEtag(), options.getTimeoutIntervalInMs(), null, options, opContext); + this.setConnection(request); client.getCredentials().signRequestLite(request, -1L, opContext); From 305003149d27b582633288ee6bddfc282e779478 Mon Sep 17 00:00:00 2001 From: veudayab Date: Thu, 9 May 2013 13:28:04 -0700 Subject: [PATCH 03/17] Unit test fixes --- .../windowsazure/services/blob/client/BlobTestBase.java | 5 ++--- .../windowsazure/services/queue/client/QueueTestBase.java | 2 +- .../windowsazure/services/table/client/TableTestBase.java | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java index a2cc575d3a7b..3da51d425a0e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java @@ -45,9 +45,8 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK } else { String cloudAccount = CLOUD_ACCOUNT_HTTP; - cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", "jaidb3"); - cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", - "+qjm/8MjakncuZwpjNfYtaKDHrJH3zkQAKDywuTNh9hdb3ETcQ4wweVdX3nzFsXsWkI5la8EZg04PIbPkWrWBQ=="); + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("blob.accountName")); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("blob.accountKey")); httpAcc = CloudStorageAccount.parse(cloudAccount); } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java index e44acb2a2100..831bbf6ca30d 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java @@ -31,7 +31,7 @@ */ public class QueueTestBase { public static boolean USE_DEV_FABRIC = false; - public static final String CLOUD_ACCOUNT_HTTP = "DefaultEndpointsProtocol=https;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; + public static final String CLOUD_ACCOUNT_HTTP = "DefaultEndpointsProtocol=http;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; public static final String CLOUD_ACCOUNT_HTTPS = "DefaultEndpointsProtocol=https;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; protected static CloudStorageAccount httpAcc; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java index 80c7ce30738a..bb4d9d1a156d 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java @@ -35,7 +35,7 @@ */ public class TableTestBase { public static boolean USE_DEV_FABRIC = false; - public static final String CLOUD_ACCOUNT_HTTP = "DefaultEndpointsProtocol=https;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; + public static final String CLOUD_ACCOUNT_HTTP = "DefaultEndpointsProtocol=http;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; public static final String CLOUD_ACCOUNT_HTTPS = "DefaultEndpointsProtocol=https;AccountName=[ACCOUNT NAME];AccountKey=[ACCOUNT KEY]"; public static class class1 extends TableServiceEntity { From f88ea6c024cd8d544803ec562dd4bf12d1db2666 Mon Sep 17 00:00:00 2001 From: veudayab Date: Tue, 28 May 2013 11:22:01 -0700 Subject: [PATCH 04/17] Support all flavors of sharedkeysigning in java --- .../services/blob/client/CloudBlob.java | 41 ++-- .../services/blob/client/CloudBlobClient.java | 2 +- .../blob/client/CloudBlobContainer.java | 35 ++-- .../services/blob/client/CloudBlockBlob.java | 8 +- .../services/blob/client/CloudPageBlob.java | 9 +- .../core/storage/AuthenticationScheme.java | 30 +++ .../services/core/storage/ServiceClient.java | 35 +++- .../core/storage/StorageCredentials.java | 175 ++++++++++++++++- .../StorageCredentialsAccountAndKey.java | 176 +++++++++++++++++- .../storage/StorageCredentialsAnonymous.java | 70 ++++++- ...orageCredentialsSharedAccessSignature.java | 84 ++++++++- .../utils/implementation/BaseRequest.java | 35 +++- .../utils/implementation/Canonicalizer.java | 78 +++++++- .../implementation/CanonicalizerFactory.java | 20 +- .../implementation/StorageOperation.java | 23 +++ .../TableFullCanonicalizer.java | 57 ++++++ .../TableLiteCanonicalizer.java | 10 +- .../services/queue/client/CloudQueue.java | 39 ++-- .../queue/client/CloudQueueClient.java | 2 +- .../services/table/client/CloudTable.java | 6 +- .../table/client/CloudTableClient.java | 3 +- .../table/client/QueryTableOperation.java | 2 +- .../table/client/TableBatchOperation.java | 2 +- .../services/table/client/TableOperation.java | 8 +- .../services/blob/client/BlobTestBase.java | 2 + .../blob/client/CloudBlobContainerTests.java | 43 +++++ .../queue/client/CloudQueueTests.java | 32 ++++ .../services/queue/client/QueueTestBase.java | 2 + .../table/client/TableClientTests.java | 25 +++ .../services/table/client/TableTestBase.java | 2 + 30 files changed, 958 insertions(+), 98 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AuthenticationScheme.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableFullCanonicalizer.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java index 10193bc590c6..578019fa34c0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java @@ -296,7 +296,8 @@ public String execute(final CloudBlobClient client, final CloudBlob blob, final .getRequestOptions().getTimeoutIntervalInMs(), LeaseAction.ACQUIRE, leaseTimeInSeconds, proposedLeaseId, null, accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -409,7 +410,7 @@ public Long execute(final CloudBlobClient client, final CloudBlob blob, final Op breakPeriodInSeconds, accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -544,7 +545,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); - client.getCredentials().signRequest(request, 0); + + this.signRequest(client, request, 0, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -624,7 +626,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op blobOptions.getTimeoutIntervalInMs(), copyId, accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0); + this.signRequest(client, request, 0, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -700,7 +702,7 @@ public CloudBlob execute(final CloudBlobClient client, final CloudBlob blob, .getRequestOptions().getTimeoutIntervalInMs(), accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -790,7 +792,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -882,7 +884,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlob blob, final accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -967,7 +969,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op blobOptions.getTimeoutIntervalInMs(), blob.snapshotID, accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); + final InputStream streamRef = ExecutionEngine.getInputStream(request, opContext, this.getResult()); final String contentMD5 = request.getHeaderField(Constants.HeaderConstants.CONTENT_MD5); @@ -1146,7 +1149,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1304,7 +1307,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op request.setRequestProperty(Constants.HeaderConstants.RANGE_GET_CONTENT_MD5, "true"); } - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); final InputStream sourceStream = ExecutionEngine.getInputStream(request, opContext, this.getResult()); @@ -1441,7 +1444,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlob blob, final opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1929,7 +1932,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -2010,7 +2013,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -2100,7 +2103,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -2228,7 +2231,7 @@ public Long execute(final CloudBlobClient client, final CloudBlob blob, final Op accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -2369,7 +2372,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op BlobRequest.addMetadata(request, blob.metadata, opContext); - client.getCredentials().signRequest(request, length); + this.signRequest(client, request, length, null); final StreamMd5AndLength descriptor = Utility.writeToOutputStream(sourceStream, request.getOutputStream(), length, true, false, null, opContext); @@ -2454,7 +2457,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -2529,7 +2533,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op this.setConnection(request); BlobRequest.addMetadata(request, blob.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java index 4a85876d6c98..5113afab641d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobClient.java @@ -387,7 +387,7 @@ ResultSegment listContainersCore(final String prefix, options.getTimeoutIntervalInMs(), listingContext, detailsIncluded, opContext); taskReference.setConnection(listContainerRequest); - this.getCredentials().signRequest(listContainerRequest, -1L); + taskReference.signRequest(this, listContainerRequest, -1L, null); ExecutionEngine.processRequest(listContainerRequest, opContext, taskReference.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java index 0465a0e5d034..10e2a450a514 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java @@ -223,7 +223,8 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta this.setConnection(request); ContainerRequest.addMetadata(request, container.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -298,7 +299,8 @@ public Boolean execute(final CloudBlobClient client, final CloudBlobContainer co this.setConnection(request); ContainerRequest.addMetadata(request, container.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -391,7 +393,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta .getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -462,7 +464,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlobContainer co .getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -536,7 +538,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta .getRequestOptions().getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -614,7 +616,7 @@ public BlobContainerPermissions execute(final CloudBlobClient client, final Clou .getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -694,7 +696,7 @@ public Boolean execute(final CloudBlobClient client, final CloudBlobContainer co .getRequestOptions().getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1114,7 +1116,7 @@ ResultSegment listBlobsCore(final String prefix, final boolean use options.getTimeoutIntervalInMs(), listingContext, options, opContext); taskReference.setConnection(listBlobsRequest); - this.blobServiceClient.getCredentials().signRequest(listBlobsRequest, -1L); + taskReference.signRequest(this.blobServiceClient, listBlobsRequest, -1L, null); ExecutionEngine.processRequest(listBlobsRequest, opContext, taskReference.getResult()); @@ -1540,7 +1542,8 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta this.setConnection(request); ContainerRequest.addMetadata(request, container.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1619,7 +1622,9 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta ContainerRequest.writeSharedAccessIdentifiersToStream(permissions.getSharedAccessPolicies(), outBuffer); final byte[] aclBytes = outBuffer.toString().getBytes("UTF8"); - client.getCredentials().signRequest(request, aclBytes.length); + + this.signRequest(client, request, aclBytes.length, null); + final OutputStream outStreamRef = request.getOutputStream(); outStreamRef.write(aclBytes); @@ -1719,7 +1724,7 @@ public String execute(final CloudBlobClient client, final CloudBlobContainer con accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1802,7 +1807,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1885,7 +1890,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1971,7 +1976,7 @@ public Long execute(final CloudBlobClient client, final CloudBlobContainer conta accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -2064,7 +2069,7 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java index 91ad867eac9b..d6724ed776ae 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlockBlob.java @@ -202,7 +202,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op request.setRequestProperty(Constants.HeaderConstants.CONTENT_MD5, descriptor.getMd5()); - client.getCredentials().signRequest(request, descriptor.getLength()); + this.signRequest(client, request, descriptor.getLength(), null); + Utility.writeToOutputStream(blockListInputStream, request.getOutputStream(), descriptor.getLength(), false, false, null, opContext); @@ -294,7 +295,7 @@ public ArrayList execute(final CloudBlobClient client, final CloudBl blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -624,7 +625,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op request.setRequestProperty(Constants.HeaderConstants.CONTENT_MD5, md5); } - client.getCredentials().signRequest(request, length); + this.signRequest(client, request, length, null); + Utility.writeToOutputStream(sourceStream, request.getOutputStream(), length, true /* rewindSourceStream */, false /* calculateMD5 */, null, opContext); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java index 90ef8038334a..38611d54063e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudPageBlob.java @@ -271,7 +271,7 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op BlobRequest.addMetadata(request, blob.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -352,7 +352,7 @@ public ArrayList execute(final CloudBlobClient client, final CloudBlo blobOptions.getTimeoutIntervalInMs(), blob.snapshotID, accessCondition, blobOptions, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -480,11 +480,12 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op request.setRequestProperty(Constants.HeaderConstants.CONTENT_MD5, md5); } - client.getCredentials().signRequest(request, length); + this.signRequest(client, request, length, null); + request.getOutputStream().write(data); } else { - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); } ExecutionEngine.processRequest(request, opContext, this.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AuthenticationScheme.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AuthenticationScheme.java new file mode 100644 index 000000000000..b2b898055046 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/AuthenticationScheme.java @@ -0,0 +1,30 @@ +/** + * 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.windowsazure.services.core.storage; + +/** + * Specifies the authentication scheme used to sign HTTP requests. + */ +public enum AuthenticationScheme { + /** + * Signs HTTP requests using the Shared Key Lite authentication scheme. + */ + SHAREDKEYLITE, + + /** + * Signs HTTP requests using the Shared Key authentication scheme. + */ + SHAREDKEYFULL; +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/ServiceClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/ServiceClient.java index 8a6df9f916f3..1360b9cedfb4 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/ServiceClient.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/ServiceClient.java @@ -57,6 +57,11 @@ public abstract class ServiceClient { */ protected int timeoutInMs = Constants.DEFAULT_TIMEOUT_IN_MS; + /** + * Holds the AuthenticationScheme associated with this Service Client. + */ + protected AuthenticationScheme authenticationScheme = AuthenticationScheme.SHAREDKEYFULL; + /** * Creates an instance of the ServiceClient class using the specified service endpoint. * @@ -142,8 +147,10 @@ public ServiceProperties execute(final ServiceClient client, final Void v, final final HttpURLConnection request = BaseRequest.getServiceProperties(client.getEndpoint(), this .getRequestOptions().getTimeoutIntervalInMs(), null, opContext); + this.setConnection(request); + + this.signRequest(client, request, -1, null); - client.getCredentials().signRequest(request, -1); ExecutionEngine.processRequest(request, opContext, this.getResult()); if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { @@ -167,6 +174,16 @@ public final StorageCredentials getCredentials() { return this.credentials; } + /** + * Returns the AuthenticationScheme associated with this service client. + * + * @return An {@link AuthenticationScheme} object that represents the authentication scheme associated with this + * client. + */ + public final AuthenticationScheme getAuthenticationScheme() { + return this.authenticationScheme; + } + /** * Returns the base URI for this service client. * @@ -229,6 +246,18 @@ protected final void setCredentials(final StorageCredentials credentials) { this.credentials = credentials; } + /** + * Sets the Authentication Scheme to use with this service client. + * + * @param scheme + * An AuthenticationScheme object that represents the authentication scheme being assigned + * for the service + * client. + */ + public final void setAuthenticationScheme(final AuthenticationScheme scheme) { + this.authenticationScheme = scheme; + } + /** * Sets the RetryPolicyFactory object to use when making service requests. * @@ -317,6 +346,7 @@ public Void execute(final ServiceClient client, final Void v, final OperationCon final HttpURLConnection request = BaseRequest.setServiceProperties(client.getEndpoint(), this .getRequestOptions().getTimeoutIntervalInMs(), null, opContext); + this.setConnection(request); final byte[] propertiesBytes = BaseRequest.serializeServicePropertiesToByteArray(properties, opContext); @@ -326,7 +356,8 @@ public Void execute(final ServiceClient client, final Void v, final OperationCon true /* rewindSourceStream */, true /* calculateMD5 */); request.setRequestProperty(Constants.HeaderConstants.CONTENT_MD5, descriptor.getMd5()); - client.getCredentials().signRequest(request, descriptor.getLength()); + this.signRequest(client, request, descriptor.getLength(), null); + Utility.writeToOutputStream(dataInputStream, request.getOutputStream(), descriptor.getLength(), false /* rewindSourceStream */, false /* calculateMD5 */, null, opContext); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java index 009a71655746..245ff1dd9142 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java @@ -39,8 +39,8 @@ public abstract class StorageCredentials { * Either include an account name with an account key (specifying values for * {@link CloudStorageAccount#ACCOUNT_NAME_NAME} and {@link CloudStorageAccount#ACCOUNT_KEY_NAME} ), or a * shared access signature (specifying a value for - * {@link CloudStorageAccount#SHARED_ACCESS_SIGNATURE_NAME} ). If you use an account name and account key, - * do not include a shared access signature, and vice versa. + * {@link CloudStorageAccount#SHARED_ACCESS_SIGNATURE_NAME} ). If you use an account name and account + * key, do not include a shared access signature, and vice versa. * * @return A {@link StorageCredentials} object representing the storage credentials determined from the name/value * pairs. @@ -81,8 +81,8 @@ protected static StorageCredentials tryParseCredentials(final HashMapString that contains the key/value pairs that represent the storage credentials. *

- * The format for the connection string is in the pattern "keyname=value". Multiple key/value pairs - * can be separated by a semi-colon, for example, "keyname1=value1;keyname2=value2". + * The format for the connection string is in the pattern "keyname=value". Multiple key/value + * pairs can be separated by a semi-colon, for example, "keyname1=value1;keyname2=value2". * * @return A {@link StorageCredentials} object representing the storage credentials determined from the connection * string. @@ -214,6 +214,9 @@ public static StorageCredentials tryParseCredentials(final String connectionStri /** * Signs a request under the Shared Key authentication scheme. * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -225,12 +228,16 @@ public static StorageCredentials tryParseCredentials(final String connectionStri * @throws StorageException * If a storage service error occurred. */ + @Deprecated public abstract void signRequest(HttpURLConnection request, long contentLength) throws InvalidKeyException, StorageException; /** * Signs a request using the specified operation context under the Shared Key authentication scheme. * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -245,11 +252,15 @@ public abstract void signRequest(HttpURLConnection request, long contentLength) * @throws StorageException * If a storage service error occurred. */ + @Deprecated public abstract void signRequest(HttpURLConnection request, long contentLength, OperationContext opContext) throws InvalidKeyException, StorageException; /** - * Signs a request under the Shared Key Lite authentication scheme. + * Signs a table request under the Shared Key Lite authentication scheme. + * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. * * @param request * An HttpURLConnection object that represents the request to sign. @@ -261,12 +272,15 @@ public abstract void signRequest(HttpURLConnection request, long contentLength, * @throws StorageException * If an unspecified storage exception occurs. */ + @Deprecated public abstract void signRequestLite(HttpURLConnection request, long contentLength) throws StorageException, InvalidKeyException; /** - * Signs a request using the specified operation context under the Shared Key Lite authentication scheme. + * Signs a table request using the specified operation context under the Shared Key Lite authentication scheme. * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -281,9 +295,157 @@ public abstract void signRequestLite(HttpURLConnection request, long contentLeng * @throws StorageException * If a storage service error occurred. */ + @Deprecated public abstract void signRequestLite(HttpURLConnection request, long contentLength, OperationContext opContext) throws StorageException, InvalidKeyException; + /** + * 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 abstract void signBlobAndQueueRequest(HttpURLConnection request, long contentLength) + throws InvalidKeyException, StorageException; + + /** + * Signs a request using the specified operation context 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + public abstract void signBlobAndQueueRequest(HttpURLConnection request, long contentLength, + OperationContext opContext) throws InvalidKeyException, StorageException; + + /** + * Signs a request under the Shared Key Lite 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 an unspecified storage exception occurs. + */ + public abstract void signBlobAndQueueRequestLite(HttpURLConnection request, long contentLength) + throws StorageException, InvalidKeyException; + + /** + * Signs a request using the specified operation context under the Shared Key Lite 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + public abstract void signBlobAndQueueRequestLite(HttpURLConnection request, long contentLength, + OperationContext opContext) throws StorageException, InvalidKeyException; + + /** + * Signs a table 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 abstract void signTableRequest(HttpURLConnection request, long contentLength) throws InvalidKeyException, + StorageException; + + /** + * Signs a table request using the specified operation context 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + public abstract void signTableRequest(HttpURLConnection request, long contentLength, OperationContext opContext) + throws InvalidKeyException, StorageException; + + /** + * Signs a table request under the Shared Key Lite 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 an unspecified storage exception occurs. + */ + public abstract void signTableRequestLite(HttpURLConnection request, long contentLength) throws StorageException, + InvalidKeyException; + + /** + * Signs a table request using the specified operation context under the Shared Key Lite 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + + public abstract void signTableRequestLite(HttpURLConnection request, long contentLength, OperationContext opContext) + throws StorageException, InvalidKeyException; + /** * Returns a String that represents this instance. * @@ -330,4 +492,5 @@ public abstract void signRequestLite(HttpURLConnection request, long contentLeng */ public abstract URI transformUri(URI resourceUri, OperationContext opContext) throws URISyntaxException, StorageException; + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java index 2881295c1f26..b0b27ab63d98 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java @@ -257,7 +257,7 @@ public void setCredentials(final Credentials credentials) { @Override public void signRequest(final java.net.HttpURLConnection request, final long contentLength) throws InvalidKeyException, StorageException { - this.signRequest(request, contentLength, null); + this.signBlobAndQueueRequest(request, contentLength, null); } /** @@ -300,7 +300,7 @@ public void signRequest(final java.net.HttpURLConnection request, final long con @Override public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength) throws InvalidKeyException, StorageException { - this.signRequestLite(request, contentLength, null); + this.signTableRequestLite(request, contentLength, null); } /** @@ -327,6 +327,178 @@ public void signRequestLite(final java.net.HttpURLConnection request, final long BaseRequest.signRequestForTableSharedKeyLite(request, this.credentials, contentLength, opContext); } + /** + * 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. + */ + @Override + public void signBlobAndQueueRequest(final java.net.HttpURLConnection request, final long contentLength) + throws InvalidKeyException, StorageException { + this.signBlobAndQueueRequest(request, contentLength, null); + } + + /** + * Signs a request using the specified operation context 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + @Override + public void signBlobAndQueueRequest(final java.net.HttpURLConnection request, final long contentLength, + OperationContext opContext) throws InvalidKeyException, StorageException { + opContext = opContext == null ? new OperationContext() : opContext; + BaseRequest.signRequestForBlobAndQueue(request, this.credentials, contentLength, opContext); + } + + /** + * Signs a request using the Shared Key Lite 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 an unspecified storage exception occurs. + */ + @Override + public void signBlobAndQueueRequestLite(final java.net.HttpURLConnection request, final long contentLength) + throws InvalidKeyException, StorageException { + this.signBlobAndQueueRequestLite(request, contentLength, null); + } + + /** + * Signs a request using the specified operation context under the Shared Key Lite 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + @Override + public void signBlobAndQueueRequestLite(final java.net.HttpURLConnection request, final long contentLength, + OperationContext opContext) throws StorageException, InvalidKeyException { + opContext = opContext == null ? new OperationContext() : opContext; + BaseRequest.signRequestForBlobAndQueueSharedKeyLite(request, this.credentials, contentLength, opContext); + } + + /** + * 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. + */ + @Override + public void signTableRequest(final java.net.HttpURLConnection request, final long contentLength) + throws InvalidKeyException, StorageException { + this.signTableRequest(request, contentLength, null); + } + + /** + * Signs a request using the specified operation context 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + @Override + public void signTableRequest(final java.net.HttpURLConnection request, final long contentLength, + OperationContext opContext) throws InvalidKeyException, StorageException { + opContext = opContext == null ? new OperationContext() : opContext; + BaseRequest.signRequestForTableSharedKey(request, this.credentials, contentLength, opContext); + } + + /** + * Signs a request using the Shared Key Lite 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 an unspecified storage exception occurs. + */ + @Override + public void signTableRequestLite(final java.net.HttpURLConnection request, final long contentLength) + throws InvalidKeyException, StorageException { + this.signTableRequestLite(request, contentLength, null); + } + + /** + * Signs a request using the specified operation context under the Shared Key Lite 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. + * @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. + * + * @throws InvalidKeyException + * If the given key is invalid. + * @throws StorageException + * If a storage service error occurred. + */ + @Override + public void signTableRequestLite(final java.net.HttpURLConnection request, final long contentLength, + OperationContext opContext) throws StorageException, InvalidKeyException { + opContext = opContext == null ? new OperationContext() : opContext; + BaseRequest.signRequestForTableSharedKeyLite(request, this.credentials, contentLength, opContext); + } + /** * Returns a String that represents this instance, optionally including sensitive data. * diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java index baf4e16dd16d..f7890b6234f9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java @@ -178,7 +178,7 @@ public String getAccountName() { * the length of the content written to the output stream. If unknown, specify -1. */ @Override - public void signRequest(final java.net.HttpURLConnection connection, final long contentLength) { + public void signBlobAndQueueRequest(final java.net.HttpURLConnection connection, final long contentLength) { // No op } @@ -196,7 +196,7 @@ public void signRequest(final java.net.HttpURLConnection connection, final long * object, that represents the current operation */ @Override - public void signRequest(final java.net.HttpURLConnection request, final long contentLength, + public void signBlobAndQueueRequest(final java.net.HttpURLConnection request, final long contentLength, final OperationContext opContext) { // No op } @@ -209,7 +209,7 @@ public void signRequest(final java.net.HttpURLConnection request, final long con * the request, as an HttpURLConnection object, to sign */ @Override - public void signRequestLite(final java.net.HttpURLConnection connection, final long contentLength) { + public void signBlobAndQueueRequestLite(final java.net.HttpURLConnection connection, final long contentLength) { // No op } @@ -225,7 +225,69 @@ public void signRequestLite(final java.net.HttpURLConnection connection, final l * object, that represents the current operation */ @Override - public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength, + public void signBlobAndQueueRequestLite(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + + /** + * Signs a request using the specified credentials under the Shared Key authentication scheme. This is not a valid + * operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. + * + * @param connection + * the request, as an HttpURLConnection object, to sign + * @param contentLength + * the length of the content written to the output stream. If unknown, specify -1. + */ + @Override + public void signTableRequest(final java.net.HttpURLConnection connection, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified credentials and operation context under the Shared Key authentication scheme. + * This is not a valid operation for objects of type StorageCredentialsAnonymous so the method performs + * a no-op. + * + * @param request + * the request, as an HttpURLConnection object, to sign + * @param contentLength + * the length of the content written to the output stream. If unknown, specify -1. + * @param opContext + * an operation context, as a {@link com.microsoft.windowsazure.services.core.storage.OperationContext} + * object, that represents the current operation + */ + @Override + public void signTableRequest(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + + /** + * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a + * valid operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. + * + * @param connection + * the request, as an HttpURLConnection object, to sign + */ + @Override + public void signTableRequestLite(final java.net.HttpURLConnection connection, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a + * valid operation for objects of type StorageCredentialsSharedAccessSignature so the method performs a + * no-op. + * + * @param request + * the request, as an HttpURLConnection object, to sign + * @param opContext + * an operation context, as a {@link com.microsoft.windowsazure.services.core.storage.OperationContext} + * object, that represents the current operation + */ + @Override + public void signTableRequestLite(final java.net.HttpURLConnection request, final long contentLength, final OperationContext opContext) { // No op } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java index 4702824027ff..1bee911c69cb 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java @@ -96,8 +96,8 @@ public String computeHmac256(final String value) { /** * Computes a signature for the specified string using the HMAC-SHA256 algorithm with the specified operation - * context. This is not a valid operation for objects of type StorageCredentialsSharedAccessSignature so - * the method merely returns null. + * context. This is not a valid operation for objects of type StorageCredentialsSharedAccessSignature + * so the method merely returns null. * * @param value * The UTF-8-encoded string to sign. @@ -130,8 +130,8 @@ public String computeHmac512(final String value) { /** * Computes a signature for the specified string using the HMAC-SHA512 algorithm with the specified operation - * context. This is not a valid operation for objects of type StorageCredentialsSharedAccessSignature so - * the method merely returns null. + * context. This is not a valid operation for objects of type StorageCredentialsSharedAccessSignature + * so the method merely returns null. * * @param value * The UTF-8-encoded string to sign. @@ -191,7 +191,7 @@ public String getToken() { * The length of the content written to the output stream. If unknown, specify -1. */ @Override - public void signRequest(final java.net.HttpURLConnection request, final long contentLength) { + public void signBlobAndQueueRequest(final java.net.HttpURLConnection request, final long contentLength) { // No op } @@ -210,7 +210,7 @@ public void signRequest(final java.net.HttpURLConnection request, final long con * the operation. */ @Override - public void signRequest(final java.net.HttpURLConnection request, final long contentLength, + public void signBlobAndQueueRequest(final java.net.HttpURLConnection request, final long contentLength, final OperationContext opContext) { // No op } @@ -225,7 +225,7 @@ public void signRequest(final java.net.HttpURLConnection request, final long con * The length of the content written to the output stream. If unknown, specify -1. */ @Override - public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength) { + public void signBlobAndQueueRequestLite(final java.net.HttpURLConnection request, final long contentLength) { // No op } @@ -244,7 +244,75 @@ public void signRequestLite(final java.net.HttpURLConnection request, final long * the operation. */ @Override - public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength, + public void signBlobAndQueueRequestLite(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + + /** + * Signs a request under the Shared Key authentication scheme. This is not a valid operation for objects of type + * StorageCredentialsSharedAccessSignature so the method performs a no-op. + * + * @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. + */ + @Override + public void signTableRequest(final java.net.HttpURLConnection request, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified operation context under the Shared Key authentication scheme. This is not a + * valid operation for objects of type StorageCredentialsSharedAccessSignature so the method performs a + * no-op. + * + * @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. + * @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. + */ + @Override + public void signTableRequest(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + + /** + * Signs a request under the Shared Key Lite authentication scheme. This is not a valid operation for objects of + * type StorageCredentialsSharedAccessSignature so the method performs a no-op. + * + * @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. + */ + @Override + public void signTableRequestLite(final java.net.HttpURLConnection request, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified operation context under the Shared Key Lite authentication scheme. This is + * not a valid operation for objects of type StorageCredentialsSharedAccessSignature so the method + * performs a no-op. + * + * @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. + * @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. + */ + @Override + public void signTableRequestLite(final java.net.HttpURLConnection request, final long contentLength, final OperationContext opContext) { // No op } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/BaseRequest.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/BaseRequest.java index e5273db93f60..19538da0c985 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/BaseRequest.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/BaseRequest.java @@ -498,7 +498,40 @@ public static void signRequestForBlobAndQueueSharedKeyLite(final HttpURLConnecti /** * - * Signs the request appropriately to make it an authenticated request for Blob and Queue. + * Signs the request appropriately to make it an authenticated request for Table. + * + * @param request + * a HttpURLConnection for the operation. + * @param credentials + * the credentials to use for signing. + * @param contentLength + * the length of the content written to the output stream, -1 if unknown. + * @param opContext + * an object used to track the execution of the operation + * @throws InvalidKeyException + * if the credentials key is invalid. + * @throws StorageException + */ + public static void signRequestForTableSharedKey(final HttpURLConnection request, final Credentials credentials, + final Long contentLength, final OperationContext opContext) throws InvalidKeyException, StorageException { + request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime()); + + final Canonicalizer canonicalizer = CanonicalizerFactory.getTableFullCanonicalizer(request); + + final String stringToSign = canonicalizer.canonicalize(request, credentials.getAccountName(), contentLength, + opContext); + + final String computedBase64Signature = StorageKey.computeMacSha256(credentials.getKey(), stringToSign); + + // TODO Vnext add logging + // System.out.println(String.format("Signing %s\r\n%s\r\n", stringToSign, computedBase64Signature)); + request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION, + String.format("%s %s:%s", "SharedKey", credentials.getAccountName(), computedBase64Signature)); + } + + /** + * + * Signs the request appropriately to make it an authenticated request for Table. * * @param request * a HttpURLConnection for the operation. diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/Canonicalizer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/Canonicalizer.java index b78e9c258cd3..77c5f71d266d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/Canonicalizer.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/Canonicalizer.java @@ -34,11 +34,26 @@ import com.microsoft.windowsazure.services.core.storage.utils.Utility; /** - * RESERVED FOR INTERNAL USE. This is a Version 2 Canoncicalization strategy conforming to the PDC 2009-09-19 + * RESERVED FOR INTERNAL USE. This is a Version 2 Canonicalization strategy conforming to the PDC 2009-09-19 * specification */ abstract class Canonicalizer { + /** + * The expected length for the canonicalized string when SharedKeyFull is used to sign requests. + */ + private static final int ExpectedBlobQueueCanonicalizedStringLength = 300; + + /** + * The expected length for the canonicalized string when SharedKeyLite is used to sign requests. + */ + private static final int ExpectedBlobQueueLiteCanonicalizedStringLength = 250; + + /** + * The expected length for the canonicalized string when SharedKeyFull is used to sign table requests. + */ + private static final int ExpectedTableCanonicalizedStringLength = 200; + /** * Add x-ms- prefixed headers in a fixed order. * @@ -130,7 +145,8 @@ protected static String canonicalizeHttpRequest(final java.net.URL address, fina // The first element should be the Method of the request. // I.e. GET, POST, PUT, or HEAD. - final StringBuilder canonicalizedString = new StringBuilder(conn.getRequestMethod()); + final StringBuilder canonicalizedString = new StringBuilder(ExpectedBlobQueueCanonicalizedStringLength); + canonicalizedString.append(conn.getRequestMethod()); // The next elements are // If any element is missing it may be empty. @@ -199,7 +215,9 @@ protected static String canonicalizeHttpRequestLite(final java.net.URL address, final HttpURLConnection conn, final OperationContext opContext) throws StorageException { // The first element should be the Method of the request. // I.e. GET, POST, PUT, or HEAD. - final StringBuilder canonicalizedString = new StringBuilder(conn.getRequestMethod()); + // + final StringBuilder canonicalizedString = new StringBuilder(ExpectedBlobQueueLiteCanonicalizedStringLength); + canonicalizedString.append(conn.getRequestMethod()); // The second element should be the MD5 value. // This is optional and may be empty. @@ -220,7 +238,59 @@ protected static String canonicalizeHttpRequestLite(final java.net.URL address, addCanonicalizedHeaders(conn, canonicalizedString); - appendCanonicalizedElement(canonicalizedString, getCanonicalizedResource(address, accountName)); + appendCanonicalizedElement(canonicalizedString, getCanonicalizedResourceLite(address, accountName)); + + return canonicalizedString.toString(); + } + + /** + * Constructs a canonicalized string that will be used to construct the signature string + * for signing a Table service request under the Shared Key authentication scheme. + * + * @param address + * the request URI + * @param accountName + * the account name associated with the request + * @param method + * the verb to be used for the HTTP request. + * @param contentType + * the content type of the HTTP request. + * @param contentLength + * the length of the content written to the outputstream in bytes, -1 if unknown + * @param date + * the date/time specification for the HTTP request + * @param conn + * the HttpURLConnection for the operation. + * @param opContext + * the OperationContext for the request. + * @return A canonicalized string. + * @throws StorageException + */ + protected static String canonicalizeTableHttpRequest(final java.net.URL address, final String accountName, + final String method, final String contentType, final long contentLength, final String date, + final HttpURLConnection conn, final OperationContext opContext) throws StorageException { + // The first element should be the Method of the request. + // I.e. GET, POST, PUT, or HEAD. + final StringBuilder canonicalizedString = new StringBuilder(ExpectedTableCanonicalizedStringLength); + canonicalizedString.append(conn.getRequestMethod()); + + // The second element should be the MD5 value. + // This is optional and may be empty. + final String httpContentMD5Value = Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.CONTENT_MD5); + appendCanonicalizedElement(canonicalizedString, httpContentMD5Value); + + // The third element should be the content type. + appendCanonicalizedElement(canonicalizedString, contentType); + + // The fourth element should be the request date. + // See if there's an storage date header. + // If there's one, then don't use the date header. + + final String dateString = Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.DATE); + // If x-ms-date header exists, Date should be that value. + appendCanonicalizedElement(canonicalizedString, dateString.equals(Constants.EMPTY_STRING) ? date : dateString); + + appendCanonicalizedElement(canonicalizedString, getCanonicalizedResourceLite(address, accountName)); return canonicalizedString.toString(); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/CanonicalizerFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/CanonicalizerFactory.java index 54ae1d41fe3e..1ba789f44c40 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/CanonicalizerFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/CanonicalizerFactory.java @@ -45,6 +45,11 @@ final class CanonicalizerFactory { /** * The Canonicalizer instance for Table */ + private static final TableFullCanonicalizer TABLE_FULL_INSTANCE = new TableFullCanonicalizer(); + + /** + * The Canonicalizer instance for Table Lite + */ private static final TableLiteCanonicalizer TABLE_LITE_INSTANCE = new TableLiteCanonicalizer(); /** @@ -81,7 +86,18 @@ protected static Canonicalizer getBlobQueueLiteCanonicalizer(final HttpURLConnec } /** - * Gets the Blob queue lite Canonicalizer + * Gets the table full Canonicalizer. + * + * @param conn + * the HttpURLConnection for the current operation + * @return the appropriate Canonicalizer for the operation. + */ + protected static Canonicalizer getTableFullCanonicalizer(final HttpURLConnection conn) { + return TABLE_FULL_INSTANCE; + } + + /** + * Gets the table lite Canonicalizer * * @param conn * the HttpURLConnection for the current operation @@ -93,7 +109,7 @@ protected static Canonicalizer getTableLiteCanonicalizer(final HttpURLConnection } else { throw new UnsupportedOperationException( - "Versions before 2009-09-19 do not support Shared Key Lite for Blob And Queue."); + "Versions before 2009-09-19 do not support Shared Key Lite for Table."); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java index a18d41dc19dd..47ae9204e384 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/StorageOperation.java @@ -15,10 +15,13 @@ package com.microsoft.windowsazure.services.core.storage.utils.implementation; import java.net.HttpURLConnection; +import java.security.InvalidKeyException; +import com.microsoft.windowsazure.services.core.storage.AuthenticationScheme; import com.microsoft.windowsazure.services.core.storage.OperationContext; import com.microsoft.windowsazure.services.core.storage.RequestOptions; import com.microsoft.windowsazure.services.core.storage.RequestResult; +import com.microsoft.windowsazure.services.core.storage.ServiceClient; import com.microsoft.windowsazure.services.core.storage.StorageException; /** @@ -155,6 +158,26 @@ protected final StorageException materializeException(final HttpURLConnection re return StorageException.translateException(request, null, opContext); } + public final void signRequest(ServiceClient client, HttpURLConnection request, long contentLength, + OperationContext context) throws InvalidKeyException, StorageException { + if (client.getAuthenticationScheme() == AuthenticationScheme.SHAREDKEYFULL) { + client.getCredentials().signBlobAndQueueRequest(request, contentLength, context); + } + else { + client.getCredentials().signBlobAndQueueRequestLite(request, contentLength, context); + } + } + + public final void signTableRequest(ServiceClient client, HttpURLConnection request, long contentLength, + OperationContext context) throws InvalidKeyException, StorageException { + if (client.getAuthenticationScheme() == AuthenticationScheme.SHAREDKEYFULL) { + client.getCredentials().signTableRequest(request, contentLength, context); + } + else { + client.getCredentials().signTableRequestLite(request, contentLength, context); + } + } + /** * @param exceptionReference * the exception to set diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableFullCanonicalizer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableFullCanonicalizer.java new file mode 100644 index 000000000000..c3088315fb73 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableFullCanonicalizer.java @@ -0,0 +1,57 @@ +/** + * 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.windowsazure.services.core.storage.utils.implementation; + +import java.net.HttpURLConnection; +import java.security.InvalidParameterException; + +import com.microsoft.windowsazure.services.core.storage.Constants; +import com.microsoft.windowsazure.services.core.storage.OperationContext; +import com.microsoft.windowsazure.services.core.storage.StorageException; +import com.microsoft.windowsazure.services.core.storage.utils.Utility; + +/** + * RESERVED FOR INTERNAL USE. Provides an implementation of the Canonicalizer class for requests against Table + * Service under the Shared Key authentication scheme. + */ +final class TableFullCanonicalizer extends Canonicalizer { + + /** + * Constructs a canonicalized string for signing a request. + * + * @param conn + * the HttpURLConnection to canonicalize + * @param accountName + * the account name associated with the request + * @param contentLength + * the length of the content written to the outputstream in bytes, -1 if unknown + * @param opContext + * the OperationContext for the given request + * @return a canonicalized string. + * @throws StorageException + */ + @Override + protected String canonicalize(final HttpURLConnection conn, final String accountName, final Long contentLength, + final OperationContext opContext) throws StorageException { + + if (contentLength < -1) { + throw new InvalidParameterException("ContentLength must be set to -1 or non-negative Long value"); + } + + return canonicalizeTableHttpRequest(conn.getURL(), accountName, conn.getRequestMethod(), + Utility.getStandardHeaderValue(conn, Constants.HeaderConstants.CONTENT_TYPE), contentLength, null, + conn, opContext); + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableLiteCanonicalizer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableLiteCanonicalizer.java index 913ed76d908a..44211bf76946 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableLiteCanonicalizer.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/utils/implementation/TableLiteCanonicalizer.java @@ -30,6 +30,12 @@ * under the Shared Key Lite authentication scheme. */ class TableLiteCanonicalizer extends Canonicalizer { + + /** + * The expected length for the canonicalized string when SharedKeyLite is used to sign table requests. + */ + private static final int ExpectedTableLiteCanonicalizedStringLength = 150; + /** * Constructs a canonicalized string for signing a request. * @@ -56,8 +62,8 @@ protected String canonicalize(final HttpURLConnection conn, final String account throw new IllegalArgumentException( "Canonicalization did not find a non empty x-ms-date header in the request. Please use a request with a valid x-ms-date header in RFC 123 format."); } - - final StringBuilder canonicalizedString = new StringBuilder(dateString); + final StringBuilder canonicalizedString = new StringBuilder(ExpectedTableLiteCanonicalizedStringLength); + canonicalizedString.append(dateString); appendCanonicalizedElement(canonicalizedString, getCanonicalizedResourceLite(conn.getURL(), accountName)); return canonicalizedString.toString(); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java index 15b646e33651..4190dd58ac73 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java @@ -217,7 +217,8 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final final byte[] messageBytes = QueueRequest.generateMessageRequestBody(stringToSend); - client.getCredentials().signRequest(request, messageBytes.length); + this.signRequest(client, request, messageBytes.length, null); + final OutputStream outStreamRef = request.getOutputStream(); outStreamRef.write(messageBytes); @@ -286,7 +287,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final this.getRequestOptions().getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -352,7 +353,8 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final this.setConnection(request); QueueRequest.addMetadata(request, queue.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -426,7 +428,8 @@ public Boolean execute(final CloudQueueClient client, final CloudQueue queue, this.setConnection(request); QueueRequest.addMetadata(request, queue.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -512,7 +515,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final .getRequestOptions().getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -584,7 +587,7 @@ public Boolean execute(final CloudQueueClient client, final CloudQueue queue, .getRequestOptions().getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -672,7 +675,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -739,7 +742,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -813,7 +816,7 @@ public Boolean execute(final CloudQueueClient client, final CloudQueue queue, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1029,7 +1032,7 @@ public ArrayList execute(final CloudQueueClient client, final this.getRequestOptions().getTimeoutIntervalInMs(), numberOfMessages, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1164,7 +1167,7 @@ public ArrayList execute(final CloudQueueClient client, final numberOfMessages, visibilityTimeoutInSeconds, opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1296,13 +1299,15 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final if (messageUpdateFields.contains(MessageUpdateFields.CONTENT)) { final byte[] messageBytes = QueueRequest.generateMessageRequestBody(stringToSend); - client.getCredentials().signRequest(request, messageBytes.length); + this.signRequest(client, request, messageBytes.length, null); + final OutputStream outStreamRef = request.getOutputStream(); outStreamRef.write(messageBytes); } else { request.setFixedLengthStreamingMode(0); - client.getCredentials().signRequest(request, 0L); + + this.signRequest(client, request, 0L, null); } ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1377,7 +1382,7 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final this.setConnection(request); QueueRequest.addMetadata(request, queue.metadata, opContext); - client.getCredentials().signRequest(request, 0L); + this.signRequest(client, request, 0L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -1455,7 +1460,9 @@ public Void execute(final CloudQueueClient client, final CloudQueue queue, final QueueRequest.writeSharedAccessIdentifiersToStream(permissions.getSharedAccessPolicies(), outBuffer); final byte[] aclBytes = outBuffer.toString().getBytes("UTF8"); - client.getCredentials().signRequest(request, aclBytes.length); + + this.signRequest(client, request, aclBytes.length, null); + final OutputStream outStreamRef = request.getOutputStream(); outStreamRef.write(aclBytes); @@ -1528,7 +1535,7 @@ public QueuePermissions execute(final CloudQueueClient client, final CloudQueue .getRequestOptions().getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequest(request, -1L); + this.signRequest(client, request, -1L, null); ExecutionEngine.processRequest(request, opContext, this.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java index 7f1f12938aa0..b4b1f97c2bed 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueueClient.java @@ -226,7 +226,7 @@ ResultSegment listQueuesCore(final String prefix, final QueueListing options.getTimeoutIntervalInMs(), listingContext, detailsIncluded, opContext); taskReference.setConnection(listQueueRequest); - this.getCredentials().signRequest(listQueueRequest, -1L); + taskReference.signRequest(this, listQueueRequest, -1L, null); ExecutionEngine.processRequest(listQueueRequest, opContext, taskReference.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java index 47dc6bce8f9c..298f2a8f6064 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java @@ -490,7 +490,9 @@ public Void execute(final CloudTableClient client, final CloudTable table, final TableRequest.writeSharedAccessIdentifiersToStream(permissions.getSharedAccessPolicies(), outBuffer); final byte[] aclBytes = outBuffer.toString().getBytes("UTF8"); - client.getCredentials().signRequestLite(request, aclBytes.length, opContext); + + this.signTableRequest(client, request, aclBytes.length, opContext); + final OutputStream outStreamRef = request.getOutputStream(); outStreamRef.write(aclBytes); @@ -564,7 +566,7 @@ public TablePermissions execute(final CloudTableClient client, final CloudTable .getTimeoutIntervalInMs(), opContext); this.setConnection(request); - client.getCredentials().signRequestLite(request, -1L, opContext); + this.signTableRequest(client, request, -1L, opContext); ExecutionEngine.processRequest(request, opContext, this.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java index 8a240fe9bb9d..ca181e471aa6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTableClient.java @@ -799,7 +799,8 @@ protected ResultSegment executeQuerySegmentedCore( queryToExecute.generateQueryBuilder(), continuationToken, options, opContext); taskReference.setConnection(queryRequest); - this.getCredentials().signRequestLite(queryRequest, -1L, opContext); + taskReference.signTableRequest(this, queryRequest, -1L, opContext); + ExecutionEngine.processRequest(queryRequest, opContext, taskReference.getResult()); if (taskReference.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java index e92207cd4ae4..48a01577e808 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/QueryTableOperation.java @@ -188,7 +188,7 @@ tableName, generateRequestIdentity(isTableEntry, operation.getPartitionKey(), fa options, opContext); this.setConnection(request); - client.getCredentials().signRequestLite(request, -1L, opContext); + this.signTableRequest(client, request, -1L, opContext); ExecutionEngine.processRequest(request, opContext, this.getResult()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java index 90b773477e55..cef17a1c030b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableBatchOperation.java @@ -395,7 +395,7 @@ public ArrayList execute(final CloudTableClient client, final Table options.getTimeoutIntervalInMs(), batchID, null, options, opContext); this.setConnection(request); - client.getCredentials().signRequestLite(request, -1L, opContext); + this.signTableRequest(client, request, -1L, opContext); MimeHelper.writeBatchToStream(request.getOutputStream(), tableName, batch, batchID, changeSet, opContext); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java index 72d385e1996a..81b030426817 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TableOperation.java @@ -261,7 +261,7 @@ tableName, generateRequestIdentity(isTableEntry, tableIdentity, false), operatio .getEtag(), options.getTimeoutIntervalInMs(), null, options, opContext); this.setConnection(request); - client.getCredentials().signRequestLite(request, -1L, opContext); + this.signTableRequest(client, request, -1L, opContext); ExecutionEngine.processRequest(request, opContext, this.getResult()); @@ -330,7 +330,7 @@ tableName, generateRequestIdentity(isTableEntry, tableIdentity, false), operation.opType.getUpdateType(), options.getTimeoutIntervalInMs(), null, options, opContext); this.setConnection(request); - client.getCredentials().signRequestLite(request, -1L, opContext); + this.signTableRequest(client, request, -1L, opContext); AtomPubParser.writeSingleEntityToStream(operation.getEntity(), isTableEntry, request.getOutputStream(), opContext); @@ -412,7 +412,7 @@ tableName, generateRequestIdentity(false, null, false), operation.getEntity().ge options.getTimeoutIntervalInMs(), null, options, opContext); this.setConnection(request); - client.getCredentials().signRequestLite(request, -1L, opContext); + this.signTableRequest(client, request, -1L, opContext); AtomPubParser.writeSingleEntityToStream(operation.getEntity(), false, request.getOutputStream(), opContext); @@ -479,7 +479,7 @@ tableName, generateRequestIdentity(false, null, false), operation.getEntity().ge options.getTimeoutIntervalInMs(), null, options, opContext); this.setConnection(request); - client.getCredentials().signRequestLite(request, -1L, opContext); + this.signTableRequest(client, request, -1L, opContext); AtomPubParser.writeSingleEntityToStream(operation.getEntity(), false, request.getOutputStream(), opContext); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java index 3da51d425a0e..1b69119c1e48 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java @@ -21,6 +21,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; +import com.microsoft.windowsazure.services.core.storage.AuthenticationScheme; import com.microsoft.windowsazure.services.core.storage.CloudStorageAccount; import com.microsoft.windowsazure.services.core.storage.StorageException; @@ -52,6 +53,7 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK } bClient = httpAcc.createCloudBlobClient(); + bClient.setAuthenticationScheme(AuthenticationScheme.SHAREDKEYFULL); testSuiteContainerName = generateRandomContainerName(); CloudBlobContainer container = bClient.getContainerReference(testSuiteContainerName); container.create(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainerTests.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainerTests.java index e007c4151140..36a73da82be8 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainerTests.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainerTests.java @@ -36,6 +36,7 @@ import org.junit.Test; import com.microsoft.windowsazure.services.core.storage.AccessCondition; +import com.microsoft.windowsazure.services.core.storage.AuthenticationScheme; import com.microsoft.windowsazure.services.core.storage.OperationContext; import com.microsoft.windowsazure.services.core.storage.ResultSegment; import com.microsoft.windowsazure.services.core.storage.RetryNoRetry; @@ -808,4 +809,46 @@ public void testCurrentOperationByteCount() throws URISyntaxException, StorageEx blobRef.delete(); } + + @Test + public void testContainerSharedKeyLite() throws StorageException, URISyntaxException { + bClient.setAuthenticationScheme(AuthenticationScheme.SHAREDKEYLITE); + String name = generateRandomContainerName(); + CloudBlobContainer newContainer = bClient.getContainerReference(name); + newContainer.create(); + + BlobContainerPermissions expectedPermissions; + BlobContainerPermissions testPermissions; + + try { + // Test new permissions. + expectedPermissions = new BlobContainerPermissions(); + testPermissions = newContainer.downloadPermissions(); + assertTablePermissionsEqual(expectedPermissions, testPermissions); + + // Test setting empty permissions. + newContainer.uploadPermissions(expectedPermissions); + testPermissions = newContainer.downloadPermissions(); + assertTablePermissionsEqual(expectedPermissions, testPermissions); + + // Add a policy, check setting and getting. + SharedAccessBlobPolicy policy1 = new SharedAccessBlobPolicy(); + Calendar now = GregorianCalendar.getInstance(); + policy1.setSharedAccessStartTime(now.getTime()); + now.add(Calendar.MINUTE, 10); + policy1.setSharedAccessExpiryTime(now.getTime()); + + policy1.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.DELETE, + SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE)); + expectedPermissions.getSharedAccessPolicies().put(UUID.randomUUID().toString(), policy1); + + newContainer.uploadPermissions(expectedPermissions); + testPermissions = newContainer.downloadPermissions(); + assertTablePermissionsEqual(expectedPermissions, testPermissions); + } + finally { + // cleanup + newContainer.deleteIfExists(); + } + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/CloudQueueTests.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/CloudQueueTests.java index 53c95807d465..2f91a392326c 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/CloudQueueTests.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/CloudQueueTests.java @@ -34,6 +34,7 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.core.storage.AuthenticationScheme; import com.microsoft.windowsazure.services.core.storage.OperationContext; import com.microsoft.windowsazure.services.core.storage.StorageCredentialsSharedAccessSignature; import com.microsoft.windowsazure.services.core.storage.StorageErrorCodeStrings; @@ -1359,4 +1360,35 @@ public void testSASClientParse() throws StorageException, URISyntaxException, In CloudQueue queue2 = new CloudQueue(queueUri, queueClient2); queue2.getName(); } + + @Test + public void testQueueSharedKeyLite() throws URISyntaxException, StorageException { + qClient.setAuthenticationScheme(AuthenticationScheme.SHAREDKEYLITE); + String queueName = UUID.randomUUID().toString().toLowerCase(); + CloudQueue queue = qClient.getQueueReference(queueName); + Assert.assertEquals(queueName, queue.getName()); + + OperationContext createQueueContext = new OperationContext(); + queue.create(null, createQueueContext); + Assert.assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); + + try { + HashMap metadata1 = new HashMap(); + metadata1.put("ExistingMetadata1", "ExistingMetadataValue1"); + queue.setMetadata(metadata1); + queue.create(); + Assert.fail(); + } + catch (StorageException e) { + Assert.assertTrue(e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT); + + } + + queue.downloadAttributes(); + OperationContext createQueueContext2 = new OperationContext(); + queue.create(null, createQueueContext2); + Assert.assertEquals(createQueueContext2.getLastResult().getStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); + + queue.delete(); + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java index 831bbf6ca30d..4ccfa9f78136 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java @@ -22,6 +22,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; +import com.microsoft.windowsazure.services.core.storage.AuthenticationScheme; import com.microsoft.windowsazure.services.core.storage.CloudStorageAccount; import com.microsoft.windowsazure.services.core.storage.StorageException; @@ -53,6 +54,7 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK } qClient = httpAcc.createCloudQueueClient(); + qClient.setAuthenticationScheme(AuthenticationScheme.SHAREDKEYFULL); testSuiteQueueName = generateRandomQueueName(); queue = qClient.getQueueReference(testSuiteQueueName); queue.create(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableClientTests.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableClientTests.java index 3f9bf6fa9a75..dda98602e798 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableClientTests.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableClientTests.java @@ -33,6 +33,7 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.core.storage.AuthenticationScheme; import com.microsoft.windowsazure.services.core.storage.ResultSegment; import com.microsoft.windowsazure.services.core.storage.StorageCredentialsSharedAccessSignature; import com.microsoft.windowsazure.services.core.storage.StorageException; @@ -641,6 +642,30 @@ public void testTableSASFromPermission() throws StorageException, URISyntaxExcep } } + @Test + public void tableCreateAndAttemptCreateOnceExistsSharedKeyLite() throws StorageException, URISyntaxException { + tClient.setAuthenticationScheme(AuthenticationScheme.SHAREDKEYLITE); + String tableName = generateRandomTableName(); + CloudTable table = tClient.getTableReference(tableName); + try { + table.create(); + Assert.assertTrue(table.exists()); + + // Should fail as it already exists + try { + table.create(); + fail(); + } + catch (StorageException ex) { + Assert.assertEquals(ex.getErrorCode(), "TableAlreadyExists"); + } + } + finally { + // cleanup + table.deleteIfExists(); + } + } + private CloudTableClient getTableForSas(CloudTable table, SharedAccessTablePolicy policy, String accessIdentifier, String startPk, String startRk, String endPk, String endRk) throws InvalidKeyException, StorageException { String sasString = table diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java index bb4d9d1a156d..4d50f8dce703 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java @@ -26,6 +26,7 @@ import org.junit.BeforeClass; import com.microsoft.windowsazure.services.blob.client.CloudBlobClient; +import com.microsoft.windowsazure.services.core.storage.AuthenticationScheme; import com.microsoft.windowsazure.services.core.storage.CloudStorageAccount; import com.microsoft.windowsazure.services.core.storage.StorageException; import com.microsoft.windowsazure.services.queue.client.CloudQueueClient; @@ -595,6 +596,7 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK tClient = httpAcc.createCloudTableClient(); qClient = httpAcc.createCloudQueueClient(); testSuiteTableName = generateRandomTableName(); + tClient.setAuthenticationScheme(AuthenticationScheme.SHAREDKEYFULL); CloudTable table = tClient.getTableReference(testSuiteTableName); table.create(); } From b2eccda962b309e9919448a2d1b557eee06a2a9c Mon Sep 17 00:00:00 2001 From: veudayab Date: Wed, 5 Jun 2013 15:19:42 -0700 Subject: [PATCH 05/17] Support all flavors of sharedkeysigning in Java --- .../storage/StorageCredentialsAnonymous.java | 78 +++++++++++++++++++ ...orageCredentialsSharedAccessSignature.java | 78 +++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java index f7890b6234f9..e676a277b068 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java @@ -168,6 +168,84 @@ public String getAccountName() { return null; } + /** + * Signs a request using the specified credentials under the Shared Key authentication scheme. This is not a valid + * operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. + * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * + * @param connection + * the request, as an HttpURLConnection object, to sign + * @param contentLength + * the length of the content written to the output stream. If unknown, specify -1. + */ + @Override + @Deprecated + public void signRequest(final java.net.HttpURLConnection connection, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified credentials and operation context under the Shared Key authentication scheme. + * This is not a valid operation for objects of type StorageCredentialsAnonymous so the method performs + * a no-op. + * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * + * @param request + * the request, as an HttpURLConnection object, to sign + * @param contentLength + * the length of the content written to the output stream. If unknown, specify -1. + * @param opContext + * an operation context, as a {@link com.microsoft.windowsazure.services.core.storage.OperationContext} + * object, that represents the current operation + */ + @Override + @Deprecated + public void signRequest(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + + /** + * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a + * valid operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. + * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. + * + * @param connection + * the request, as an HttpURLConnection object, to sign + */ + @Override + @Deprecated + public void signRequestLite(final java.net.HttpURLConnection connection, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a + * valid operation for objects of type StorageCredentialsSharedAccessSignature so the method performs a + * no-op. + * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. + * + * @param request + * the request, as an HttpURLConnection object, to sign + * @param opContext + * an operation context, as a {@link com.microsoft.windowsazure.services.core.storage.OperationContext} + * object, that represents the current operation + */ + @Override + @Deprecated + public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + /** * Signs a request using the specified credentials under the Shared Key authentication scheme. This is not a valid * operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java index 1bee911c69cb..189fb00f9512 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java @@ -181,6 +181,84 @@ public String getToken() { return this.token; } + /** + * Signs a request using the specified credentials under the Shared Key authentication scheme. This is not a valid + * operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. + * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * + * @param connection + * the request, as an HttpURLConnection object, to sign + * @param contentLength + * the length of the content written to the output stream. If unknown, specify -1. + */ + @Override + @Deprecated + public void signRequest(final java.net.HttpURLConnection connection, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified credentials and operation context under the Shared Key authentication scheme. + * This is not a valid operation for objects of type StorageCredentialsAnonymous so the method performs + * a no-op. + * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * + * @param request + * the request, as an HttpURLConnection object, to sign + * @param contentLength + * the length of the content written to the output stream. If unknown, specify -1. + * @param opContext + * an operation context, as a {@link com.microsoft.windowsazure.services.core.storage.OperationContext} + * object, that represents the current operation + */ + @Override + @Deprecated + public void signRequest(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + + /** + * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a + * valid operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. + * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. + * + * @param connection + * the request, as an HttpURLConnection object, to sign + */ + @Override + @Deprecated + public void signRequestLite(final java.net.HttpURLConnection connection, final long contentLength) { + // No op + } + + /** + * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a + * valid operation for objects of type StorageCredentialsSharedAccessSignature so the method performs a + * no-op. + * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. + * + * @param request + * the request, as an HttpURLConnection object, to sign + * @param opContext + * an operation context, as a {@link com.microsoft.windowsazure.services.core.storage.OperationContext} + * object, that represents the current operation + */ + @Override + @Deprecated + public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength, + final OperationContext opContext) { + // No op + } + /** * Signs a request under the Shared Key authentication scheme. This is not a valid operation for objects of type * StorageCredentialsSharedAccessSignature so the method performs a no-op. From e1440fa6a33609ac4f1cbe91fd59f7f79568e2fe Mon Sep 17 00:00:00 2001 From: veudayab Date: Wed, 12 Jun 2013 14:42:48 -0700 Subject: [PATCH 06/17] Mark signRequest* methods as deprecated in StorageCredentialsAccountAndKey.java --- .../storage/StorageCredentialsAccountAndKey.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java index b0b27ab63d98..791497a68fe3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java @@ -244,6 +244,8 @@ public void setCredentials(final Credentials credentials) { /** * Signs a request under the Shared Key authentication scheme. * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -255,6 +257,7 @@ public void setCredentials(final Credentials credentials) { * If a storage service error occurred. */ @Override + @Deprecated public void signRequest(final java.net.HttpURLConnection request, final long contentLength) throws InvalidKeyException, StorageException { this.signBlobAndQueueRequest(request, contentLength, null); @@ -263,6 +266,8 @@ public void signRequest(final java.net.HttpURLConnection request, final long con /** * Signs a request using the specified operation context under the Shared Key authentication scheme. * + * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and + * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -278,6 +283,7 @@ public void signRequest(final java.net.HttpURLConnection request, final long con * If a storage service error occurred. */ @Override + @Deprecated public void signRequest(final java.net.HttpURLConnection request, final long contentLength, OperationContext opContext) throws InvalidKeyException, StorageException { opContext = opContext == null ? new OperationContext() : opContext; @@ -287,6 +293,8 @@ public void signRequest(final java.net.HttpURLConnection request, final long con /** * Signs a request using the Shared Key Lite authentication scheme. * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -298,6 +306,7 @@ public void signRequest(final java.net.HttpURLConnection request, final long con * If an unspecified storage exception occurs. */ @Override + @Deprecated public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength) throws InvalidKeyException, StorageException { this.signTableRequestLite(request, contentLength, null); @@ -306,6 +315,8 @@ public void signRequestLite(final java.net.HttpURLConnection request, final long /** * Signs a request using the specified operation context under the Shared Key Lite authentication scheme. * + * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} + * depending on the desired shared key authentication scheme. * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -321,6 +332,7 @@ public void signRequestLite(final java.net.HttpURLConnection request, final long * If a storage service error occurred. */ @Override + @Deprecated public void signRequestLite(final java.net.HttpURLConnection request, final long contentLength, OperationContext opContext) throws StorageException, InvalidKeyException { opContext = opContext == null ? new OperationContext() : opContext; From 552f5f66d71afb556bc77e311495cccdf9b7a633 Mon Sep 17 00:00:00 2001 From: veudayab Date: Thu, 20 Jun 2013 15:08:12 -0700 Subject: [PATCH 07/17] Documentation changes to deprecated methods --- .../core/storage/StorageCredentials.java | 17 +++++++++-------- .../StorageCredentialsAccountAndKey.java | 18 ++++++++++-------- .../storage/StorageCredentialsAnonymous.java | 16 ++++++++-------- ...torageCredentialsSharedAccessSignature.java | 16 ++++++++-------- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java index 245ff1dd9142..a766631e84b5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentials.java @@ -214,8 +214,8 @@ public static StorageCredentials tryParseCredentials(final String connectionStri /** * Signs a request under the Shared Key authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * * @param request * An HttpURLConnection object that represents the request to sign. @@ -235,8 +235,8 @@ public abstract void signRequest(HttpURLConnection request, long contentLength) /** * Signs a request using the specified operation context under the Shared Key authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * * @param request * An HttpURLConnection object that represents the request to sign. @@ -259,8 +259,8 @@ public abstract void signRequest(HttpURLConnection request, long contentLength, /** * Signs a table request under the Shared Key Lite authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. * * @param request * An HttpURLConnection object that represents the request to sign. @@ -279,8 +279,9 @@ public abstract void signRequestLite(HttpURLConnection request, long contentLeng /** * Signs a table request using the specified operation context under the Shared Key Lite authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. + * * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java index 791497a68fe3..27fd4f9cac3f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAccountAndKey.java @@ -244,8 +244,8 @@ public void setCredentials(final Credentials credentials) { /** * Signs a request under the Shared Key authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -266,8 +266,8 @@ public void signRequest(final java.net.HttpURLConnection request, final long con /** * Signs a request using the specified operation context under the Shared Key authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -293,8 +293,9 @@ public void signRequest(final java.net.HttpURLConnection request, final long con /** * Signs a request using the Shared Key Lite authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. + * * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength @@ -315,8 +316,9 @@ public void signRequestLite(final java.net.HttpURLConnection request, final long /** * Signs a request using the specified operation context under the Shared Key Lite authentication scheme. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. + * * @param request * An HttpURLConnection object that represents the request to sign. * @param contentLength diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java index e676a277b068..7ceb94a78675 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsAnonymous.java @@ -172,8 +172,8 @@ public String getAccountName() { * Signs a request using the specified credentials under the Shared Key authentication scheme. This is not a valid * operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * * @param connection * the request, as an HttpURLConnection object, to sign @@ -191,8 +191,8 @@ public void signRequest(final java.net.HttpURLConnection connection, final long * This is not a valid operation for objects of type StorageCredentialsAnonymous so the method performs * a no-op. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * * @param request * the request, as an HttpURLConnection object, to sign @@ -213,8 +213,8 @@ public void signRequest(final java.net.HttpURLConnection request, final long con * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a * valid operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. * * @param connection * the request, as an HttpURLConnection object, to sign @@ -230,8 +230,8 @@ public void signRequestLite(final java.net.HttpURLConnection connection, final l * valid operation for objects of type StorageCredentialsSharedAccessSignature so the method performs a * no-op. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. * * @param request * the request, as an HttpURLConnection object, to sign diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java index 189fb00f9512..8e0d609f5fe6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/StorageCredentialsSharedAccessSignature.java @@ -185,8 +185,8 @@ public String getToken() { * Signs a request using the specified credentials under the Shared Key authentication scheme. This is not a valid * operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * * @param connection * the request, as an HttpURLConnection object, to sign @@ -204,8 +204,8 @@ public void signRequest(final java.net.HttpURLConnection connection, final long * This is not a valid operation for objects of type StorageCredentialsAnonymous so the method performs * a no-op. * - * @deprecated This method has been deprecated. Please use {@link signBlobAndQueueRequest} and - * {@link signBlobAndQueueRequestLite} depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signBlobAndQueueRequest} or + * {@link signBlobAndQueueRequestLite}, depending on your desired shared key authentication scheme. * * @param request * the request, as an HttpURLConnection object, to sign @@ -226,8 +226,8 @@ public void signRequest(final java.net.HttpURLConnection request, final long con * Signs a request using the specified credentials under the Shared Key Lite authentication scheme. This is not a * valid operation for objects of type StorageCredentialsAnonymous so the method performs a no-op. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. * * @param connection * the request, as an HttpURLConnection object, to sign @@ -243,8 +243,8 @@ public void signRequestLite(final java.net.HttpURLConnection connection, final l * valid operation for objects of type StorageCredentialsSharedAccessSignature so the method performs a * no-op. * - * @deprecated This method has been deprecated. Please use {@link signTableRequest} and {@link signTableRequestLite} - * depending on the desired shared key authentication scheme. + * @deprecated This method has been deprecated. Please use either {@link signTableRequest} or + * {@link signTableRequestLite}, depending on your desired shared key authentication scheme. * * @param request * the request, as an HttpURLConnection object, to sign From 7478ff924f2befe12da9dbb7a5784e17e173d603 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 26 Jun 2013 15:31:25 -0700 Subject: [PATCH 08/17] update unit tests to fix failures on CI machines. --- .../services/media/MediaProcessorIntegrationTest.java | 5 ++--- .../services/scenarios/MediaServiceWrapper.java | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java index 824c34d2dc93..26f11507aedf 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java @@ -38,13 +38,12 @@ private void verifyMediaProcessorInfo(String message, MediaProcessorInfo mediaPr } private void verifyMediaProcessorInfo(String message, String id, String name, String description, String sku, - String vendor, String version, MediaProcessorInfo mediaProcessorInfo) { + String vendor, MediaProcessorInfo mediaProcessorInfo) { assertEquals(message + " id", id, mediaProcessorInfo.getId()); assertEquals(message + " name", name, mediaProcessorInfo.getName()); assertEquals(message + " description", description, mediaProcessorInfo.getDescription()); assertEquals(message + " sku", sku, mediaProcessorInfo.getSku()); assertEquals(message + " vendor", vendor, mediaProcessorInfo.getVendor()); - assertEquals(message + " version", version, mediaProcessorInfo.getVersion()); } @Test @@ -73,6 +72,6 @@ public void listMediaProcessorWithOptionSuccess() throws ServiceException { assertEquals("listMediaProcessors size", 1, listMediaProcessorsResult.size()); MediaProcessorInfo mediaProcessorInfo = listMediaProcessorsResult.get(0); verifyMediaProcessorInfo("mediaProcessorInfo", "nb:mpid:UUID:aec03716-7c5e-4f68-b592-f4850eba9f10", - "Storage Decryption", "Storage Decryption", "", "Microsoft", "1.6", mediaProcessorInfo); + "Storage Decryption", "Storage Decryption", "", "Microsoft", mediaProcessorInfo); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java index c71781c96fe6..bc92439348ea 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java @@ -272,13 +272,13 @@ public Task.CreateBatchOperation createTaskOptions(String taskName, int inputAss String configuration = null; switch (encoderType) { case WindowsAzureMediaEncoder: - processor = getMediaProcessorIdByName(MEDIA_PROCESSOR_WINDOWS_AZURE_MEDIA_ENCODER, "2.2.0.0"); + processor = getMediaProcessorIdByName(MEDIA_PROCESSOR_WINDOWS_AZURE_MEDIA_ENCODER); // Full list of configurations strings for version 2.1 is at: // http://msdn.microsoft.com/en-us/library/jj129582.aspx configuration = "VC1 Broadband SD 4x3"; break; case StorageDecryption: - processor = getMediaProcessorIdByName(MEDIA_PROCESSOR_STORAGE_DECRYPTION, "1.6"); + processor = getMediaProcessorIdByName(MEDIA_PROCESSOR_STORAGE_DECRYPTION); configuration = null; break; default: @@ -296,10 +296,9 @@ private String getTaskBody(int inputAssetId, int outputAssetId) { + "JobOutputAsset(" + outputAssetId + ")"; } - private String getMediaProcessorIdByName(String processorName, String version) throws ServiceException { + private String getMediaProcessorIdByName(String processorName) throws ServiceException { EntityListOperation operation = MediaProcessor.list(); - operation.getQueryParameters().putSingle("$filter", - "(Name eq '" + processorName + "') and (Version eq '" + version + "')"); + operation.getQueryParameters().putSingle("$filter", "(Name eq '" + processorName + "')"); MediaProcessorInfo processor = service.list(operation).get(0); return processor.getId(); } From 200217c9ebf2d376863a618dd10af19bc5951d67 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 26 Jun 2013 15:56:15 -0700 Subject: [PATCH 09/17] fix a broken unit test on CI machine. --- .../ServiceBusConnectionSettingsTest.java | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusConnectionSettingsTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusConnectionSettingsTest.java index ec64e7d76eff..263213071b87 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusConnectionSettingsTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusConnectionSettingsTest.java @@ -1,25 +1,26 @@ /** * 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. + * 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.windowsazure.services.serviceBus.implementation; -import com.microsoft.windowsazure.services.core.Configuration; -import com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration; +import static junit.framework.Assert.*; + import org.junit.Test; -import static junit.framework.Assert.*; +import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration; public class ServiceBusConnectionSettingsTest { @@ -31,7 +32,8 @@ public void settingsAreParsedFromConnectionString() throws Exception { String connectionString = getConnectionString(ns, issuer, secret); - ServiceBusConnectionSettings settings = new ServiceBusConnectionSettings(connectionString, null, null, null, null); + ServiceBusConnectionSettings settings = new ServiceBusConnectionSettings(connectionString, null, null, null, + null); assertEquals(String.format("https://%1$s.servicebus.windows.net/", ns), settings.getUri()); assertEquals(String.format("https://%1$s-sb.accesscontrol.windows.net/WRAPv0.9", ns), settings.getWrapUri()); @@ -41,15 +43,16 @@ public void settingsAreParsedFromConnectionString() throws Exception { private String getConnectionString(String ns, String issuer, String secret) { return String.format( - "Endpoint=sb://%1$s.servicebus.windows.net/;SharedSecretIssuer=%2$s;SharedSecretValue=%3$s", - ns, issuer, secret); + "Endpoint=sb://%1$s.servicebus.windows.net/;SharedSecretIssuer=%2$s;SharedSecretValue=%3$s", ns, + issuer, secret); } private String getConnectionString(String ns, String stsEndpoint, String issuer, String secret) { - return String.format( - "Endpoint=sb://%1$s.servicebus.windows.net/;StsEndpoint=https://%1$s%4$s;SharedSecretIssuer=%2$s;SharedSecretValue=%3$s", - ns, issuer, secret, stsEndpoint); + return String + .format("Endpoint=sb://%1$s.servicebus.windows.net/;StsEndpoint=https://%1$s%4$s;SharedSecretIssuer=%2$s;SharedSecretValue=%3$s", + ns, issuer, secret, stsEndpoint); } + @Test public void settingsAreUsedFromConnectionStringInConfig() throws Exception { Configuration config = Configuration.load(); @@ -68,8 +71,8 @@ public void settingsAreUsedFromConnectionStringInConfig() throws Exception { public void settingsAreUsedFromIndividualSettingsInConfiguration() throws Exception { Configuration config = Configuration.load(); - ServiceBusConfiguration.configureWithWrapAuthentication(config, - "myNamespace", "owner", "secret", ".servicebus.windows.net/", "-sb.accesscontrol.windows.net/WRAPv0.9"); + ServiceBusConfiguration.configureWithWrapAuthentication(config, "myNamespace", "owner", "secret", + ".servicebus.windows.net/", "-sb.accesscontrol.windows.net/WRAPv0.9"); ServiceBusConnectionSettings settings = config.create(ServiceBusConnectionSettings.class); @@ -83,9 +86,8 @@ public void settingsAreUsedFromIndividualSettingsInConfiguration() throws Except public void settingsPreferConnectionStringIfBothPresentInConfiguration() throws Exception { Configuration config = Configuration.load(); - ServiceBusConfiguration.configureWithWrapAuthentication(config, - "myIndividualNamespace", "individualowner", "individualsecret", - ".servicebus.windows.net/", "-sb.accesscontrol.windows.net/WRAPv0.9"); + ServiceBusConfiguration.configureWithWrapAuthentication(config, "myIndividualNamespace", "individualowner", + "individualsecret", ".servicebus.windows.net/", "-sb.accesscontrol.windows.net/WRAPv0.9"); ServiceBusConfiguration.configureWithConnectionString(null, config, getConnectionString("myNamespaceCS", "ownerCS", "secretCS")); @@ -100,12 +102,11 @@ public void settingsPreferConnectionStringIfBothPresentInConfiguration() throws @Test public void canSetStSEndPointInConnectionString() throws Exception { - ServiceBusConnectionSettings settings = new ServiceBusConnectionSettings( - getConnectionString("myNs", "-some.accesscontrol.net", "owner", "secret"), - null, null, null, null); + ServiceBusConnectionSettings settings = new ServiceBusConnectionSettings(getConnectionString("myNs", + "-some.accesscontrol.net", "owner", "secret"), null, null, null, null); assertEquals("https://myNs.servicebus.windows.net/", settings.getUri()); - assertEquals("https://myNs-some.accesscontrol.net", settings.getWrapUri()); + assertEquals("https://myNs-some.accesscontrol.net/WRAPv0.9", settings.getWrapUri()); assertEquals("owner", settings.getWrapName()); assertEquals("secret", settings.getWrapPassword()); } From 2b5c3f6aff54b1b56c8c7313520ef0207892f059 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 27 Jun 2013 10:45:18 -0700 Subject: [PATCH 10/17] code review feedback regarding media processor integrration test. --- .../services/media/MediaProcessorIntegrationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java index 26f11507aedf..8132e3d52e67 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java @@ -44,6 +44,7 @@ private void verifyMediaProcessorInfo(String message, String id, String name, St assertEquals(message + " description", description, mediaProcessorInfo.getDescription()); assertEquals(message + " sku", sku, mediaProcessorInfo.getSku()); assertEquals(message + " vendor", vendor, mediaProcessorInfo.getVendor()); + assertTrue(message + "version length > 0", mediaProcessorInfo.getVersion().length() > 0); } @Test From 23aa9f41295202b58dc5a82ab331ab59224ca3f6 Mon Sep 17 00:00:00 2001 From: veudayab Date: Thu, 27 Jun 2013 19:01:03 -0700 Subject: [PATCH 11/17] Updated changelog --- ChangeLog.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 2c15b781280a..dbdbdf8e9582 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +2013.06.27 Version 0.4.4 + * Make sure the response stream is drained to prevent socket exhaustion. + * Support for all flavors of SharedKey and SharedKeyLite message signing through AuthenticationScheme property on client classes. + 2013.03.12 Version 0.4.1 * Added "Azure-SDK-For-Java/" To User-Agent HTTP header * Added connection string support for Service Bus From c0c8d9719919c044f70e333f7bf5335a0e23120f Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 28 Jun 2013 13:48:39 -0700 Subject: [PATCH 12/17] reduce the chance of a sporadic failure. --- .../services/serviceBus/ServiceBusIntegrationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index 971df258c02c..391a080279ae 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java @@ -486,6 +486,7 @@ public void receiveUpdatedSubscriptionForwardToTopicMessageSuccess() throws Exce new SubscriptionInfo(sourceSubscriptionName)).getValue(); service.updateSubscription(sourceTopicName, sourceSubscriptionInfo.setForwardTo(destinationTopicInfo.getUri().toString())); + Thread.sleep(1000); // Act service.sendTopicMessage(sourceTopicName, new BrokeredMessage("Hello source queue!")); From 79ce3c3842228d70dfb42a94bd115b5ee0dbf812 Mon Sep 17 00:00:00 2001 From: Guang Yang Date: Fri, 28 Jun 2013 16:39:52 -0700 Subject: [PATCH 13/17] update to 0.4.4 --- microsoft-azure-api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index 5fc0ac258437..f3199d17474f 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -17,7 +17,7 @@ 4.0.0 com.microsoft.windowsazure microsoft-windowsazure-api - 0.4.3 + 0.4.4 jar Microsoft Windows Azure Client API From cff277550969d106b62abb43119bf3bf8cabced6 Mon Sep 17 00:00:00 2001 From: Guang Yang Date: Fri, 28 Jun 2013 17:30:41 -0700 Subject: [PATCH 14/17] update changelog and readme for 0.4.4 --- ChangeLog.txt | 7 ++++++- README.md | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index e4643aa46091..02e6a9807803 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,9 @@ -2013.06.27 Version 0.4.4 +2013.07.03 Version 0.4.4 + * Windows Azure China environemnt support + * Service Bus metadata support updated to latest version + * Rich Odata entity query support for Service Bus Queue/Topic/Subscription + * Added support for Service Bus message forwarding + * Added support for Service Bus message count details * Make sure the response stream is drained to prevent socket exhaustion. * Support for all flavors of SharedKey and SharedKeyLite message signing through AuthenticationScheme property on client classes. diff --git a/README.md b/README.md index f12d7aa79956..86248e1374fb 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,14 @@ This project provides a client library in Java that makes it easy to consume Win * Create/Read/Update/Delete queues * Send/Receive/Unlock/Delete messages * Renew message lock + * Message forwarding * Topics * Create/Read/Update/Delete topics * Create/Read/Update/Delete subscriptions * Create/Read/Update/Delete rules * Send/Receive/Unlock/Delete messages * Renew message lock + * Message forwarding * Media Services * Create/Read/Update/Delete access policies * Create/Read/Update/Delete asset files @@ -57,7 +59,7 @@ within your project you can also have them installed by the Java package manager com.microsoft.windowsazure microsoft-windowsazure-api - 0.4.2 + 0.4.4 ``` From 32af1c840d881905248874ff8f4fefd1c647b032 Mon Sep 17 00:00:00 2001 From: Guang Yang Date: Fri, 28 Jun 2013 17:34:52 -0700 Subject: [PATCH 15/17] some minor fix --- ChangeLog.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 02e6a9807803..92c8e627002d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,8 +4,8 @@ * Rich Odata entity query support for Service Bus Queue/Topic/Subscription * Added support for Service Bus message forwarding * Added support for Service Bus message count details - * Make sure the response stream is drained to prevent socket exhaustion. - * Support for all flavors of SharedKey and SharedKeyLite message signing through AuthenticationScheme property on client classes. + * Make sure the response stream is drained to prevent socket exhaustion in Storage + * Support for all flavors of SharedKey and SharedKeyLite message signing through AuthenticationScheme property on client classes in Storage 2013.05.27 Version 0.4.3 * Added support for updating existing Queue/Topic/Subscription for Service Bus From 423f2700a8fbb930f25de94521e904100a99fde4 Mon Sep 17 00:00:00 2001 From: Guang Yang Date: Mon, 1 Jul 2013 09:15:23 -0700 Subject: [PATCH 16/17] incorporate feedback --- ChangeLog.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 92c8e627002d..18378c9cde81 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,11 +1,11 @@ 2013.07.03 Version 0.4.4 * Windows Azure China environemnt support - * Service Bus metadata support updated to latest version + * Service Bus metadata support updated to the latest version * Rich Odata entity query support for Service Bus Queue/Topic/Subscription * Added support for Service Bus message forwarding * Added support for Service Bus message count details - * Make sure the response stream is drained to prevent socket exhaustion in Storage - * Support for all flavors of SharedKey and SharedKeyLite message signing through AuthenticationScheme property on client classes in Storage + * Made sure the response stream is drained to prevent socket exhaustion in Storage + * Added support for all flavors of SharedKey and SharedKeyLite message signing through AuthenticationScheme property on client classes in Storage 2013.05.27 Version 0.4.3 * Added support for updating existing Queue/Topic/Subscription for Service Bus From 160210409e247b592d0df13785a27140f5e6dbc8 Mon Sep 17 00:00:00 2001 From: veudayab Date: Mon, 1 Jul 2013 10:24:50 -0700 Subject: [PATCH 17/17] Fix test issue for DateTime comparison --- .../windowsazure/services/table/client/TableTestBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java index 4d50f8dce703..32f9a19837e6 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java @@ -177,7 +177,7 @@ public void assertEquality(ComplexEntity other) { Assert.assertEquals(this.getPartitionKey(), other.getPartitionKey()); Assert.assertEquals(this.getRowKey(), other.getRowKey()); - assertDateApproxEquals(this.getDateTime(), other.getDateTime(), 100); + Assert.assertEquals(this.getDateTime().toString(), other.getDateTime().toString()); Assert.assertEquals(this.getGuid(), other.getGuid()); Assert.assertEquals(this.getString(), other.getString());