1 package com.atlassian.sal.api.net;
2
3 import java.io.InputStream;
4 import java.util.Map;
5
6 /**
7 * Represents the response when calling {@link Request#execute(ResponseHandler)}
8 *
9 * @since 2.0
10 */
11 public interface Response {
12 /**
13 * @return status code of the request.
14 */
15 int getStatusCode();
16
17 /**
18 * @return the response body of the request.
19 * @throws ResponseException If the response cannot be retrieved
20 */
21 String getResponseBodyAsString() throws ResponseException;
22
23 /**
24 * @return the response body of the request.
25 * @throws ResponseException If the response cannot be retrieved
26 */
27 InputStream getResponseBodyAsStream() throws ResponseException;
28
29 /**
30 * Unmarshall the response body as the specified type
31 *
32 * @param entityClass the type of the response
33 * @return the unmarshalled object
34 * @throws ResponseException if there was difficulty reading the response or unmarshalling the object
35 */
36 <T> T getEntity(Class<T> entityClass) throws ResponseException;
37
38 /**
39 * @return status test of the response
40 */
41 String getStatusText();
42
43 /**
44 * @return true if network returned a status code in the 200 range or 300 range
45 */
46 boolean isSuccessful();
47
48 /**
49 * Get's the header by the given name
50 *
51 * @param name The name of the header
52 * @return The value of the header. This will include all values, comma
53 * separated, if multiple header fields with the given name were specified,
54 * as per RFC2616. When the specified header key is not present,
55 * {@code null} is returned.
56 */
57 String getHeader(String name);
58
59 /**
60 * Get a map of all the headers
61 *
62 * @return A map of header names to header values. The header values will include all values, comma seperated, if
63 * multiple header fields with the given name were specified, as per RFC2616.
64 */
65 Map<String, String> getHeaders();
66 }