Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to Beirut

Conflicts:
	microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java
  • Loading branch information
Albert Cheng committed Jul 30, 2012
2 parents 5966f3b + 101b1e0 commit 36b1c3e
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import com.microsoft.windowsazure.services.blob.models.CommitBlobBlocksOptions;
import com.microsoft.windowsazure.services.blob.models.ContainerACL;
import com.microsoft.windowsazure.services.blob.models.CopyBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CopyBlobResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobBlockOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobPagesOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobPagesResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobSnapshotOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobSnapshotResult;
import com.microsoft.windowsazure.services.blob.models.CreateContainerOptions;
Expand Down Expand Up @@ -429,7 +431,7 @@ void setContainerMetadata(String container, HashMap<String, String> metadata, Se
* @throws ServiceException
* if an error occurs accessing the storage service.
*/
void createPageBlob(String container, String blob, long length) throws ServiceException;
CreateBlobResult createPageBlob(String container, String blob, long length) throws ServiceException;

/**
* Creates a page blob of the specified maximum length, using the specified options.
Expand Down Expand Up @@ -457,7 +459,8 @@ void setContainerMetadata(String container, HashMap<String, String> metadata, Se
* @throws ServiceException
* if an error occurs accessing the storage service.
*/
void createPageBlob(String container, String blob, long length, CreateBlobOptions options) throws ServiceException;
CreateBlobResult createPageBlob(String container, String blob, long length, CreateBlobOptions options)
throws ServiceException;

/**
* Creates a block blob from a content stream.
Expand All @@ -473,7 +476,7 @@ void setContainerMetadata(String container, HashMap<String, String> metadata, Se
* @throws ServiceException
* if an error occurs accessing the storage service.
*/
void createBlockBlob(String container, String blob, InputStream contentStream) throws ServiceException;
CreateBlobResult createBlockBlob(String container, String blob, InputStream contentStream) throws ServiceException;

/**
* Creates a block blob from a content stream, using the specified options.
Expand All @@ -495,7 +498,7 @@ void setContainerMetadata(String container, HashMap<String, String> metadata, Se
* @throws ServiceException
* if an error occurs accessing the storage service.
*/
void createBlockBlob(String container, String blob, InputStream contentStream, CreateBlobOptions options)
CreateBlobResult createBlockBlob(String container, String blob, InputStream contentStream, CreateBlobOptions options)
throws ServiceException;

/**
Expand Down Expand Up @@ -1214,8 +1217,8 @@ CreateBlobSnapshotResult createBlobSnapshot(String container, String blob, Creat
* @throws ServiceException
* if an error occurs accessing the storage service.
*/
void copyBlob(String destinationContainer, String destinationBlob, String sourceContainer, String sourceBlob)
throws ServiceException;
CopyBlobResult copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
String sourceBlob) throws ServiceException;

/**
* Copies a source blob to a destination within the storage account, using the specified options.
Expand Down Expand Up @@ -1293,8 +1296,8 @@ void copyBlob(String destinationContainer, String destinationBlob, String source
* @throws ServiceException
* if an error occurs accessing the storage service.
*/
void copyBlob(String destinationContainer, String destinationBlob, String sourceContainer, String sourceBlob,
CopyBlobOptions options) throws ServiceException;
CopyBlobResult copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
String sourceBlob, CopyBlobOptions options) throws ServiceException;

