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 /**
14 * @return status code of the request.
15 */
16 int getStatusCode();
17
18 /**
19 * @return the response body of the request.
20 * @throws ResponseException If the response cannot be retrieved
21 */
22 String getResponseBodyAsString() throws ResponseException;
23
24 /**
25 * @return the response body of the request.
26 * @throws ResponseException If the response cannot be retrieved
27 */
28 InputStream getResponseBodyAsStream() throws ResponseException;
29
30 /**
31 * Unmarshall the response body as the specified type
32 *
33 * @param entityClass the type of the response
34 * @return the unmarshalled object
35 * @throws ResponseException if there was difficulty reading the response or unmarshalling the object
36 */
37 <T> T getEntity(Class<T> entityClass) throws ResponseException;
38
39 /**
40 * @return status test of the response
41 */
42 String getStatusText();
43
44 /**
45 * @return true if network returned a status code in the 200 range or 300 range
46 */
47 boolean isSuccessful();
48
49 /**
50 * Get's the header by the given name
51 *
52 * @param name The name of the header
53 * @return The value of the header. This will include all values, comma
54 * separated, if multiple header fields with the given name were specified,
55 * as per RFC2616. When the specified header key is not present,
56 * {@code null} is returned.
57 */
58 String getHeader(String name);
59
60 /**
61 * Get a map of all the headers
62 *
63 * @return A map of header names to header values. The header values will include all values, comma seperated, if
64 * multiple header fields with the given name were specified, as per RFC2616.
65 */
66 Map<String, String> getHeaders();
67 }