View Javadoc

1   /**
2    * Licensed to jclouds, Inc. (jclouds) under one or more
3    * contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  jclouds licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.jclouds.aws.domain;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /**
25   * When an Amazon S3 request is in error, the client receives an error response.
26   * 
27   * @see <a
28   *      href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?ErrorResponse.html"
29   *      />
30   * @author Adrian Cole
31   * 
32   */
33  public class AWSError {
34     private String code;
35     private String message;
36     private String requestId;
37     private String requestToken;
38     private Map<String, String> details = new HashMap<String, String>();
39     private String stringSigned;
40     private String signature;
41  
42     @Override
43     public String toString() {
44        final StringBuilder sb = new StringBuilder();
45        sb.append("AWSError");
46        sb.append("{requestId='").append(requestId).append('\'');
47        sb.append(", requestToken='").append(requestToken).append('\'');
48        if (code != null)
49           sb.append(", code='").append(code).append('\'');
50        if (message != null)
51           sb.append(", message='").append(message).append('\'');
52        if (stringSigned != null)
53           sb.append(", stringSigned='").append(stringSigned).append('\'');
54        if (getSignature() != null)
55           sb.append(", signature='").append(getSignature()).append('\'');
56        if (details.size() != 0)
57           sb.append(", context='").append(details.toString()).append('\'').append('}');
58        return sb.toString();
59     }
60  
61     public void setCode(String code) {
62        this.code = code;
63     }
64  
65     /**
66      * The error code is a string that uniquely identifies an error condition. It is meant to be read
67      * and understood by programs that detect and handle errors by type
68      * 
69      * @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/ErrorCode.html" />
70      */
71     public String getCode() {
72        return code;
73     }
74  
75     public void setMessage(String message) {
76        this.message = message;
77     }
78  
79     /**
80      * The error message contains a generic description of the error condition in English.
81      * 
82      * @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/ErrorMessage.html" />
83      */
84     public String getMessage() {
85        return message;
86     }
87  
88     public void setRequestId(String requestId) {
89        this.requestId = requestId;
90     }
91  
92     /**
93      * * A unique ID assigned to each request by the system. In the unlikely event that you have
94      * problems with Amazon S3, Amazon can use this to help troubleshoot the problem.
95      * 
96      */
97     public String getRequestId() {
98        return requestId;
99     }
100 
101    public void setStringSigned(String stringSigned) {
102       this.stringSigned = stringSigned;
103    }
104 
105    /**
106     * @return what jclouds signed before sending the request.
107     */
108    public String getStringSigned() {
109       return stringSigned;
110    }
111 
112    public void setDetails(Map<String, String> context) {
113       this.details = context;
114    }
115 
116    /**
117     * @return additional details surrounding the error.
118     */
119    public Map<String, String> getDetails() {
120       return details;
121    }
122 
123    public void setRequestToken(String requestToken) {
124       this.requestToken = requestToken;
125    }
126 
127    public String getRequestToken() {
128       return requestToken;
129    }
130 
131    public void setSignature(String signature) {
132       this.signature = signature;
133    }
134 
135    public String getSignature() {
136       return signature;
137    }
138 }