LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 * Copyright (c) 2010 Google Inc. | 2 * Copyright (c) 2010 Google Inc. |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.apache.org/licenses/LICENSE-2.0 | 7 * http://www.apache.org/licenses/LICENSE-2.0 |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 /** HTTP status code. */ | 31 /** HTTP status code. */ |
32 private final int statusCode; | 32 private final int statusCode; |
33 | 33 |
34 /** Status message or {@code null}. */ | 34 /** Status message or {@code null}. */ |
35 private final String statusMessage; | 35 private final String statusMessage; |
36 | 36 |
37 /** HTTP headers. */ | 37 /** HTTP headers. */ |
38 private final transient HttpHeaders headers; | 38 private final transient HttpHeaders headers; |
39 | 39 |
40 /** HTTP response. */ | |
41 @Deprecated | |
42 private final transient HttpResponse response; | |
43 | |
44 /** | |
45 * Returns the HTTP response. | |
46 * | |
47 * @since 1.5 | |
48 * @deprecated (scheduled to be removed in 1.10) | |
49 */ | |
50 @Deprecated | |
51 public final HttpResponse getResponse() { | |
52 return response; | |
53 } | |
54 | |
55 /** | 40 /** |
56 * Constructor that constructs a detail message from the given HTTP response t
hat includes the | 41 * Constructor that constructs a detail message from the given HTTP response t
hat includes the |
57 * status code, status message and HTTP response content. | 42 * status code, status message and HTTP response content. |
| 43 * |
| 44 * <p> |
| 45 * Callers of this constructor should call {@link HttpResponse#disconnect} aft
er |
| 46 * {@link HttpResponseException} is instantiated. Example usage: |
| 47 * </p> |
| 48 * |
| 49 * <pre> |
| 50 try { |
| 51 throw new HttpResponseException(response); |
| 52 } finally { |
| 53 response.disconnect(); |
| 54 } |
| 55 * </pre> |
58 * | 56 * |
59 * @param response HTTP response | 57 * @param response HTTP response |
60 */ | 58 */ |
61 public HttpResponseException(HttpResponse response) { | 59 public HttpResponseException(HttpResponse response) { |
62 this(response, computeMessageWithContent(response)); | 60 this(response, computeMessageWithContent(response)); |
63 } | 61 } |
64 | 62 |
65 /** | 63 /** |
66 * Constructor that allows an alternative detail message to be used. | 64 * Constructor that allows an alternative detail message to be used. |
67 * | 65 * |
| 66 * <p> |
| 67 * Callers of this constructor should call {@link HttpResponse#disconnect} aft
er |
| 68 * {@link HttpResponseException} is instantiated. Example usage: |
| 69 * </p> |
| 70 * |
| 71 * <pre> |
| 72 try { |
| 73 throw new HttpResponseException(response, message); |
| 74 } finally { |
| 75 response.disconnect(); |
| 76 } |
| 77 * </pre> |
| 78 * |
68 * @param response HTTP response | 79 * @param response HTTP response |
69 * @param message detail message to use or {@code null} for none | 80 * @param message detail message to use or {@code null} for none |
70 * @since 1.6 | 81 * @since 1.6 |
71 */ | 82 */ |
72 public HttpResponseException(HttpResponse response, String message) { | 83 public HttpResponseException(HttpResponse response, String message) { |
73 super(message); | 84 super(message); |
74 statusCode = response.getStatusCode(); | 85 statusCode = response.getStatusCode(); |
75 statusMessage = response.getStatusMessage(); | 86 statusMessage = response.getStatusMessage(); |
76 headers = response.getHeaders(); | 87 headers = response.getHeaders(); |
77 this.response = response; | |
78 } | 88 } |
79 | 89 |
80 /** | 90 /** |
81 * Returns whether received a successful HTTP status code {@code >= 200 && < 3
00} (see | 91 * Returns whether received a successful HTTP status code {@code >= 200 && < 3
00} (see |
82 * {@link #getStatusCode()}). | 92 * {@link #getStatusCode()}). |
83 * | 93 * |
84 * <p> | 94 * <p> |
85 * Upgrade warning: Overriding this method is no longer supported, and will be
made final in | 95 * Upgrade warning: Overriding this method is no longer supported, and will be
made final in |
86 * 1.10. | 96 * 1.10. |
87 * </p> | 97 * </p> |
(...skipping 23 matching lines...) Expand all Loading... |
111 * Returns the HTTP status message or {@code null} for none. | 121 * Returns the HTTP status message or {@code null} for none. |
112 * | 122 * |
113 * @since 1.9 | 123 * @since 1.9 |
114 */ | 124 */ |
115 public final String getStatusMessage() { | 125 public final String getStatusMessage() { |
116 return statusMessage; | 126 return statusMessage; |
117 } | 127 } |
118 | 128 |
119 /** | 129 /** |
120 * Returns the HTTP response headers. | 130 * Returns the HTTP response headers. |
121 * | 131 * |
122 * @since 1.7 | 132 * @since 1.7 |
123 */ | 133 */ |
124 public HttpHeaders getHeaders() { | 134 public HttpHeaders getHeaders() { |
125 return headers; | 135 return headers; |
126 } | 136 } |
127 | 137 |
128 /** | 138 /** |
129 * Returns an exception message to use for the given HTTP response. | 139 * Returns an exception message to use for the given HTTP response. |
130 */ | 140 */ |
131 private static String computeMessageWithContent(HttpResponse response) { | 141 private static String computeMessageWithContent(HttpResponse response) { |
(...skipping 25 matching lines...) Expand all Loading... |
157 String statusMessage = response.getStatusMessage(); | 167 String statusMessage = response.getStatusMessage(); |
158 if (statusMessage != null) { | 168 if (statusMessage != null) { |
159 if (statusCode != 0) { | 169 if (statusCode != 0) { |
160 builder.append(' '); | 170 builder.append(' '); |
161 } | 171 } |
162 builder.append(statusMessage); | 172 builder.append(statusMessage); |
163 } | 173 } |
164 return builder; | 174 return builder; |
165 } | 175 } |
166 } | 176 } |
LEFT | RIGHT |