/**
* Gets a new lease on a blob.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import com.microsoft.windowsazure.services.blob.models.CommitBlobBlocksOptions;
import com.microsoft.windowsazure.services.blob.models.ContainerACL;
import com.microsoft.windowsazure.services.blob.models.CopyBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CopyBlobResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobBlockOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobPagesOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobPagesResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobSnapshotOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobSnapshotResult;
import com.microsoft.windowsazure.services.blob.models.CreateContainerOptions;
Expand Down Expand Up @@ -383,9 +385,9 @@ public ListBlobsResult listBlobs(String container, ListBlobsOptions options) thr
}

@Override
public void createPageBlob(String container, String blob, long length) throws ServiceException {
public CreateBlobResult createPageBlob(String container, String blob, long length) throws ServiceException {
try {
service.createPageBlob(container, blob, length);
return service.createPageBlob(container, blob, length);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand All @@ -396,10 +398,10 @@ public void createPageBlob(String container, String blob, long length) throws Se
}

@Override
public void createPageBlob(String container, String blob, long length, CreateBlobOptions options)
public CreateBlobResult createPageBlob(String container, String blob, long length, CreateBlobOptions options)
throws ServiceException {
try {
service.createPageBlob(container, blob, length, options);
return service.createPageBlob(container, blob, length, options);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand All @@ -410,9 +412,10 @@ public void createPageBlob(String container, String blob, long length, CreateBlo
}

@Override
public void createBlockBlob(String container, String blob, InputStream contentStream) throws ServiceException {
public CreateBlobResult createBlockBlob(String container, String blob, InputStream contentStream)
throws ServiceException {
try {
service.createBlockBlob(container, blob, contentStream);
return service.createBlockBlob(container, blob, contentStream);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand All @@ -423,10 +426,10 @@ public void createBlockBlob(String container, String blob, InputStream contentSt
}

@Override
public void createBlockBlob(String container, String blob, InputStream contentStream, CreateBlobOptions options)
throws ServiceException {
public CreateBlobResult createBlockBlob(String container, String blob, InputStream contentStream,
CreateBlobOptions options) throws ServiceException {
try {
service.createBlockBlob(container, blob, contentStream, options);
return service.createBlockBlob(container, blob, contentStream, options);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand Down Expand Up @@ -776,10 +779,10 @@ public CreateBlobSnapshotResult createBlobSnapshot(String container, String blob
}

@Override
public void copyBlob(String destinationContainer, String destinationBlob, String sourceContainer, String sourceBlob)
throws ServiceException {
public CopyBlobResult copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
String sourceBlob) throws ServiceException {
try {
service.copyBlob(destinationContainer, destinationBlob, sourceContainer, sourceBlob);
return service.copyBlob(destinationContainer, destinationBlob, sourceContainer, sourceBlob);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand All @@ -790,10 +793,10 @@ public void copyBlob(String destinationContainer, String destinationBlob, String
}

@Override
public void copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
public CopyBlobResult copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
String sourceBlob, CopyBlobOptions options) throws ServiceException {
try {
service.copyBlob(destinationContainer, destinationBlob, sourceContainer, sourceBlob, options);
return service.copyBlob(destinationContainer, destinationBlob, sourceContainer, sourceBlob, options);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import com.microsoft.windowsazure.services.blob.models.ContainerACL;
import com.microsoft.windowsazure.services.blob.models.ContainerACL.PublicAccessType;
import com.microsoft.windowsazure.services.blob.models.CopyBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CopyBlobResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobBlockOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobPagesOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobPagesResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobSnapshotOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobSnapshotResult;
import com.microsoft.windowsazure.services.blob.models.CreateContainerOptions;
Expand Down Expand Up @@ -488,12 +490,12 @@ public ListBlobsResult listBlobs(String container, ListBlobsOptions options) thr
}

@Override
public void createPageBlob(String container, String blob, long length) throws ServiceException {
createPageBlob(container, blob, length, new CreateBlobOptions());
public CreateBlobResult createPageBlob(String container, String blob, long length) throws ServiceException {
return createPageBlob(container, blob, length, new CreateBlobOptions());
}

@Override
public void createPageBlob(String container, String blob, long length, CreateBlobOptions options)
public CreateBlobResult createPageBlob(String container, String blob, long length, CreateBlobOptions options)
throws ServiceException {
String path = createPathFromContainer(container);
WebResource webResource = getResource(options).path(path).path(blob);
Expand All @@ -505,17 +507,25 @@ public void createPageBlob(String container, String blob, long length, CreateBlo
builder = addOptionalHeader(builder, "x-ms-blob-sequence-number", options.getSequenceNumber());
builder = addPutBlobHeaders(options, builder);

builder.put();
ClientResponse clientResponse = builder.put(ClientResponse.class);
ThrowIfError(clientResponse);

CreateBlobResult createBlobResult = new CreateBlobResult();
createBlobResult.setEtag(clientResponse.getHeaders().getFirst("ETag"));
createBlobResult.setLastModified(dateMapper.parse(clientResponse.getHeaders().getFirst("Last-Modified")));

return createBlobResult;
}

@Override
public void createBlockBlob(String container, String blob, InputStream contentStream) throws ServiceException {
createBlockBlob(container, blob, contentStream, new CreateBlobOptions());
public CreateBlobResult createBlockBlob(String container, String blob, InputStream contentStream)
throws ServiceException {
return createBlockBlob(container, blob, contentStream, new CreateBlobOptions());
}

@Override
public void createBlockBlob(String container, String blob, InputStream contentStream, CreateBlobOptions options)
throws ServiceException {
public CreateBlobResult createBlockBlob(String container, String blob, InputStream contentStream,
CreateBlobOptions options) throws ServiceException {
String path = createPathFromContainer(container);
System.out.println(path);
WebResource webResource = getResource(options).path(path).path(blob);
Expand All @@ -526,7 +536,14 @@ public void createBlockBlob(String container, String blob, InputStream contentSt
builder = addPutBlobHeaders(options, builder);

Object contentObject = (contentStream == null ? new byte[0] : contentStream);
builder.put(contentObject);
ClientResponse clientResponse = builder.put(ClientResponse.class, contentObject);
ThrowIfError(clientResponse);

CreateBlobResult createBlobResult = new CreateBlobResult();
createBlobResult.setEtag(clientResponse.getHeaders().getFirst("ETag"));
createBlobResult.setLastModified(dateMapper.parse(clientResponse.getHeaders().getFirst("Last-Modified")));

return createBlobResult;
}

@Override
Expand Down Expand Up @@ -651,6 +668,9 @@ public GetBlobResult getBlob(String container, String blob, GetBlobOptions optio
builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId());
builder = addOptionalRangeHeader(builder, options.getRangeStart(), options.getRangeEnd());
builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition());
if (options.isComputeRangeMD5()) {
builder = addOptionalHeader(builder, "x-ms-range-get-content-md5", "true");
}

ClientResponse response = builder.get(ClientResponse.class);
ThrowIfNotSuccess(response);
Expand Down Expand Up @@ -713,13 +733,13 @@ public CreateBlobSnapshotResult createBlobSnapshot(String container, String blob
}

@Override
public void copyBlob(String destinationContainer, String destinationBlob, String sourceContainer, String sourceBlob)
throws ServiceException {
copyBlob(destinationContainer, destinationBlob, sourceContainer, sourceBlob, new CopyBlobOptions());
public CopyBlobResult copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
String sourceBlob) throws ServiceException {
return copyBlob(destinationContainer, destinationBlob, sourceContainer, sourceBlob, new CopyBlobOptions());
}

@Override
public void copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
public CopyBlobResult copyBlob(String destinationContainer, String destinationBlob, String sourceContainer,
String sourceBlob, CopyBlobOptions options) {
String path = createPathFromContainer(destinationContainer);
WebResource webResource = getResource(options).path(path).path(destinationBlob);
Expand All @@ -733,7 +753,14 @@ public void copyBlob(String destinationContainer, String destinationBlob, String
builder = addOptionalAccessConditionHeader(builder, options.getAccessCondition());
builder = addOptionalSourceAccessConditionHeader(builder, options.getSourceAccessCondition());

builder.put();
ClientResponse clientResponse = builder.put(ClientResponse.class);
ThrowIfError(clientResponse);

CopyBlobResult copyBlobResult = new CopyBlobResult();
copyBlobResult.setEtag(clientResponse.getHeaders().getFirst("ETag"));
copyBlobResult.setLastModified(dateMapper.parse(clientResponse.getHeaders().getFirst("Last-Modified")));

return copyBlobResult;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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.blob.models;

import java.util.Date;

import com.microsoft.windowsazure.services.blob.BlobContract;

/**
* A wrapper class for the response returned from a Blob Service REST API Copy Blob operation. This is returned by calls
* to implementations of {@link BlobContract#copyBlob(String, String, String, String, CopyBlobOptions)}.
* <p>
* See the <a href="http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx">Copy Blob</a> documentation on
* MSDN for details of the underlying Blob Service REST API operation.
*/
public class CopyBlobResult {
private String etag;
private Date lastModified;

/**
* Gets the ETag of the blob.
*
* @return
* A {@link String} containing the server-assigned ETag value for the copy blob.
*/
public String getEtag() {
return etag;
}

/**
* Sets the ETag of the blob from the <code>ETag</code> header returned in the
* response.
* <p>
* This method is invoked by the API to set the value from the Blob Service REST API operation response returned by
* the server.
*
* @param etag
* A {@link String} containing the server-assigned ETag value for the blob.
*/
public void setEtag(String etag) {
this.etag = etag;
}

/**
* Gets the last modified time of the blob.
* <p>
*
* @return
* A {@link java.util.Date} containing the last modified time of the blob.
*/
public Date getLastModified() {
return lastModified;
}

/**
* Sets the last modified time of the blob from the <code>Last-Modified</code> header
* returned in the response.
* <p>
* This method is invoked by the API to set the value from the Blob Service REST API operation response returned by
* the server.
*
* @param lastModified
* A {@link java.util.Date} containing the last modified time of the blob.
*/
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
}
Loading

0 comments on commit 36b1c3e

Please sign in to comment.