T - The object that data from the server should be parsed into.R - The child class extending this object.public abstract class BoxRequest<T extends BoxObject,R extends BoxRequest<T,R>>
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
BoxRequest.BoxRequestHandler<R extends BoxRequest>
This class handles parsing the response from Box's server into the correct data object if successful or throw the appropriate exception if not.
|
static class |
BoxRequest.ContentTypes
The different content types used to encode data sent to the Box Server.
|
static class |
BoxRequest.Methods
The different type of methods to communicate with the Box server.
|
static class |
BoxRequest.TLSSSLSocketFactory |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
JSON_OBJECT |
protected java.util.LinkedHashMap<java.lang.String,java.lang.Object> |
mBodyMap |
protected BoxRequest.ContentTypes |
mContentType |
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> |
mHeaderMap |
protected ProgressListener |
mListener |
protected java.util.HashMap<java.lang.String,java.lang.String> |
mQueryMap |
protected BoxRequest.Methods |
mRequestMethod |
protected java.lang.String |
mRequestUrlString |
protected boolean |
mRequiresSocket |
protected BoxSession |
mSession |
protected int |
mTimeout |
| Modifier | Constructor and Description |
|---|---|
protected |
BoxRequest(BoxRequest request)
Helper constructor used to copy the fields of one BoxRequest to another.
|
|
BoxRequest(java.lang.Class<T> clazz,
java.lang.String requestUrl,
BoxSession session)
Constructs a new BoxRequest.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.net.URL |
buildUrl() |
protected void |
createHeaderMap() |
protected com.box.androidsdk.content.requests.BoxHttpRequest |
createHttpRequest() |
protected java.lang.String |
createQuery(java.util.Map<java.lang.String,java.lang.String> map) |
boolean |
equals(java.lang.Object o) |
protected java.lang.String |
getIfMatchEtag() |
protected java.lang.String |
getIfNoneMatchEtag() |
BoxRequest.BoxRequestHandler |
getRequestHandler()
Gets the request handler.
|
BoxSession |
getSession()
Gets session used to authenticate this request.
|
protected java.net.Socket |
getSocket()
This method requires mRequiresSocket to be set to true before connecting.
|
java.lang.String |
getStringBody()
Gets the string body for the request.
|
protected T |
handleSendForCachedResult()
Default implementation for sending a request.
|
protected <R extends BoxRequest & BoxCacheableRequest> |
handleToTaskForCachedResult()
Default implementation for getting a task to execute the request.
|
protected void |
handleUpdateCache(BoxResponse<T> response)
If available, makes a call to update the cache with the provided result
|
int |
hashCode() |
protected void |
importRequestContentMapsFrom(BoxRequest source)
Copies data from query and body maps into the current request.
|
protected void |
logDebug(BoxHttpResponse response) |
protected void |
logRequest() |
protected T |
onSend()
Synchronously make the request to Box and handle the response appropriately.
|
protected void |
onSendCompleted(BoxResponse<T> response)
Post action that will be performed after a successful send occurs.
|
protected void |
parseHashMapEntry(com.eclipsesource.json.JsonObject jsonBody,
java.util.Map.Entry<java.lang.String,java.lang.Object> entry) |
protected com.eclipsesource.json.JsonValue |
parseJsonObject(java.lang.Object obj) |
T |
send()
Synchronously make the request to Box and handle the response appropriately.
|
protected BoxHttpResponse |
sendRequest(com.box.androidsdk.content.requests.BoxHttpRequest request,
java.net.HttpURLConnection connection) |
protected void |
setBody(com.box.androidsdk.content.requests.BoxHttpRequest request) |
R |
setContentType(BoxRequest.ContentTypes contentType)
Set the content type encoding.
|
protected void |
setHeaders(com.box.androidsdk.content.requests.BoxHttpRequest request) |
protected R |
setIfMatchEtag(java.lang.String etag) |
protected R |
setIfNoneMatchEtag(java.lang.String etag) |
R |
setRequestHandler(BoxRequest.BoxRequestHandler handler)
Sets a request handler to handle sending the request.
|
R |
setTimeOut(int timeOut)
Set the time out for this request in milliseconds via the method in HttpUrlConnection.
|
BoxFutureTask<T> |
toTask()
Creates a BoxFutureTask to make the request asynchronously.
|
public static final java.lang.String JSON_OBJECT
protected java.lang.String mRequestUrlString
protected BoxRequest.Methods mRequestMethod
protected java.util.HashMap<java.lang.String,java.lang.String> mQueryMap
protected java.util.LinkedHashMap<java.lang.String,java.lang.Object> mBodyMap
protected java.util.LinkedHashMap<java.lang.String,java.lang.String> mHeaderMap
protected BoxRequest.ContentTypes mContentType
protected BoxSession mSession
protected transient ProgressListener mListener
protected int mTimeout
protected boolean mRequiresSocket
public BoxRequest(java.lang.Class<T> clazz, java.lang.String requestUrl, BoxSession session)
clazz - The class of the object that should be returned, the class specified by the child in T.requestUrl - the url to use to connect to Box.session - the session used to authenticate the given request.protected BoxRequest(BoxRequest request)
request - the request to copy data from.protected void importRequestContentMapsFrom(BoxRequest source)
source - the request to copy data from.public BoxSession getSession()
public BoxRequest.BoxRequestHandler getRequestHandler()
public R setRequestHandler(BoxRequest.BoxRequestHandler handler)
handler - the request handler to use for handling given request.public R setContentType(BoxRequest.ContentTypes contentType)
contentType - sets the encoding type of this request.public R setTimeOut(int timeOut)
Warning: if the hostname resolves to multiple IP addresses, this client will try each in RFC 3484 order. If connecting to each of these addresses fails, multiple timeouts will elapse before the connect attempt throws an exception. Host names that support both IPv6 and IPv4 always have at least 2 IP addresses.
timeOut - time in milliseconds to wait for request to finish.public final T send() throws BoxException
BoxException - thrown if there was a problem with handling the request.protected T onSend() throws BoxException
BoxException - thrown if there was a problem with handling the request.protected void onSendCompleted(BoxResponse<T> response) throws BoxException
response - response of the BoxRequestBoxException - thrown if there was a problem with handling the request.public BoxFutureTask<T> toTask()
protected com.box.androidsdk.content.requests.BoxHttpRequest createHttpRequest()
throws java.io.IOException,
BoxException
java.io.IOExceptionBoxExceptionprotected BoxHttpResponse sendRequest(com.box.androidsdk.content.requests.BoxHttpRequest request, java.net.HttpURLConnection connection) throws java.io.IOException, BoxException
java.io.IOExceptionBoxExceptionprotected java.net.URL buildUrl()
throws java.net.MalformedURLException,
java.io.UnsupportedEncodingException
java.net.MalformedURLExceptionjava.io.UnsupportedEncodingExceptionprotected java.lang.String createQuery(java.util.Map<java.lang.String,java.lang.String> map)
throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingExceptionprotected void createHeaderMap()
protected void setHeaders(com.box.androidsdk.content.requests.BoxHttpRequest request)
protected R setIfMatchEtag(java.lang.String etag)
protected java.lang.String getIfMatchEtag()
protected R setIfNoneMatchEtag(java.lang.String etag)
protected java.lang.String getIfNoneMatchEtag()
protected void setBody(com.box.androidsdk.content.requests.BoxHttpRequest request)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getStringBody()
throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException - thrown if there was a problem with the encoding of the body.protected void parseHashMapEntry(com.eclipsesource.json.JsonObject jsonBody,
java.util.Map.Entry<java.lang.String,java.lang.Object> entry)
protected com.eclipsesource.json.JsonValue parseJsonObject(java.lang.Object obj)
protected void logDebug(BoxHttpResponse response) throws BoxException
BoxExceptionprotected void logRequest()
protected T handleSendForCachedResult() throws BoxException
BoxException - Exception from sending the request. A BoxException.CacheImplementationNotFound
will be thrown if a cache implementation is not provided in BoxConfig and fromCache is trueprotected <R extends BoxRequest & BoxCacheableRequest> BoxFutureTask<T> handleToTaskForCachedResult() throws BoxException
R - A BoxRequest that implements BoxCaceableRequestBoxException - thrown if there is no cache implementation set in BoxConfig.protected void handleUpdateCache(BoxResponse<T> response) throws BoxException
response - the new result to update the cache withBoxException - thrown if there was an issue updating cache for given response.public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectprotected java.net.Socket getSocket()