Skip to content

Commit

Permalink
Merge pull request Azure#21 from WindowsAzure/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Albert Cheng committed Oct 9, 2012
2 parents 3f29fc3 + 808a960 commit 8f59e46
Show file tree
Hide file tree
Showing 8 changed files with 1,415 additions and 1,074 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -0,0 +1,67 @@
/**
* Copyright 2012 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.media.implementation;

import java.net.URISyntaxException;

import javax.ws.rs.core.UriBuilder;

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;

/**
* Filter responsible for adding SAS tokens to outgoing requests.
*
*/
public class SASTokenFilter extends ClientFilter {
private final String sasToken;

/**
* Construct a SASTokenFilter that will insert the tokens given
* in the provided sasUrl.
*
* @param sasUrl
* URL containing authentication information
* @throws URISyntaxException
*/
public SASTokenFilter(String sasToken) {
this.sasToken = sasToken;
}

/* (non-Javadoc)
* @see com.sun.jersey.api.client.filter.ClientFilter#handle(com.sun.jersey.api.client.ClientRequest)
*/
@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException {
UriBuilder newUri = UriBuilder.fromUri(cr.getURI());
String currentQuery = cr.getURI().getRawQuery();
if (currentQuery == null) {
currentQuery = "";
}
else if (currentQuery.length() > 0) {
currentQuery += "&";
}
currentQuery += sasToken;

newUri.replaceQuery(currentQuery);
cr.setURI(newUri.build());

return getNext().handle(cr);
}

}

This file was deleted.

Expand Up @@ -20,8 +20,6 @@
import java.util.EnumSet;
import java.util.List;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
Expand All @@ -39,6 +37,9 @@ public class AccessPolicyIntegrationTest extends IntegrationTestBase {

private static final String testPrefix = "testPolicy";

@Rule
public ExpectedException expected = ExpectedException.none();

@BeforeClass
public static void setup() throws Exception {
service = MediaService.create(createConfig());
Expand Down Expand Up @@ -114,9 +115,6 @@ public void canRetrieveListOfAccessPolicies() throws Exception {
EnumSet.of(AccessPolicyPermission.WRITE, AccessPolicyPermission.LIST)));
}

@Rule
public ExpectedException expected = ExpectedException.none();

@Test
public void getWithBadIdThrowsServiceException() throws Exception {
expected.expect(ServiceException.class);
Expand All @@ -125,26 +123,7 @@ public void getWithBadIdThrowsServiceException() throws Exception {

@Test
public void getWithValidButNonExistentPolicyIdThrows404ServiceException() throws Exception {
expected.expect(new BaseMatcher<ServiceException>() {

@Override
public boolean matches(Object item) {
if (item.getClass() != ServiceException.class) {
return false;
}

if (((ServiceException) item).getHttpStatusCode() != 404) {
return false;
}

return true;
}

@Override
public void describeTo(Description description) {
description.appendText("Must be ServiceException with a 404 status code");
}
});
expected.expect(new ServiceExceptionMatcher(404));
service.getAccessPolicy("nb:pid:UUID:bce3863e-830b-49f5-9199-7cfaff52935f");
}

Expand Down

0 comments on commit 8f59e46

Please sign in to comment.