public class Response extends Object
Modifier and Type | Field and Description |
---|---|
Object |
body |
protected HttpURLConnection |
connection |
String |
contentType |
Map<String,List<String>> |
headerFields |
IOException |
ioException |
protected Request |
request |
int |
responseCode |
String |
responseMessage |
URL |
url |
Constructor and Description |
---|
Response(Request request,
HttpURLConnection connection,
IOException ioe,
int milestoneCode)
Constructor when there was an IOException
|
Response(Request request,
HttpURLConnection connection,
Object body)
Constructor for a success
Reads various fields from the HttpURLConnection
|
Modifier and Type | Method and Description |
---|---|
static StringBuilder |
formatHeaders(Map<String,List<String>> headers)
Formats the HTTP headers nicely...
|
Object |
getBody()
The response data (generally taken from HttpURLConnection.getInputStream())
|
String |
getContentType()
Content-Type
|
Map<String,List<String>> |
getHeaderFields()
Return the Headers from the response
|
IOException |
getIOException()
If there was an IOException, return it here
|
String |
getRedirect() |
Request |
getRequest()
Get the request that triggered this response.
|
int |
getResponseCode()
Returns the positive HTTP status code,
or else one of Request.Milestone.gerErrorCode() (which are negative)
|
String |
getResponseMessage()
Message corresponding to the HTTP status code,
or else the message from the IOException
|
URL |
getURL()
The URL we talked to
|
int |
responseGroup()
Which "hundreds" the response was in, e.g.
|
void |
throwIOException()
If you like to throw the IOException
|
String |
toString()
Nicely formatted summary of the response...
|
boolean |
wasSuccessful() |
protected final Request request
protected final HttpURLConnection connection
public final String contentType
public final URL url
public final Object body
public final int responseCode
public final String responseMessage
public final IOException ioException
public Response(Request request, HttpURLConnection connection, Object body)
request
- the HTTP Request that initiated this responseconnection
- non-nullbody
- may be null (came from connection.getInputStream())public Response(Request request, HttpURLConnection connection, IOException ioe, int milestoneCode)
request
- the HTTP Request that initiated this responseconnection
- may be null if connection failed to open.ioe
- the IOException (non-null)milestoneCode
- small negative number taken from Request.Milestonepublic String getContentType()
URLConnection.getContentType()
public Map<String,List<String>> getHeaderFields()
URLConnection.getHeaderFields()
public int getResponseCode()
HttpURLConnection.getResponseCode()
,
Request.Milestone.errorCode()
public String getResponseMessage()
HttpURLConnection.getResponseMessage()
public Object getBody()
public URL getURL()
URLConnection.getURL()
public IOException getIOException()
public int responseGroup()
public String getRedirect()
public void throwIOException() throws IOException
IOException
public Request getRequest()
public boolean wasSuccessful()
public String toString()
public static StringBuilder formatHeaders(Map<String,List<String>> headers)
headers
-