Search in sources :

Example 1 with Response

use of com.amazonaws.Response in project aws-sdk-android by aws-amplify.

the class AmazonHttpClientTest method testRequestHander2s.

@Test
public void testRequestHander2s() {
    final Request<?> testRequest = new DefaultRequest<String>("test");
    final List<Object> calls = new ArrayList<Object>();
    List<RequestHandler2> handlers = new ArrayList<RequestHandler2>();
    RequestHandler2 defaultHandler = new RequestHandler2() {

        @Override
        public void beforeRequest(Request<?> request) {
            assertSame(testRequest, request);
            calls.add(this);
        }

        @Override
        public void afterResponse(Request<?> request, Response<?> response) {
        }

        @Override
        public void afterError(Request<?> request, Response<?> response, Exception e) {
        }
    };
    RequestHandler2 credentialHandler = new CredentialsRequestHandler() {

        @Override
        public void beforeRequest(Request<?> request) {
            assertSame(testRequest, request);
            calls.add(this);
        }

        @Override
        public void afterResponse(Request<?> request, Response<?> response) {
        }

        @Override
        public void afterError(Request<?> request, Response<?> response, Exception e) {
        }
    };
    handlers.add(defaultHandler);
    handlers.add(credentialHandler);
    ExecutionContext ec = new ExecutionContext(handlers, false, null);
    client.requestHandler2s(testRequest, ec);
    assertEquals(calls.size(), 2);
    assertTrue(calls.contains(defaultHandler));
    assertTrue(calls.contains(credentialHandler));
}
Also used : AmazonWebServiceResponse(com.amazonaws.AmazonWebServiceResponse) Response(com.amazonaws.Response) DefaultRequest(com.amazonaws.DefaultRequest) RequestHandler2(com.amazonaws.handlers.RequestHandler2) ArrayList(java.util.ArrayList) Request(com.amazonaws.Request) DefaultRequest(com.amazonaws.DefaultRequest) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) URISyntaxException(java.net.URISyntaxException) CRC32MismatchException(com.amazonaws.internal.CRC32MismatchException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) CredentialsRequestHandler(com.amazonaws.handlers.CredentialsRequestHandler) Test(org.junit.Test)

Example 2 with Response

use of com.amazonaws.Response in project aws-sdk-android by aws-amplify.

the class AmazonHttpClientTest method testAfterError.

@Test
public void testAfterError() {
    final Request<?> testRequest = new DefaultRequest<String>("test");
    final Response<?> testResponse = new Response<String>("test", new HttpResponse.Builder().build());
    final List<Object> calls = new ArrayList<Object>();
    List<RequestHandler2> handlers = new ArrayList<RequestHandler2>();
    final AmazonClientException ace = new AmazonClientException("Test exception");
    RequestHandler2 handler = new RequestHandler2() {

        @Override
        public void beforeRequest(Request<?> request) {
        }

        @Override
        public void afterResponse(Request<?> request, Response<?> response) {
        }

        @Override
        public void afterError(Request<?> request, Response<?> response, Exception e) {
            assertSame(testRequest, request);
            assertSame(testResponse, response);
            assertSame(e, ace);
            calls.add(this);
        }
    };
    handlers.add(handler);
    client.afterError(testRequest, testResponse, handlers, ace);
    assertEquals(calls.size(), 1);
    assertTrue(calls.contains(handler));
}
Also used : DefaultRequest(com.amazonaws.DefaultRequest) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) Request(com.amazonaws.Request) DefaultRequest(com.amazonaws.DefaultRequest) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) URISyntaxException(java.net.URISyntaxException) CRC32MismatchException(com.amazonaws.internal.CRC32MismatchException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) AmazonWebServiceResponse(com.amazonaws.AmazonWebServiceResponse) Response(com.amazonaws.Response) RequestHandler2(com.amazonaws.handlers.RequestHandler2) Test(org.junit.Test)

Example 3 with Response

use of com.amazonaws.Response in project aws-sdk-android by aws-amplify.

the class AmazonHttpClientTest method testAfterResponse.

