Skip to content

Commit

Permalink
Merge pull request #159 from christav/dev
Browse files Browse the repository at this point in the history
Added error checking to list blob call to defend against missing headers
  • Loading branch information
Chris Tavares committed Oct 10, 2012
2 parents 9a909f1 + 97ea1c2 commit 110adf1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,19 @@ else if (options.isUncommittedList()) {
ListBlobBlocksResult result = response.getEntity(ListBlobBlocksResult.class);
result.setEtag(response.getHeaders().getFirst("ETag"));
result.setContentType(response.getHeaders().getFirst("Content-Type"));
result.setContentLength(Long.parseLong(response.getHeaders().getFirst("x-ms-blob-content-length")));
result.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));

String blobContentLength = response.getHeaders().getFirst("x-ms-blob-content-length");
if (blobContentLength != null) {
result.setContentLength(Long.parseLong(blobContentLength));
}
else {
result.setContentLength(0);
}

String lastModified = response.getHeaders().getFirst("Last-Modified");
if (lastModified != null) {
result.setLastModified(dateMapper.parse(lastModified));
}

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,38 @@ public void listBlobsWithDelimiterWorks() throws Exception {
assertEquals(0, results6.getBlobPrefixes().size());
}

// Repro case for https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/295
@Test
public void listBlockBlobWithNoCommittedBlocksWorks() throws Exception {
Configuration config = createConfiguration();
BlobContract service = BlobService.create(config);

String container = "mysample2";
String blob = "test14";

try {
service.createContainer(container);
service.listBlobs(container);
service.createBlockBlob(container, blob, null);
service.createBlobBlock(container, blob, "01", new ByteArrayInputStream(new byte[] { 0x00 }));
service.listBlobBlocks(container, blob, new ListBlobBlocksOptions().setCommittedList(true)
.setUncommittedList(true));
service.listBlobs(container);
service.deleteContainer(container);
Thread.sleep(40000);
service.createContainer(container);
service.listBlobs(container);
service.createBlobBlock(container, blob, "01", new ByteArrayInputStream(new byte[] { 0x00 }));
// The next line throws
service.listBlobBlocks(container, blob, new ListBlobBlocksOptions().setCommittedList(true)
.setUncommittedList(true));
service.listBlobs(container);
}
finally {
deleteContainers(service, null, new String[] { container });
}
}

@Test
public void createPageBlobWorks() throws Exception {
// Arrange
Expand Down

0 comments on commit 110adf1

Please sign in to comment.