Search in sources :

Example 1 with AbortedException

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

the class RetryUtilsTest method testIsInterruptedException.

@Test
public void testIsInterruptedException() {
    assertTrue(RetryUtils.isInterrupted(new AbortedException()));
    Exception interrupted = new Exception(new InterruptedException());
    assertTrue(RetryUtils.isInterrupted(interrupted));
    Exception interruptedio = new Exception(new InterruptedIOException());
    assertTrue(RetryUtils.isInterrupted(interruptedio));
    Exception socketTimeout = new Exception(new SocketTimeoutException());
    assertFalse(RetryUtils.isInterrupted(socketTimeout));
}
Also used : InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException) AbortedException(com.amazonaws.AbortedException) SocketTimeoutException(java.net.SocketTimeoutException) AbortedException(com.amazonaws.AbortedException) InterruptedIOException(java.io.InterruptedIOException) Test(org.junit.Test)

Example 2 with AbortedException

use of com.amazonaws.AbortedException in project javabuilder by code-dot-org.

the class AWSContentManager method generateAssetUploadUrl.

@Override
public String generateAssetUploadUrl(String filename) throws JavabuilderException {
    if (this.uploads >= UPLOADS_PER_SESSION) {
        throw new UserInitiatedException(UserInitiatedExceptionKey.TOO_MANY_UPLOADS, String.format("Too many Prompter images. We currently support up to %s Prompter images per project.\n", UPLOADS_PER_SESSION));
    }
    final String key = this.generateKey(filename);
    final long expirationTimeMs = System.currentTimeMillis() + context.getRemainingTimeInMillis();
    try {
        final URL presignedUrl = s3Client.generatePresignedUrl(this.bucketName, key, new Date(expirationTimeMs), HttpMethod.PUT);
        this.uploads++;
        // Add the GET url for this file to the asset map so it can be referenced later.
        this.projectData.addNewAssetUrl(filename, this.contentBucketUrl + "/" + key);
        return this.contentBucketUrl + presignedUrl.getFile();
    } catch (AbortedException e) {
    // this is most likely because the end user interrupted program execution. We can safely
    // ignore this.
    } catch (SdkClientException e) {
        throw new InternalServerError(InternalErrorKey.INTERNAL_RUNTIME_EXCEPTION, e);
    }
    return null;
}
Also used : SdkClientException(com.amazonaws.SdkClientException) AbortedException(com.amazonaws.AbortedException) URL(java.net.URL) Date(java.util.Date)

Example 3 with AbortedException

use of com.amazonaws.AbortedException in project javabuilder by code-dot-org.

the class AWSContentManager method writeToOutputFile.

@Override
public String writeToOutputFile(String filename, byte[] inputBytes, String contentType) throws JavabuilderException {
    if (this.writes >= WRITES_PER_SESSION) {
        throw new UserInitiatedException(UserInitiatedExceptionKey.TOO_MANY_WRITES);
    }
    String filePath = this.generateKey(filename);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType(contentType);
    metadata.setContentLength(inputBytes.length);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(inputBytes);
    try {
        this.s3Client.putObject(this.bucketName, filePath, inputStream, metadata);
    } catch (AbortedException e) {
    // this is most likely because the end user interrupted program execution. We can safely
    // ignore this.
    } catch (SdkClientException e) {
        // We couldn't write to S3, send a message to the user and fail. The S3 SDK includes retries.
        throw new InternalServerError(InternalErrorKey.INTERNAL_RUNTIME_EXCEPTION, e);
    }
    this.writes++;
    return this.contentBucketUrl + "/" + filePath;
}
Also used : SdkClientException(com.amazonaws.SdkClientException) ByteArrayInputStream(java.io.ByteArrayInputStream) AbortedException(com.amazonaws.AbortedException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 4 with AbortedException

use of com.amazonaws.AbortedException in project datarouter by hotpads.

the class BaseSqsPeekMultiOp method run.

@Override
protected final List<T> run() {
    ReceiveMessageRequest request = makeRequest();
    ReceiveMessageResult result;
    try {
        result = sqsClientManager.getAmazonSqs(clientId).receiveMessage(request);
    } catch (AbortedException e) {
        throw new UncheckedInterruptedException("", e);
    }
    List<Message> messages = result.getMessages();
    return messages.isEmpty() ? List.of() : extractDatabeans(messages);
}
Also used : ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) Message(com.amazonaws.services.sqs.model.Message) AbortedException(com.amazonaws.AbortedException) UncheckedInterruptedException(io.datarouter.util.concurrent.UncheckedInterruptedException) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult)

Example 5 with AbortedException

use of com.amazonaws.AbortedException in project datarouter by hotpads.

the class SqsAckOp method run.

@Override
protected Void run() {
    String handle = StringCodec.UTF_8.decode(key.getHandle());
    var deleteRequest = new DeleteMessageRequest(queueUrl, handle);
    try {
        sqsClientManager.getAmazonSqs(clientId).deleteMessage(deleteRequest);
    } catch (AbortedException e) {
        throw new UncheckedInterruptedException("", e);
    }
    return null;
}
Also used : AbortedException(com.amazonaws.AbortedException) DeleteMessageRequest(com.amazonaws.services.sqs.model.DeleteMessageRequest) UncheckedInterruptedException(io.datarouter.util.concurrent.UncheckedInterruptedException)

Aggregations

AbortedException (com.amazonaws.AbortedException)18 Test (org.junit.Test)7 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 SdkClientException (com.amazonaws.SdkClientException)4 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)4 ConstantInputStream (com.amazonaws.testutils.util.ConstantInputStream)4 UncheckedInterruptedException (io.datarouter.util.concurrent.UncheckedInterruptedException)4 File (java.io.File)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)2 SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ExecutorService (java.util.concurrent.ExecutorService)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ProgressListener (com.amazonaws.event.ProgressListener)1 ProgressListenerCallbackExecutor (com.amazonaws.event.ProgressListenerCallbackExecutor)1