1 /*
2 * Copyright 2010-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;
16
17 import java.util.Map;
18
19 /**
20 * Represents additional metadata included with a response from AWS. Response
21 * metadata varies by service, but all services return an AWS request ID that
22 * can be used in the event a service call isn't working as expected and you
23 * need to work with AWS support to debug an issue.
24 * <p>
25 * Access to AWS request IDs is also available through the com.amazonaws.request
26 * logger in the AWS SDK for Java.
27 */
28 public class ResponseMetadata {
29 public static final String AWS_REQUEST_ID = "AWS_REQUEST_ID";
30
31 public static final String AWS_EXTENDED_REQUEST_ID = "AWS_EXTENDED_REQUEST_ID";
32
33 protected final Map<String, String> metadata;
34
35 /**
36 * Creates a new ResponseMetadata object from a specified map of raw
37 * metadata information.
38 *
39 * @param metadata
40 * The raw metadata for the new ResponseMetadata object.
41 */
42 public ResponseMetadata(Map<String, String> metadata) {
43 this.metadata = metadata;
44 }
45
46 /**
47 * Creates a new ResponseMetadata object from an existing ResponseMetadata
48 * object.
49 *
50 * @param originalResponseMetadata
51 * The ResponseMetadata object from which to create the new
52 * object.
53 */
54 public ResponseMetadata(ResponseMetadata originalResponseMetadata) {
55 this(originalResponseMetadata.metadata);
56 }
57
58 /**
59 * Returns the AWS request ID contained in this response metadata object.
60 * AWS request IDs can be used in the event a service call isn't working as
61 * expected and you need to work with AWS support to debug an issue.
62 *
63 * @return The AWS request ID contained in this response metadata object.
64 */
65 public String getRequestId() {
66 return metadata.get(AWS_REQUEST_ID);
67 }
68
69 @Override
70 public String toString() {
71 if (metadata == null) return "{}";
72 return metadata.toString();
73 }
74
75 }
76