1 /*
2 * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15 package com.amazonaws.services.s3.internal;
16
17 import com.amazonaws.internal.SdkPredicate;
18 import com.amazonaws.services.s3.model.AmazonS3Exception;
19
20 /**
21 * Complete Multipart Upload API returns a 2xx
22 * success response with an Error xml in the body. Some of these errors
23 * can be retried as per the API documentation {@see http://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadComplete.html}
24 *
25 * This predicate analyzes the exception and returns true if the exception
26 * can be retried.
27 *
28 * <p/>
29 * A sample success response with Error response Xml in body:
30 * <p/>
31 * HTTP/1.1 200 OK
32 * x-amz-id-2: Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==
33 * x-amz-request-id: 656c76696e6727732072657175657374
34 * Date: Mon, 1 Nov 2010 20:34:56 GMT
35 * Connection: close
36 * Server: AmazonS3
37 *
38 * <?xml version="1.0" encoding="UTF-8"?>
39 * <Error>
40 * <Code>InternalError</Code>
41 * <Message>We encountered an internal error. Please try again.</Message>
42 * <RequestId>656c76696e6727732072657175657374</RequestId>
43 * <HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>
44 * </Error>
45 */
46 public class CompleteMultipartUploadRetryablePredicate extends SdkPredicate<AmazonS3Exception> {
47
48 private static final String ERROR_CODE = "InternalError";
49 private static final String RETYABLE_ERROR_MESSAGE = "Please try again.";
50
51 @Override
52 public boolean test(AmazonS3Exception exception) {
53
54 if (exception == null || exception.getErrorCode() == null ||
55 exception.getErrorMessage() == null) {
56 return false;
57 }
58
59 return exception.getErrorCode().contains(ERROR_CODE) &&
60 exception.getErrorMessage().contains(RETYABLE_ERROR_MESSAGE);
61 }
62 }
63