diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java index f4914fb400568..1366704cf2d81 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java @@ -148,12 +148,12 @@ private Builder addOptionalRangeHeader(Builder builder, Long rangeStart, Long ra return PipelineHelpers.addOptionalRangeHeader(builder, rangeStart, rangeEnd); } - private Builder addOptionalAccessContitionHeader(Builder builder, AccessCondition accessCondition) { - return PipelineHelpers.addOptionalAccessContitionHeader(builder, accessCondition); + private Builder addOptionalAccessConditionHeader(Builder builder, AccessCondition accessCondition) { + return PipelineHelpers.addOptionalAccessConditionHeader(builder, accessCondition); } - private Builder addOptionalSourceAccessContitionHeader(Builder builder, AccessCondition accessCondition) { - return PipelineHelpers.addOptionalSourceAccessContitionHeader(builder, accessCondition); + private Builder addOptionalSourceAccessConditionHeader(Builder builder, AccessCondition accessCondition) { + return PipelineHelpers.addOptionalSourceAccessConditionHeader(builder, accessCondition); } private HashMap getMetadataFromHeaders(ClientResponse response) { @@ -193,7 +193,7 @@ private Builder addPutBlobHeaders(CreateBlobOptions options, Builder builder) { builder = addOptionalHeader(builder, "x-ms-blob-cache-control", options.getBlobCacheControl()); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); builder = addOptionalMetadataHeader(builder, options.getMetadata()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); return builder; } @@ -324,7 +324,7 @@ public void deleteContainer(String container, DeleteContainerOptions options) th WebResource webResource = getResource(options).path(container).queryParam("resType", "container"); WebResource.Builder builder = webResource.header("x-ms-version", API_VERSION); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); builder.delete(); } @@ -445,7 +445,7 @@ public void setContainerMetadata(String container, HashMap metad WebResource.Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalMetadataHeader(builder, metadata); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); builder.put(); } @@ -560,7 +560,7 @@ public GetBlobPropertiesResult getBlobProperties(String container, String blob, Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); ClientResponse response = builder.method("HEAD", ClientResponse.class); ThrowIfNotSuccess(response); @@ -582,7 +582,7 @@ public GetBlobMetadataResult getBlobMetadata(String container, String blob, GetB Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); ClientResponse response = builder.get(ClientResponse.class); ThrowIfError(response); @@ -611,7 +611,7 @@ public SetBlobPropertiesResult setBlobProperties(String container, String blob, builder = addOptionalHeader(builder, "x-ms-sequence-number-action", options.getSequenceNumberAction()); builder = addOptionalHeader(builder, "x-ms-blob-sequence-number", options.getSequenceNumber()); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); ClientResponse response = builder.put(ClientResponse.class); ThrowIfError(response); @@ -642,7 +642,7 @@ public SetBlobMetadataResult setBlobMetadata(String container, String blob, Hash WebResource.Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); builder = addOptionalMetadataHeader(builder, metadata); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); ClientResponse response = builder.put(ClientResponse.class); ThrowIfError(response); @@ -667,7 +667,7 @@ public GetBlobResult getBlob(String container, String blob, GetBlobOptions optio Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); builder = addOptionalRangeHeader(builder, options.getRangeStart(), options.getRangeEnd()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); if (options.isComputeRangeMD5()) { builder = addOptionalHeader(builder, "x-ms-range-get-content-md5", "true"); } @@ -700,7 +700,7 @@ public void deleteBlob(String container, String blob, DeleteBlobOptions options) builder = addOptionalHeader(builder, "x-ms-delete-snapshots", options.getDeleteSnaphotsOnly() ? "only" : "include"); } - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); builder.delete(); } @@ -719,7 +719,7 @@ public CreateBlobSnapshotResult createBlobSnapshot(String container, String blob Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); builder = addOptionalMetadataHeader(builder, options.getMetadata()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); ClientResponse response = builder.put(ClientResponse.class); ThrowIfError(response); @@ -750,8 +750,8 @@ public CopyBlobResult copyBlob(String destinationContainer, String destinationBl builder = addOptionalHeader(builder, "x-ms-copy-source", getCopyBlobSourceName(sourceContainer, sourceBlob, options)); builder = addOptionalMetadataHeader(builder, options.getMetadata()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); - builder = addOptionalSourceAccessContitionHeader(builder, options.getSourceAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); + builder = addOptionalSourceAccessConditionHeader(builder, options.getSourceAccessCondition()); ClientResponse clientResponse = builder.put(ClientResponse.class); ThrowIfError(clientResponse); @@ -815,7 +815,7 @@ private AcquireLeaseResult putLeaseImpl(String leaseAction, String container, St Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", leaseId); builder = addOptionalHeader(builder, "x-ms-lease-action", leaseAction); - builder = addOptionalAccessContitionHeader(builder, accessCondition); + builder = addOptionalAccessConditionHeader(builder, accessCondition); // Note: Add content type here to enable proper HMAC signing ClientResponse response = builder.put(ClientResponse.class); @@ -861,7 +861,7 @@ private CreateBlobPagesResult updatePageBlobPagesImpl(String action, String cont builder = addOptionalHeader(builder, "Content-MD5", options.getContentMD5()); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); builder = addOptionalHeader(builder, "x-ms-page-write", action); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); ClientResponse response = builder.put(ClientResponse.class, contentStream); ThrowIfError(response); @@ -889,7 +889,7 @@ public ListBlobRegionsResult listBlobRegions(String container, String blob, List Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalRangeHeader(builder, options.getRangeStart(), options.getRangeEnd()); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); ClientResponse response = builder.get(ClientResponse.class); ThrowIfError(response); @@ -941,7 +941,7 @@ public void commitBlobBlocks(String container, String blob, BlockList blockList, builder = addOptionalHeader(builder, "x-ms-blob-content-language", options.getBlobContentLanguage()); builder = addOptionalHeader(builder, "x-ms-blob-content-md5", options.getBlobContentMD5()); builder = addOptionalMetadataHeader(builder, options.getMetadata()); - builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition()); builder.put(blockList); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java index 21b95538f6e11..7f117707aafcc 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java @@ -80,7 +80,7 @@ public static Builder addOptionalRangeHeader(Builder builder, Long rangeStart, L return builder; } - public static Builder addOptionalAccessContitionHeader(Builder builder, AccessCondition accessCondition) { + public static Builder addOptionalAccessConditionHeader(Builder builder, AccessCondition accessCondition) { if (accessCondition != null) { if (accessCondition.getHeader() != AccessConditionHeaderType.NONE) { builder = addOptionalHeader(builder, accessCondition.getHeader().toString(), accessCondition.getValue()); @@ -89,19 +89,23 @@ public static Builder addOptionalAccessContitionHeader(Builder builder, AccessCo return builder; } - public static Builder addOptionalSourceAccessContitionHeader(Builder builder, AccessCondition accessCondition) { + public static Builder addOptionalSourceAccessConditionHeader(Builder builder, AccessCondition accessCondition) { if (accessCondition != null) { if (accessCondition.getHeader() != AccessConditionHeaderType.NONE) { String headerName; switch (accessCondition.getHeader()) { case IF_MATCH: headerName = "x-ms-source-if-match"; + break; case IF_UNMODIFIED_SINCE: headerName = "x-ms-source-if-unmodified-since"; + break; case IF_MODIFIED_SINCE: headerName = "x-ms-source-if-modified-since"; + break; case IF_NONE_MATCH: headerName = "x-ms-source-if-none-match"; + break; default: headerName = ""; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java index c654e49c6faef..7fc710b76d00a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/ServiceBusRestProxy.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import javax.inject.Named; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import org.apache.commons.logging.Log; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpersTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpersTest.java new file mode 100644 index 0000000000000..670b3e7ae0a23 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpersTest.java @@ -0,0 +1,42 @@ +/** + * Copyright 2011 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.utils.pipeline; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.microsoft.windowsazure.services.blob.models.AccessCondition; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.WebResource.Builder; + +public class PipelineHelpersTest { + @Test + public void addOptionalSourceAccessConditionHeaderSuccess() throws Exception { + // Arrange + Client client = Client.create(); + WebResource webResource = client.resource("http://www.microsoft.com"); + Builder builder = webResource.header("ms-version", "1.0"); + AccessCondition accessCondition = AccessCondition.ifMatch("thisIsAETag"); + + // Act + Builder resultBuilder = PipelineHelpers.addOptionalSourceAccessConditionHeader(builder, accessCondition); + + // Assert + assertNotNull(resultBuilder); + + } +}