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.azure.storage.domain;
20  
21  import java.util.Map;
22  
23  import com.google.common.collect.Maps;
24  
25  /**
26   * When an Azure Storage request is in error, the client receives an error response.
27   * 
28   * @see <a href="http://msdn.microsoft.com/en-us/library/dd573365.aspx" />
29   * @author Adrian Cole
30   * 
31   */
32  public class AzureStorageError {
33     private String code;
34     private String message;
35     private String requestId;
36     private Map<String, String> details = Maps.newHashMap();
37     private String stringSigned;
38     private String signature;
39  
40     @Override
41     public String toString() {
42        final StringBuilder sb = new StringBuilder();
43        sb.append("AzureError");
44        sb.append("{requestId='").append(requestId).append('\'');
45        if (code != null)
46           sb.append(", code='").append(code).append('\'');
47        if (message != null)
48           sb.append(", message='").append(message).append('\'');
49        if (stringSigned != null)
50           sb.append(", stringSigned='").append(stringSigned).append('\'');
51        if (getSignature() != null)
52           sb.append(", signature='").append(getSignature()).append('\'');
53        if (details.size() != 0)
54           sb.append(", context='").append(details.toString()).append('\'').append('}');
55        return sb.toString();
56     }
57  
58     public void setCode(String code) {
59        this.code = code;
60     }
61  
62     public String getCode() {
63        return code;
64     }
65  
66     public void setMessage(String message) {
67        this.message = message;
68     }
69  
70     public String getMessage() {
71        return message;
72     }
73  
74     public void setRequestId(String requestId) {
75        this.requestId = requestId;
76     }
77  
78     /**
79      * If a request is consistently failing and you have verified that the request is properly
80      * formulated, you may use this value to report the error to Microsoft. In your report, include
81      * the value of x-ms-request-id, the approximate time that the request was made, the storage
82      * service against which the request was made, and the type of operation that the request
83      * attempted
84      */
85     public String getRequestId() {
86        return requestId;
87     }
88  
89     public void setStringSigned(String stringSigned) {
90        this.stringSigned = stringSigned;
91     }
92  
93     /**
94      * @return what jclouds signed before sending the request.
95      */
96     public String getStringSigned() {
97        return stringSigned;
98     }
99  
100    public void setDetails(Map<String, String> context) {
101       this.details = context;
102    }
103 
104    /**
105     * @return additional details surrounding the error.
106     */
107    public Map<String, String> getDetails() {
108       return details;
109    }
110 
111    public void setSignature(String signature) {
112       this.signature = signature;
113    }
114 
115    public String getSignature() {
116       return signature;
117    }
118 }