Skip to content

Commit

Permalink
Merge pull request #7 from gcheng/Beirut
Browse files Browse the repository at this point in the history
Add breaks to AddOptionalAccessCondition in PipelineHelper
  • Loading branch information
Albert Cheng committed Jul 30, 2012
2 parents 101b1e0 + 36b1c3e commit e9830c4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> getMetadataFromHeaders(ClientResponse response) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -445,7 +445,7 @@ public void setContainerMetadata(String container, HashMap<String, String> 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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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");
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 = "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

}
}

0 comments on commit e9830c4

Please sign in to comment.