Skip to content

Commit

Permalink
Merge pull request Azure#446 from jcookems/fix445
Browse files Browse the repository at this point in the history
Fix for Azure#445
  • Loading branch information
jcookems committed Oct 31, 2012
2 parents c6ad7c0 + 735ffbe commit 6a41e3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@

import javax.ws.rs.core.MultivaluedMap;

import com.microsoft.windowsazure.services.core.IdempotentClientFilter;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.filter.ClientFilter;

/**
* A small filter that adds the required Media services/OData 3
* version headers to the request as it goes through.
*
*/
public class VersionHeadersFilter extends ClientFilter {
public class VersionHeadersFilter extends IdempotentClientFilter {

/* (non-Javadoc)
* @see com.sun.jersey.api.client.filter.ClientFilter#handle(com.sun.jersey.api.client.ClientRequest)
* @see com.microsoft.windowsazure.services.core.IdempotentClientFilter#doHandle(com.sun.jersey.api.client.ClientRequest)
*/
@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException {
public ClientResponse doHandle(ClientRequest cr) throws ClientHandlerException {
MultivaluedMap<String, Object> headers = cr.getHeaders();
headers.add("DataServiceVersion", "3.0");
headers.add("MaxDataServiceVersion", "3.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import java.util.EnumSet;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.microsoft.windowsazure.services.core.ExponentialRetryPolicy;
import com.microsoft.windowsazure.services.core.RetryPolicyFilter;
import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission;
Expand Down Expand Up @@ -59,11 +60,6 @@ private void verifyPolicyProperties(String message, String testName, double dura
assertEquals(message + " Created & LastModified", policy.getCreated(), policy.getLastModified());
}

@Before
public void setupInstance() throws Exception {
service = MediaService.create(config);
}

@Test
public void canCreateAccessPolicy() throws Exception {
String testName = testPolicyPrefix + "CanCreate";
Expand Down Expand Up @@ -200,4 +196,17 @@ public void canDeleteAccessPolicyByNonexistId() throws Exception {
expectedException.expect(new ServiceExceptionMatcher(404));
service.deleteAccessPolicy(validButNonexistAccessPolicyId);
}

@Test
public void canUploadBlockBlobWithExplicitRetry() throws Exception {
String name = testPolicyPrefix + "canUploadBlockBlobWithExplicitRetry";
double duration = 1;
EnumSet<AccessPolicyPermission> write = EnumSet.of(AccessPolicyPermission.WRITE);
service.createAccessPolicy(name + "1", duration, write);

ExponentialRetryPolicy forceRetryPolicy = new ExponentialRetryPolicy(1, 1, new int[] { 201 });
MediaContract forceRetryService = service.withFilter(new RetryPolicyFilter(forceRetryPolicy));

forceRetryService.createAccessPolicy(name + "2", duration, write);
}
}

0 comments on commit 6a41e3a

Please sign in to comment.