@Test
public void testAfterResponse() {
    final Request<?> testRequest = new DefaultRequest<String>("test");
    final Response<?> testResponse = new Response<String>("test", new HttpResponse.Builder().build());
    final List<Object> calls = new ArrayList<Object>();
    List<RequestHandler2> handlers = new ArrayList<RequestHandler2>();
    RequestHandler2 handler = new RequestHandler2() {

        @Override
        public void beforeRequest(Request<?> request) {
        }

        @Override
        public void afterResponse(Request<?> request, Response<?> response) {
            assertSame(testRequest, request);
            assertSame(testResponse, response);
            calls.add(this);
        }

        @Override
        public void afterError(Request<?> request, Response<?> response, Exception e) {
        }
    };
    handlers.add(handler);
    client.afterResponse(testRequest, handlers, testResponse, null);
    assertEquals(calls.size(), 1);
    assertTrue(calls.contains(handler));
}
Also used : AmazonWebServiceResponse(com.amazonaws.AmazonWebServiceResponse) Response(com.amazonaws.Response) DefaultRequest(com.amazonaws.DefaultRequest) RequestHandler2(com.amazonaws.handlers.RequestHandler2) ArrayList(java.util.ArrayList) Request(com.amazonaws.Request) DefaultRequest(com.amazonaws.DefaultRequest) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) URISyntaxException(java.net.URISyntaxException) CRC32MismatchException(com.amazonaws.internal.CRC32MismatchException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) Test(org.junit.Test)

Example 4 with Response

use of com.amazonaws.Response in project fernet-java8 by l0s.

the class MemoryOverwritingRequestHandlerTest method verifyAfterErrorClearsSecret.

@Test
public void verifyAfterErrorClearsSecret() {
    // given
    final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 });
    assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
    final PutSecretValueRequest originalRequest = new PutSecretValueRequest();
    originalRequest.setSecretBinary(secretBinary);
    final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest, "AWSSecretsManager");
    final PutSecretValueResult result = mock(PutSecretValueResult.class);
    final HttpResponse httpResponse = mock(HttpResponse.class);
    final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse);
    // when
    handler.afterError(request, response, new Exception());
    // then
    assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
}
Also used : HttpResponse(com.amazonaws.http.HttpResponse) Response(com.amazonaws.Response) PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest) DefaultRequest(com.amazonaws.DefaultRequest) HttpResponse(com.amazonaws.http.HttpResponse) ByteBuffer(java.nio.ByteBuffer) PutSecretValueResult(com.amazonaws.services.secretsmanager.model.PutSecretValueResult) Test(org.junit.Test)

Example 5 with Response

use of com.amazonaws.Response in project fernet-java8 by l0s.

the class MemoryOverwritingRequestHandlerTest method verifyAfterResponseClearsSecret.

@Test
public void verifyAfterResponseClearsSecret() {
    // given
    final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 });
    assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
    final PutSecretValueRequest originalRequest = new PutSecretValueRequest();
    originalRequest.setSecretBinary(secretBinary);
    final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest, "AWSSecretsManager");
    final PutSecretValueResult result = mock(PutSecretValueResult.class);
    final HttpResponse httpResponse = mock(HttpResponse.class);
    final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse);
    // when
    handler.afterResponse(request, response);
    // then
    assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
}
Also used : HttpResponse(com.amazonaws.http.HttpResponse) Response(com.amazonaws.Response) PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest) DefaultRequest(com.amazonaws.DefaultRequest) HttpResponse(com.amazonaws.http.HttpResponse) ByteBuffer(java.nio.ByteBuffer) PutSecretValueResult(com.amazonaws.services.secretsmanager.model.PutSecretValueResult) Test(org.junit.Test)

Aggregations

Response (com.amazonaws.Response)7 DefaultRequest (com.amazonaws.DefaultRequest)5 Test (org.junit.Test)5 AmazonClientException (com.amazonaws.AmazonClientException)4 AmazonServiceException (com.amazonaws.AmazonServiceException)4 AmazonWebServiceResponse (com.amazonaws.AmazonWebServiceResponse)4 Request (com.amazonaws.Request)4 IOException (java.io.IOException)4 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)3 RequestHandler2 (com.amazonaws.handlers.RequestHandler2)3 CRC32MismatchException (com.amazonaws.internal.CRC32MismatchException)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 HttpResponse (com.amazonaws.http.HttpResponse)2 PutSecretValueRequest (com.amazonaws.services.secretsmanager.model.PutSecretValueRequest)2 PutSecretValueResult (com.amazonaws.services.secretsmanager.model.PutSecretValueResult)2 ByteBuffer (java.nio.ByteBuffer)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 Signer (com.amazonaws.auth.Signer)1