Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #513 from Azure/legacy-dev
Browse files Browse the repository at this point in the history
Legacy dev
  • Loading branch information
rickle-msft authored Dec 2, 2019
2 parents c07aeb2 + 66eec3a commit 46a61b1
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 24 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2019.12.02 Version 8.5.0
* Support for HTTP proxy with Basic auth.
* Support for HTTP proxy with Digest auth.
* Added an option to SharedAccessHeaders that will allow the customer to preserve the raw value set on the object. Headers could previously be changed by an internal url decode that might modified the desired value.

2019.08.05 Version 8.4.0
* Support for 2019-02-02 REST version. Please see our REST API documentation and blogs for information about the related added features.
* Added support for setting rehydrate priority for SetBlobTier and CopyBlob APIs.
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.4.0</version>
<version>8.5.0</version>
</dependency>
```

Expand Down Expand Up @@ -101,7 +101,9 @@ public class BlobSample {
// Upload an image file.
CloudBlockBlob blob = container.getBlockBlobReference("image1.jpg");
File sourceFile = new File("c:\\myimages\\image1.jpg");
blob.upload(new FileInputStream(sourceFile), sourceFile.length());
try (FileInputStream sourceStream = new FileInputStream(sourceFile)) {
blob.upload(sourceStream, sourceFile.length());
}

// Download the image file.
File destinationFile = new File(sourceFile.getParentFile(), "image1Download.tmp");
Expand Down
2 changes: 1 addition & 1 deletion microsoft-azure-storage-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.4.0</version>
<version>8.5.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.4.0</version>
<version>8.5.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,47 @@ public void eventOccurred(SendingRequestEvent eventArg) {
sasBlob.download(new ByteArrayOutputStream(), null, null, context);
}

@Test
@Category(SlowTests.class)
public void testBlobSaSWithSharedAccessBlobHeadersPreserveRaw() throws InvalidKeyException,
IllegalArgumentException, StorageException, URISyntaxException, InterruptedException {
SharedAccessBlobPolicy sp = createSharedAccessPolicy(EnumSet.of(SharedAccessBlobPermissions.READ,
SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST), 300);
BlobContainerPermissions perms = new BlobContainerPermissions();

perms.getSharedAccessPolicies().put("readperm", sp);
this.container.uploadPermissions(perms);
Thread.sleep(30000);

SharedAccessBlobHeaders headers = new SharedAccessBlobHeaders(true);
headers.setCacheControl("no%20cache");
headers.setContentDisposition("inline; filename=\"My Image.jpg\"; filename*=UTF-8''My%20Image.jpg");
headers.setContentEncoding("gzip%20");
headers.setContentLanguage("da%20");
headers.setContentType("text/html; charset=utf%208");

CloudBlockBlob sasBlob = new CloudBlockBlob(new URI(this.blob.getUri().toString() + "?"
+ this.blob.generateSharedAccessSignature(null, headers, "readperm")));
OperationContext context = new OperationContext();

context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {

@Override
public void eventOccurred(SendingRequestEvent eventArg) {
HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject();
assertEquals("no%20cache", connection.getHeaderField(Constants.HeaderConstants.CACHE_CONTROL));
assertEquals("inline; filename=\"My Image.jpg\"; filename*=UTF-8''My%20Image.jpg",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_DISPOSITION));
assertEquals("gzip%20", connection.getHeaderField(Constants.HeaderConstants.CONTENT_ENCODING));
assertEquals("da%20", connection.getHeaderField(Constants.HeaderConstants.CONTENT_LANGUAGE));
assertEquals("text/html; charset=utf%208",
connection.getHeaderField(Constants.HeaderConstants.CONTENT_TYPE));
}
});

sasBlob.download(new ByteArrayOutputStream(), null, null, context);
}

@Test
public void testAppendBlobCopyWithSasAndSnapshot()
throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ public static class HeaderConstants {
/**
* Specifies the value to use for UserAgent header.
*/
public static final String USER_AGENT_VERSION = "8.4.0";
public static final String USER_AGENT_VERSION = "8.5.0";

/**
* The default type for content-type and accept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,31 @@ public final class OperationContext {
*/
private static Proxy proxyDefault;

/**
* Represents a username to be used by default for a proxy when making a request.
*/
private static String proxyDefaultUsername = null;

/**
* Represents a password to be used by default for a proxy when making a request.
*/
private static String proxyDefaultPassword = null;

/**
* Represents a proxy to be used when making a request.
*/
private Proxy proxy;

/**
* Represents a username for a proxy when making a request.
*/
private String proxyUsername = null;

/**
* Represents a password for a proxy when making a request.
*/
private String proxyPassword = null;

/**
* Represents the operation latency, in milliseconds, from the client's perspective. This may include any potential
* retries.
Expand Down Expand Up @@ -241,6 +261,26 @@ public Proxy getProxy() {
return this.proxy;
}

/**
* Gets a username for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a username use {@link #setProxyUsername(String)}
*
* @return A {@link String} to use when making a request.
*/
public String getProxyUsername() {
return proxyUsername != null ? proxyUsername : getDefaultProxyUsername();
}

/**
* Gets the password for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a password to use {@link #setProxyPassword(String)}
*
* @return A {@link String} to use when making a request.
*/
public String getProxyPassword() {
return proxyPassword != null ? proxyPassword : getDefaultProxyPassword();
}

/**
* Gets any additional headers for the request, for example, for proxy or logging information.
*
Expand Down Expand Up @@ -446,6 +486,28 @@ public void setProxy(Proxy proxy) {
this.proxy = proxy;
}

/**
* Sets a username for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param username
* A {@link java.lang.String} to use when making a request.
*/
public void setProxyUsername(final String username) {
this.proxyUsername = username;
}

/**
* Sets a password for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param password
* A {@link java.lang.String} to use when making a request.
*/
public void setProxyPassword(final String password) {
this.proxyPassword = password;
}

/**
* Sets any additional headers for the request, for example, for proxy or logging information.
*
Expand Down Expand Up @@ -619,4 +681,46 @@ public static Proxy getDefaultProxy() {
public static void setDefaultProxy(Proxy defaultProxy) {
OperationContext.proxyDefault = defaultProxy;
}

/**
* Gets a default username for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a username use {@link #setDefaultProxyUsername(String)}
*
* @return A {@link String} to use when making a request.
*/
public static String getDefaultProxyUsername() {
return OperationContext.proxyDefaultUsername;
}

/**
* Gets the default password for the authenticated proxy which will be used when making a request.
* Default is <code>null</code>. To set a password to use {@link #setProxyPassword(String)}
*
* @return A {@link String} to use when making a request.
*/
public static String getDefaultProxyPassword() {
return OperationContext.proxyDefaultPassword;
}

/**
* Sets a default username for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param username
* A {@link java.lang.String} to use when making a request.
*/
public static void setDefaultProxyUsername(final String username) {
OperationContext.proxyDefaultUsername = username;
}

/**
* Sets a default password for an authenticated proxy which will be used when making a request.
* Default is <code>null</code>.
*
* @param password
* A {@link java.lang.String} to use when making a request.
*/
public static void setDefaultProxyPassword(final String password) {
OperationContext.proxyDefaultPassword = password;
}
}
Loading

0 comments on commit 46a61b1

Please sign in to comment.