View Javadoc

1   package com.atlassian.httpclient.api;
2   
3   import java.io.InputStream;
4   import java.util.Map;
5   
6   /**
7    * Represents the result of an HTTP request.
8    */
9   public interface Response extends Message {
10      /**
11       * Gets the status code of the response.
12       *
13       * @return The status code
14       */
15      int getStatusCode();
16  
17      /**
18       * Gets the status text of the response.
19       *
20       * @return The status text
21       */
22      String getStatusText();
23  
24      /**
25       * Indicates whether or not this response's status code is categorized as "Informational" (1xx).
26       *
27       * @return True if status code gte 100 and lt 200
28       */
29      boolean isInformational();
30  
31      /**
32       * Indicates whether or not this response's status code is categorized as "Successful" (2xx).
33       *
34       * @return True if status code gte 200 and lt 300
35       */
36      boolean isSuccessful();
37  
38      /**
39       * Indicates whether or not this response's status code is "OK".
40       *
41       * @return True if status code is 200
42       */
43      boolean isOk();
44  
45      /**
46       * Indicates whether or not this response's status code is "Created".
47       *
48       * @return True if status code is 201
49       */
50      boolean isCreated();
51  
52      /**
53       * Indicates whether or not this response's status code is "No Content".
54       *
55       * @return True if status code is 204
56       */
57      boolean isNoContent();
58  
59      /**
60       * Indicates whether or not this response's status code is categorized as "Redirection" (3xx).
61       *
62       * @return True if status code gte 300 and lt 400
63       */
64      boolean isRedirection();
65  
66      /**
67       * Indicates whether or not this response's status code is "See Other".
68       *
69       * @return True if status code is 303
70       */
71      boolean isSeeOther();
72  
73      /**
74       * Indicates whether or not this response's status code is "Not Modified".
75       *
76       * @return True if status code is 304
77       */
78      boolean isNotModified();
79  
80      /**
81       * Indicates whether or not this response's status code is categorized as "Client Error" (4xx).
82       *
83       * @return True if status code gte 400 and lt 500
84       */
85      boolean isClientError();
86  
87      /**
88       * Indicates whether or not this response's status code is "Bad Request".
89       *
90       * @return True if status code is 400
91       */
92      boolean isBadRequest();
93  
94      /**
95       * Indicates whether or not this response's status code is "Unauthorized".
96       *
97       * @return True if status code is 401
98       */
99      boolean isUnauthorized();
100 
101     /**
102      * Indicates whether or not this response's status code is "Forbidden".
103      *
104      * @return True if status code is 403
105      */
106     boolean isForbidden();
107 
108     /**
109      * Indicates whether or not this response's status code is "Not Found".
110      *
111      * @return True if status code is 404
112      */
113     boolean isNotFound();
114 
115     /**
116      * Indicates whether or not this response's status code is "Conflict".
117      *
118      * @return True if status code is 409
119      */
120     boolean isConflict();
121 
122     /**
123      * Indicates whether or not this response's status code is categorized as "Server Error" (5xx).
124      *
125      * @return True if status code gte 500 and lt 600
126      */
127     boolean isServerError();
128 
129     /**
130      * Indicates whether or not this response's status code is "Internal Server Error".
131      *
132      * @return True if status code is 500
133      */
134     boolean isInternalServerError();
135 
136     /**
137      * Indicates whether or not this response's status code is "Service Unavailable".
138      *
139      * @return True if status code is 503
140      */
141     boolean isServiceUnavailable();
142 
143     /**
144      * Indicates whether or not this response's status code is categorized as either "Client Error"
145      * or "Server Error".
146      *
147      * @return True if either of isClientError() or isServerError() is true
148      */
149     boolean isError();
150 
151     /**
152      * Indicates whether or not this response's status code is categorized as one of "Informational",
153      * "Redirection", "Client Error" or "Server Error".
154      *
155      * @return True if one of isInformational(), isRedirection() or isError() is true
156      */
157     boolean isNotSuccessful();
158 
159     interface Builder extends Common<Builder>, Buildable<Response> {
160         @Override
161         Builder setContentType(String contentType);
162 
163         @Override
164         Builder setContentCharset(String contentCharset);
165 
166         @Override
167         Builder setHeaders(Map<String, String> headers);
168 
169         @Override
170         Builder setHeader(String name, String value);
171 
172         @Override
173         Builder setEntity(String entity);
174 
175         @Override
176         Builder setEntityStream(InputStream entityStream, String encoding);
177 
178         @Override
179         Builder setEntityStream(InputStream entityStream);
180 
181         /**
182          * Sets the status text of the response.
183          *
184          * @param statusText The status text
185          * @return This object, for builder-style chaining
186          */
187         Builder setStatusText(String statusText);
188 
189         /**
190          * Sets the status code of the response.
191          *
192          * @param statusCode The status code
193          * @return This object, for builder-stye chaining
194          */
195         Builder setStatusCode(int statusCode);
196     }
197 }