public class BoxJSONRequest extends BoxAPIRequest
This request type extends BoxAPIRequest to provide additional functionality for handling JSON strings. It automatically sets the appropriate "Content-Type" HTTP headers and allows the JSON in the request to be logged.
BoxAPIRequest.RequestHeader
Modifier | Constructor and Description |
---|---|
|
BoxJSONRequest(BoxAPIConnection api,
URL url,
HttpMethod method)
Constructs an authenticated BoxJSONRequest using a provided BoxAPIConnection.
|
|
BoxJSONRequest(BoxAPIConnection api,
URL url,
String method)
Constructs an authenticated BoxJSONRequest using a provided BoxAPIConnection.
|
protected |
BoxJSONRequest(BoxAPIConnection api,
URL url,
String method,
String mediaType) |
|
BoxJSONRequest(URL url,
HttpMethod method)
Constructs an authenticated BoxJSONRequest.
|
Modifier and Type | Method and Description |
---|---|
protected String |
bodyToString()
Returns a String representation of this request's body used in
BoxAPIRequest.toString() . |
JsonObject |
getBodyAsJsonObject()
Gets the body of this request as a JsonObject.
|
JsonValue |
getBodyAsJsonValue()
Gets the body of this request as a
JsonValue . |
BoxJSONResponse |
send()
Sends this request and returns a BoxAPIResponse containing the server's response.
|
BoxJSONResponse |
send(ProgressListener listener)
Sends this request while monitoring its progress and returns a BoxAPIResponse containing the server's response.
|
void |
setBody(JsonObject body)
Sets the body of this request to a given JsonObject.
|
void |
setBody(String body)
Sets the body of this request to a given JSON string.
|
addHeader, getBody, getConnectTimeout, getMethod, getReadTimeout, getUrl, isRequestRetryable, isResponseRetryable, mediaType, resetBody, sendWithoutRetry, setBody, setBody, setConnectTimeout, setFollowRedirects, setReadTimeout, setUrl, shouldAuthenticate, toString, writeMethodWithBody
protected BoxJSONRequest(BoxAPIConnection api, URL url, String method, String mediaType)
public BoxJSONRequest(BoxAPIConnection api, URL url, String method)
api
- an API connection for authenticating the request.url
- the URL of the request.method
- the HTTP method of the request.public BoxJSONRequest(BoxAPIConnection api, URL url, HttpMethod method)
api
- an API connection for authenticating the request.url
- the URL of the request.method
- the HTTP method of the request.public BoxJSONRequest(URL url, HttpMethod method)
url
- the URL of the request.method
- the HTTP method of the request.public void setBody(String body)
setBody
in class BoxAPIRequest
body
- the JSON string to use as the body.public void setBody(JsonObject body)
body
- the JsonObject to use as the body.public JsonObject getBodyAsJsonObject()
public JsonValue getBodyAsJsonValue()
JsonValue
.public BoxJSONResponse send()
BoxAPIRequest
The type of the returned BoxAPIResponse will be based on the content type returned by the server, allowing it
to be cast to a more specific type. For example, if it's known that the API call will return a JSON response,
then it can be cast to a BoxJSONResponse
like so:
BoxJSONResponse response = (BoxJSONResponse) request.send();
If the server returns an error code or if a network error occurs, then the request will be automatically
retried. If the maximum number of retries is reached and an error still occurs, then a BoxAPIException
will be thrown.
See BoxAPIRequest.send()
for more information on sending requests.
send
in class BoxAPIRequest
BoxAPIResponse
containing the server's response.public BoxJSONResponse send(ProgressListener listener)
BoxAPIRequest
The type of the returned BoxAPIResponse will be based on the content type returned by the server, allowing it
to be cast to a more specific type. For example, if it's known that the API call will return a JSON response,
then it can be cast to a BoxJSONResponse
like so:
If the server returns an error code or if a network error occurs, then the request will be automatically
retried. If the maximum number of retries is reached and an error still occurs, then a BoxAPIException
will be thrown.
A ProgressListener is generally only useful when the size of the request is known beforehand. If the size is unknown, then the ProgressListener will be updated for each byte sent, but the total number of bytes will be reported as 0.
See BoxAPIRequest.send()
for more information on sending requests.
send
in class BoxAPIRequest
listener
- a listener for monitoring the progress of the request.BoxAPIResponse
containing the server's response.protected String bodyToString()
BoxAPIRequest
BoxAPIRequest.toString()
. This method returns
null by default.
A subclass may want override this method if the body can be converted to a String for logging or debugging purposes.
bodyToString
in class BoxAPIRequest