Search in sources :

Example 1 with Request

use of com.amazonaws.Request 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 Request

use of com.amazonaws.Request 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 Request

use of com.amazonaws.Request 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 Request

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

the class PutObjectRequestTest method doTestClone.

/**
 * Returns the cloned object.
 */
private <T extends PutObjectRequest> T doTestClone(T from, String bucket, String key, File file) {
    assertNull(from.getAccessControlList());
    assertEquals("bucket", from.getBucketName());
    assertNull(from.getCannedAcl());
    assertEquals(file, from.getFile());
    assertNull(from.getInputStream());
    assertNull(from.getRedirectLocation());
    assertNull(from.getStorageClass());
    // Fill it up - the base
    final ProgressListener listener = new ProgressListener() {

        @Override
        public void progressChanged(ProgressEvent progressEvent) {
        }
    };
    final AWSCredentials credentials = new BasicAWSCredentials("accesskey", "accessid");
    final RequestMetricCollector collector = new RequestMetricCollector() {

        @Override
        public void collectMetrics(Request<?> request, Response<?> response) {
        }
    };
    from.setGeneralProgressListener(listener);
    from.setRequestCredentials(credentials);
    from.setRequestMetricCollector(collector);
    final AccessControlList accessControlList = new AccessControlList();
    final ObjectMetadata metadata = new ObjectMetadata();
    metadata.addUserMetadata("um_k1", "um_v1");
    metadata.addUserMetadata("um_k2", "um_v2");
    final SSECustomerKey sseKey = new SSECustomerKey(new byte[32]);
    // Fill it up - the rest
    from.setAccessControlList(accessControlList);
    from.setCannedAcl(CannedAccessControlList.Private);
    from.setInputStream(System.in);
    from.setMetadata(metadata);
    from.setSSECustomerKey(sseKey);
    from.setRedirectLocation("redirectLocation");
    from.setStorageClass(StorageClass.Standard);
    assertSame(metadata, from.getMetadata());
    // Clone it
    final T to = (T) from.clone();
    // Verify
    assertSame(accessControlList, to.getAccessControlList());
    assertSame(CannedAccessControlList.Private, to.getCannedAcl());
    assertSame(System.in, to.getInputStream());
    assertNotSame(from.getMetadata(), to.getMetadata());
    final ObjectMetadata toOMD = to.getMetadata();
    assertEquals("um_v1", toOMD.getUserMetaDataOf("um_k1"));
    assertEquals("um_v2", toOMD.getUserMetaDataOf("um_k2"));
    assertSame(sseKey, to.getSSECustomerKey());
    assertEquals("redirectLocation", to.getRedirectLocation());
    assertEquals(StorageClass.Standard.toString(), to.getStorageClass());
    return to;
}
Also used : Response(com.amazonaws.Response) ProgressListener(com.amazonaws.event.ProgressListener) RequestMetricCollector(com.amazonaws.metrics.RequestMetricCollector) Request(com.amazonaws.Request) ProgressEvent(com.amazonaws.event.ProgressEvent) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 5 with Request

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

the class DefaultSigningMethodTest method createFakeGetObjectRequest.

private static Request<?> createFakeGetObjectRequest(AmazonS3Client s3) {
    try {
        final GetObjectRequest fakeRequest = new GetObjectRequest(FAKE_BUCKET, FAKE_KEY);
        final Request<?> fakeGetObjectRequest = (Request<?>) CREATE_REQUEST.invoke(s3, FAKE_BUCKET, FAKE_KEY, fakeRequest, HttpMethodName.GET);
        return fakeGetObjectRequest;
    } catch (final Exception e) {
        fail("Exception when calling the private \"createRequest\" method. " + e.getMessage());
        return null;
    }
}
Also used : AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) Request(com.amazonaws.Request) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Aggregations

Request (com.amazonaws.Request)5 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)4 Response (com.amazonaws.Response)4 AmazonClientException (com.amazonaws.AmazonClientException)3 AmazonServiceException (com.amazonaws.AmazonServiceException)3 AmazonWebServiceResponse (com.amazonaws.AmazonWebServiceResponse)3 DefaultRequest (com.amazonaws.DefaultRequest)3 RequestHandler2 (com.amazonaws.handlers.RequestHandler2)3 CRC32MismatchException (com.amazonaws.internal.CRC32MismatchException)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 ProgressEvent (com.amazonaws.event.ProgressEvent)1 ProgressListener (com.amazonaws.event.ProgressListener)1 CredentialsRequestHandler (com.amazonaws.handlers.CredentialsRequestHandler)1 RequestMetricCollector (com.amazonaws.metrics.RequestMetricCollector)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1