Skip to content

Commit

Permalink
Merge pull request #31 from gcheng/bettererror
Browse files Browse the repository at this point in the history
Bettererror
  • Loading branch information
Albert Cheng committed Apr 12, 2013
2 parents 11992bb + 53de17d commit bdc1c7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,29 @@
import com.sun.jersey.api.client.WebResource.Builder;

public class PipelineHelpers {

private static String createErrorMessage(ClientResponse clientResponse) {
clientResponse.bufferEntity();
String errorMessage = clientResponse.toString();
if (clientResponse.hasEntity()) {
errorMessage = errorMessage + " " + clientResponse.getEntity(String.class);
}
return errorMessage;
}

public static void ThrowIfNotSuccess(ClientResponse clientResponse) {
int statusCode = clientResponse.getStatus();

if ((statusCode < 200) || (statusCode >= 300)) {
throw new UniformInterfaceException(clientResponse);
String errorMessage = createErrorMessage(clientResponse);
throw new UniformInterfaceException(errorMessage, clientResponse);
}
}

public static void ThrowIfError(ClientResponse clientResponse) {
if (clientResponse.getStatus() >= 400) {
throw new UniformInterfaceException(clientResponse);
String errorMessage = createErrorMessage(clientResponse);
throw new UniformInterfaceException(errorMessage, clientResponse);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.junit.Assert.*;

import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.PrivateKey;
import java.security.Security;
Expand Down Expand Up @@ -284,9 +285,10 @@ public void rebindContentKeyWithX509CertficateSuccess() throws Exception {
byte[] aesKey = createTestAesKey();
ContentKeyInfo contentKeyInfo = createValidTestContentKeyWithAesKey("rebindContentKeyWithX509Success", aesKey);
URL serverCertificateUri = getClass().getResource("/certificate/server.crt");
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(serverCertificateUri.getFile());
X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(URLDecoder.decode(
serverCertificateUri.getFile(), "UTF-8"));
URL serverPrivateKey = getClass().getResource("/certificate/server.der");
PrivateKey privateKey = EncryptionHelper.getPrivateKey(serverPrivateKey.getFile());
PrivateKey privateKey = EncryptionHelper.getPrivateKey(URLDecoder.decode(serverPrivateKey.getFile(), "UTF-8"));

String rebindedContentKey = service.action(ContentKey.rebind(contentKeyInfo.getId(),
URLEncoder.encode(Base64.encode(x509Certificate.getEncoded()), "UTF-8")));
Expand Down

0 comments on commit bdc1c7d

Please sign in to comment.