Skip to content

Commit

Permalink
Merge pull request #651 from jcookems/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jcookems committed Mar 8, 2013
2 parents ce4a3bf + 0145416 commit 7f614ec
Show file tree
Hide file tree
Showing 55 changed files with 1,766 additions and 214 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@
.project
target
node_modules
.idea
*.iml
8 changes: 7 additions & 1 deletion ChangeLog.txt
@@ -1,4 +1,10 @@
2013.1.18 Version 0.4.0
2013.02.22 Version 0.4.1
* Fixed the return value of BlobInputStream.read
* Fixed CloudPageBlob.downloadPageRanges to retrieve the blob length
* Fixed MD5 validation in BlobInputStream
* Return ETag in TableResult not only for Insert but also for other operations

2013.01.18 Version 0.4.0
* Added support for Windows Azure Media Services
* Updated dependencies to non-beta stable versions
* Add a Sending Request Event to OperationContext in Storage Client code
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -34,7 +34,7 @@ For documentation please see the [Windows Azure Java Developer Center](http://ww
To get the source code of the SDK via git just type:

git clone git://github.com/WindowsAzure/azure-sdk-for-java.git
cd ./azure-sdk-for-java
cd ./azure-sdk-for-java/microsoft-azure-api/
mvn compile

###Option 2: Via Maven
Expand Down
2 changes: 1 addition & 1 deletion microsoft-azure-api/pom.xml
Expand Up @@ -171,7 +171,7 @@
<configuration>
<excludePackageNames>*.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization</excludePackageNames>
<bottom><![CDATA[<code>/**
<br/>* Copyright 2011 Microsoft Corporation
<br/>* Copyright Microsoft Corporation
<br/>*
<br/>* Licensed under the Apache License, Version 2.0 (the "License");
<br/>* you may not use this file except in compliance with the License.
Expand Down
Expand Up @@ -21,6 +21,7 @@
import com.microsoft.windowsazure.services.blob.models.AcquireLeaseResult;
import com.microsoft.windowsazure.services.blob.models.BlobServiceOptions;
import com.microsoft.windowsazure.services.blob.models.BlockList;
import com.microsoft.windowsazure.services.blob.models.BreakLeaseResult;
import com.microsoft.windowsazure.services.blob.models.CommitBlobBlocksOptions;
import com.microsoft.windowsazure.services.blob.models.ContainerACL;
import com.microsoft.windowsazure.services.blob.models.CopyBlobOptions;
Expand Down Expand Up @@ -1440,16 +1441,23 @@ void releaseLease(String container, String blob, String leaseId, BlobServiceOpti
* <p>
* A lease that has been broken but has not yet expired can also be released, in which case another client may
* immediately acquire a new lease on the blob.
*
*
* @deprecated Server ignores the leaseId parameter, replaced by {@link #breakLease(String, String)} without
* the useless parameter.
*
* @param container
* A {@link String} containing the name of the blob's container.
* @param blob
* A {@link String} containing the name of the blob to break a lease on.
* @param leaseId
* A {@link String} containing an optional lease ID.
*
* @param leaseId lease id to break. Ignored.
*
* @throws ServiceException
* if an error occurs accessing the storage service.
*
* @return result containing time remaining before a new lease can be acquired
*/
@Deprecated()
void breakLease(String container, String blob, String leaseId) throws ServiceException;

/**
Expand All @@ -1465,17 +1473,78 @@ void releaseLease(String container, String blob, String leaseId, BlobServiceOpti
* <p>
* A lease that has been broken but has not yet expired can also be released, in which case another client may
* immediately acquire a new lease on the blob.
*
*
* @deprecated Server ignores the leaseId parameter, replaced by
* {@link #breakLease(String, String, com.microsoft.windowsazure.services.blob.models.BlobServiceOptions)}
* without the useless parameter.
*
*
* @param container
* A {@link String} containing the name of the blob's container.
* @param blob
* A {@link String} containing the name of the blob to break a lease on.
* @param leaseId
* A {@link String} containing an optional lease ID.
* @param options
* A {@link BlobServiceOptions} instance containing options for the request.
* A {@link com.microsoft.windowsazure.services.blob.models.BlobServiceOptions} instance containing options for the request.
* @param leaseId lease id to break. Ignored.
*
* @throws ServiceException
* if an error occurs accessing the storage service.
* @return result containing time remaining before a new lease can be acquired
*/
@Deprecated()
void breakLease(String container, String blob, String leaseId, BlobServiceOptions options) throws ServiceException;

/**
* Breaks an active lease on a blob.
* <p>
* This method breaks the lease on the blob specified by the <em>blob</em> and <em>container</em> parameters. The
* <em>leaseId</em> parameter is not used by the server.
* <p>
* Once a lease is broken, it cannot be renewed. Any authorized request can break the lease; the request is not
* required to specify a matching lease ID. When a lease is broken, the remaining time on the lease is allowed to
* elapse, during which time no lease operation may be performed on the blob.
* <p>
* A lease that has been broken but has not yet expired can also be released, in which case another client may
* immediately acquire a new lease on the blob.
*
*
*
* @param container
* A {@link String} containing the name of the blob's container.
* @param blob
* A {@link String} containing the name of the blob to break a lease on.
* @throws ServiceException
* if an error occurs accessing the storage service.
*
* @return result containing time remaining before a new lease can be acquired
*/
BreakLeaseResult breakLease(String container, String blob) throws ServiceException;

/**
* Breaks an active lease on a blob, using the specified options.
* <p>
* This method breaks the lease on the blob specified by the <em>blob</em> and <em>container</em> parameters. The
* <em>leaseId</em> parameter is not used by the server. Use the {@link BlobServiceOptions options} parameter to
* specify the server timeout for the operation.
* <p>
* Once a lease is broken, it cannot be renewed. Any authorized request can break the lease; the request is not
* required to specify a matching lease ID. When a lease is broken, the remaining time on the lease is allowed to
* elapse, during which time no lease operation may be performed on the blob.
* <p>
* A lease that has been broken but has not yet expired can also be released, in which case another client may
* immediately acquire a new lease on the blob.
*
*
*
* @param container
* A {@link String} containing the name of the blob's container.
* @param blob
* A {@link String} containing the name of the blob to break a lease on.
* @param options
* A {@link com.microsoft.windowsazure.services.blob.models.BlobServiceOptions} instance containing options for the request.
* @throws ServiceException
* if an error occurs accessing the storage service.
* @return result containing time remaining before a new lease can be acquired
*/
BreakLeaseResult breakLease(String container, String blob, BlobServiceOptions options) throws ServiceException;
}
Expand Up @@ -20,6 +20,7 @@
import com.microsoft.windowsazure.services.blob.implementation.SharedKeyFilter;
import com.microsoft.windowsazure.services.blob.implementation.SharedKeyLiteFilter;
import com.microsoft.windowsazure.services.core.Builder;
import com.microsoft.windowsazure.services.core.UserAgentFilter;

public class Exports implements Builder.Exports {
@Override
Expand All @@ -30,5 +31,6 @@ public void register(Builder.Registry registry) {
registry.add(SharedKeyLiteFilter.class);
registry.add(SharedKeyFilter.class);
registry.add(ISO8601DateConverter.class);
registry.add(UserAgentFilter.class);
}
}
Expand Up @@ -82,6 +82,11 @@ public final class BlobInputStream extends InputStream {
*/
private boolean validateBlobMd5;

/**
* Holds the Blob MD5.
*/
private final String retrievedContentMD5Value;

/**
* Holds the reference to the current buffered data.
*/
Expand Down Expand Up @@ -161,11 +166,11 @@ protected BlobInputStream(final CloudBlob parentBlob, final AccessCondition acce

final HttpURLConnection attributesRequest = this.opContext.getCurrentRequestObject();

final String retrievedContentMD5Value = attributesRequest.getHeaderField(Constants.HeaderConstants.CONTENT_MD5);
this.retrievedContentMD5Value = attributesRequest.getHeaderField(Constants.HeaderConstants.CONTENT_MD5);

// Will validate it if it was returned
this.validateBlobMd5 = !options.getDisableContentMD5Validation()
&& !Utility.isNullOrEmpty(retrievedContentMD5Value);
&& !Utility.isNullOrEmpty(this.retrievedContentMD5Value);

// Validates the first option, and sets future requests to use if match
// request option.
Expand Down Expand Up @@ -395,8 +400,17 @@ public boolean markSupported() {
@DoesServiceRequest
public int read() throws IOException {
final byte[] tBuff = new byte[1];
this.read(tBuff, 0, 1);
return tBuff[0];
final int numberOfBytesRead = this.read(tBuff, 0, 1);

if (numberOfBytesRead > 0) {
return tBuff[0] & 0xFF;
}
else if (numberOfBytesRead == 0) {
throw new IOException("Unexpected error. Stream returned unexpected number of bytes.");
}
else {
return -1;
}
}

/**
Expand Down Expand Up @@ -519,13 +533,13 @@ private synchronized int readInternal(final byte[] b, final int off, int len) th
if (this.currentAbsoluteReadPosition == this.streamLength) {
// Reached end of stream, validate md5.
final String calculatedMd5 = Base64.encode(this.md5Digest.digest());
if (!calculatedMd5.equals(this.parentBlobRef.getProperties().getContentMD5())) {
if (!calculatedMd5.equals(this.retrievedContentMD5Value)) {
this.lastError = Utility
.initIOException(new StorageException(
StorageErrorCodeStrings.INVALID_MD5,
String.format(
"Blob data corrupted (integrity check failed), Expected value is %s, retrieved %s",
this.parentBlobRef.getProperties().getContentMD5(), calculatedMd5),
this.retrievedContentMD5Value, calculatedMd5),
Constants.HeaderConstants.HTTP_UNUSED_306, null, null));
this.streamFaulted = true;
throw this.lastError;
Expand Down
Expand Up @@ -221,7 +221,7 @@ protected CloudBlob(final CloudBlob otherBlob) {
*
* @param leaseTimeInSeconds
* Specifies the span of time for which to acquire the lease, in seconds.
* If null, an infinite lease will be acquired. If not null, the value must be greater than
* If null, an infinite lease will be acquired. If not null, the value must be greater than
* zero.
*
* @param proposedLeaseId
Expand All @@ -245,7 +245,7 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String
*
* @param leaseTimeInSeconds
* Specifies the span of time for which to acquire the lease, in seconds.
* If null, an infinite lease will be acquired. If not null, the value must be greater than
* If null, an infinite lease will be acquired. If not null, the value must be greater than
* zero.
*
* @param proposedLeaseId
Expand All @@ -254,12 +254,12 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the blob.
*
*
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client
* <code>null</code> will use the default request options from the associated service client
* ({@link CloudBlobClient}).
*
*
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
Expand Down Expand Up @@ -342,7 +342,7 @@ protected final void assertCorrectBlobType() throws StorageException {
}

/**
* Breaks the lease and ensures that another client cannot acquire a new lease until the current lease period
* Breaks the lease and ensures that another client cannot acquire a new lease until the current lease period
* has expired.
*
* @param breakPeriodInSeconds
Expand All @@ -360,7 +360,7 @@ public final long breakLease(final Integer breakPeriodInSeconds) throws StorageE
}

/**
* Breaks the existing lease, using the specified request options and operation context, and ensures that another
* Breaks the existing lease, using the specified request options and operation context, and ensures that another
* client cannot acquire a new lease until the current lease period has expired.
*
* @param breakPeriodInSeconds
Expand All @@ -371,7 +371,7 @@ public final long breakLease(final Integer breakPeriodInSeconds) throws StorageE
* An {@link AccessCondition} object that represents the access conditions for the blob.
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client
* <code>null</code> will use the default request options from the associated service client
* ({@link CloudBlobClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. The context
Expand Down Expand Up @@ -1328,14 +1328,16 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op
return null;
}

// Do not update blob length in downloadRangeInternal API.
final long orignalBlobLength = blob.properties.getLength();
// Do not update blob length and Content-MD5 in downloadRangeInternal API.
final long originalBlobLength = blob.properties.getLength();
final String originalContentMD5 = blob.properties.getContentMD5();
final BlobAttributes retrievedAttributes = BlobResponse.getAttributes(request, blob.getUri(),
blob.snapshotID, opContext);
blob.properties = retrievedAttributes.getProperties();
blob.metadata = retrievedAttributes.getMetadata();
blob.copyState = retrievedAttributes.getCopyState();
blob.properties.setLength(orignalBlobLength);
blob.properties.setContentMD5(originalContentMD5);
blob.properties.setLength(originalBlobLength);

final String contentLength = request.getHeaderField(Constants.HeaderConstants.CONTENT_LENGTH);
final long expectedLength = Long.parseLong(contentLength);
Expand Down Expand Up @@ -2049,7 +2051,7 @@ public final void changeLease(final String proposedLeaseId, final AccessConditio
* required to be set with an access condition.
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
* <code>null</code> will use the default request options from the associated service client
* <code>null</code> will use the default request options from the associated service client
* ({@link CloudBlobClient}).
* @param opContext
* An {@link OperationContext} object that represents the context for the current operation. The context
Expand Down
Expand Up @@ -360,6 +360,8 @@ public ArrayList<PageRange> execute(final CloudBlobClient client, final CloudBlo
}

blob.updateEtagAndLastModifiedFromResponse(request);
blob.updateLengthFromResponse(request);

final GetPageRangesResponse response = new GetPageRangesResponse(request.getInputStream());
return response.getPageRanges();
}
Expand Down Expand Up @@ -490,7 +492,6 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op
}

blob.updateEtagAndLastModifiedFromResponse(request);
blob.updateLengthFromResponse(request);
return null;
}
};
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.microsoft.windowsazure.services.blob.models.AcquireLeaseResult;
import com.microsoft.windowsazure.services.blob.models.BlobServiceOptions;
import com.microsoft.windowsazure.services.blob.models.BlockList;
import com.microsoft.windowsazure.services.blob.models.BreakLeaseResult;
import com.microsoft.windowsazure.services.blob.models.CommitBlobBlocksOptions;
import com.microsoft.windowsazure.services.blob.models.ContainerACL;
import com.microsoft.windowsazure.services.blob.models.CopyBlobOptions;
Expand Down Expand Up @@ -888,9 +889,21 @@ public void releaseLease(String container, String blob, String leaseId, BlobServ
}

@Override
@Deprecated
public void breakLease(String container, String blob, String leaseId) throws ServiceException {
breakLease(container, blob);
}

@Override
@Deprecated
public void breakLease(String container, String blob, String leaseId, BlobServiceOptions options) throws ServiceException {
breakLease(container, blob, options);
}

@Override
public BreakLeaseResult breakLease(String container, String blob) throws ServiceException {
try {
service.breakLease(container, blob, leaseId);
return service.breakLease(container, blob);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand All @@ -901,10 +914,10 @@ public void breakLease(String container, String blob, String leaseId) throws Ser
}

@Override
public void breakLease(String container, String blob, String leaseId, BlobServiceOptions options)
public BreakLeaseResult breakLease(String container, String blob, BlobServiceOptions options)
throws ServiceException {
try {
service.breakLease(container, blob, leaseId, options);
return service.breakLease(container, blob, options);
}
catch (UniformInterfaceException e) {
throw processCatch(new ServiceException(e));
Expand Down

0 comments on commit 7f614ec

Please sign in to comment.