public class APIResponse extends Object implements IAPIResponse
Constructor and Description |
---|
APIResponse(org.apache.http.ProtocolVersion pv,
org.apache.http.StatusLine status,
List<org.apache.http.Header> headers)
Create a new Response instance.
|
Modifier and Type | Method and Description |
---|---|
static <T extends APIResponse> |
copyFrom(IAPIResponse that,
Class<T> type)
Clone an api response
|
int |
getContentLength()
Retrieve the content length
|
javax.json.JsonObject |
getJsonObject()
Retrieve the response as a parsed JsonObject
|
org.apache.http.ProtocolVersion |
getProtocolVersion()
Retrieve the protocol version
|
String |
getResponseCharsetName()
Retrieve the response content character set name
|
String |
getResponseContent()
Retrieve the response content
|
org.apache.http.StatusLine |
getStatusLine()
Retrieve the status line
|
List<org.apache.http.Header> |
headers()
Access the response headers list
|
boolean |
isFailure()
Find out if the last request was a failure
Code is 400-599
|
boolean |
isJson()
A crude way to see if a response might have json in it.
|
boolean |
isRequestFail()
Find out if the last request was a failure due to client input.
|
boolean |
isServerFailure()
Find out if the last request returned a 500 range error.
|
boolean |
isSuccess()
Find out if the last request was successful
|
void |
setContent(String content,
String charset)
Set the HTTP response content and character set.
|
public APIResponse(org.apache.http.ProtocolVersion pv, org.apache.http.StatusLine status, List<org.apache.http.Header> headers)
pv
- protocol versionstatus
- status lineheaders
- response headerspublic static <T extends APIResponse> T copyFrom(IAPIResponse that, Class<T> type) throws NoSuchMethodException, InstantiationException, InvocationTargetException, IllegalArgumentException, IllegalAccessException
T
- some class that extends APIResponsethat
- Some response to clonetype
- The classNoSuchMethodException
InstantiationException
InvocationTargetException
IllegalAccessException
IllegalArgumentException
public org.apache.http.ProtocolVersion getProtocolVersion()
getProtocolVersion
in interface IAPIResponse
public org.apache.http.StatusLine getStatusLine()
getStatusLine
in interface IAPIResponse
public List<org.apache.http.Header> headers()
headers
in interface IAPIResponse
public int getContentLength()
getContentLength
in interface IAPIResponse
public void setContent(String content, String charset)
setContent
in interface IAPIResponse
content
- Contentcharset
- character set namepublic String getResponseContent()
getResponseContent
in interface IAPIResponse
public String getResponseCharsetName()
getResponseCharsetName
in interface IAPIResponse
public javax.json.JsonObject getJsonObject() throws javax.json.JsonException, javax.json.stream.JsonParsingException
getJsonObject
in interface IAPIResponse
javax.json.JsonException
- if a JSON object cannot
be created due to i/o error (IOException would be
cause of JsonException)javax.json.stream.JsonParsingException
- if a JSON object cannot
be created due to incorrect representationpublic boolean isJson()
isJson
in interface IAPIResponse
public boolean isSuccess()
isSuccess
in interface IAPIResponse
public boolean isFailure()
isFailure
in interface IAPIResponse
public boolean isRequestFail()
isRequestFail
in interface IAPIResponse
public boolean isServerFailure()
isServerFailure
in interface IAPIResponse
Copyright © 2017. All rights reserved.