T
- The type of parsed response this request expects.public abstract class Request<T> extends java.lang.Object implements java.lang.Comparable<Request<T>>
Modifier and Type | Class and Description |
---|---|
static interface |
Request.Method
Supported request methods.
|
static class |
Request.Priority
Priority values.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DEFAULT_PARAMS_ENCODING
Default encoding for POST or PUT parameters.
|
private Cache.Entry |
mCacheEntry
When a request can be retrieved from cache but must be refreshed from
the network, the cache entry will be stored here so that in the event of
a "Not Modified" response, we can be sure it hasn't been evicted from cache.
|
private boolean |
mCanceled
Whether or not this request has been canceled.
|
private int |
mDefaultTrafficStatsTag
Default tag for
android.net.TrafficStats . |
private Response.ErrorListener |
mErrorListener
Listener interface for errors.
|
private VolleyLog.MarkerLog |
mEventLog
An event log tracing the lifetime of this request; for debugging.
|
private int |
mMethod
Request method of this request.
|
private long |
mRequestBirthTime |
private RequestQueue |
mRequestQueue
The request queue this request is associated with.
|
private boolean |
mResponseDelivered
Whether or not a response has been delivered for this request yet.
|
private RetryPolicy |
mRetryPolicy
The retry policy for this request.
|
private java.lang.Integer |
mSequence
Sequence number of this request, used to enforce FIFO ordering.
|
private boolean |
mShouldCache
Whether or not responses to this request should be cached.
|
private java.lang.Object |
mTag
An opaque token tagging this request; used for bulk cancellation.
|
private java.lang.String |
mUrl
URL of this request.
|
private static long |
SLOW_REQUEST_THRESHOLD_MS
Threshold at which we should log the request (even when debug logging is not enabled).
|
Constructor and Description |
---|
Request(int method,
java.lang.String url,
Response.ErrorListener listener)
Creates a new request with the given method (one of the values from
Request.Method ),
URL, and error listener. |
Request(java.lang.String url,
Response.ErrorListener listener)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
addMarker(java.lang.String tag)
Adds an event to this request's event log; for debugging.
|
void |
cancel()
Mark this request as canceled.
|
int |
compareTo(Request<T> other)
Our comparator sorts from high to low priority, and secondarily by
sequence number to provide FIFO ordering.
|
void |
deliverError(VolleyError error)
Delivers error message to the ErrorListener that the Request was
initialized with.
|
protected abstract void |
deliverResponse(T response)
Subclasses must implement this to perform delivery of the parsed
response to their listeners.
|
private byte[] |
encodeParameters(java.util.Map<java.lang.String,java.lang.String> params,
java.lang.String paramsEncoding)
Converts
params into an application/x-www-form-urlencoded encoded string. |
private static int |
findDefaultTrafficStatsTag(java.lang.String url) |
(package private) void |
finish(java.lang.String tag)
Notifies the request queue that this request has finished (successfully or with error).
|
byte[] |
getBody()
Returns the raw POST or PUT body to be sent.
|
java.lang.String |
getBodyContentType() |
Cache.Entry |
getCacheEntry()
Returns the annotated cache entry, or null if there isn't one.
|
java.lang.String |
getCacheKey()
Returns the cache key for this request.
|
java.util.Map<java.lang.String,java.lang.String> |
getHeaders()
Returns a list of extra HTTP headers to go along with this request.
|
int |
getMethod()
Return the method for this request.
|
protected java.util.Map<java.lang.String,java.lang.String> |
getParams()
Returns a Map of parameters to be used for a POST or PUT request.
|
protected java.lang.String |
getParamsEncoding()
Returns which encoding should be used when converting POST or PUT parameters returned by
getParams() into a raw POST or PUT body. |
byte[] |
getPostBody()
Deprecated.
Use
getBody() instead. |
java.lang.String |
getPostBodyContentType()
Deprecated.
Use
getBodyContentType() instead. |
protected java.util.Map<java.lang.String,java.lang.String> |
getPostParams()
Deprecated.
Use
getParams() instead. |
protected java.lang.String |
getPostParamsEncoding()
Deprecated.
Use
getParamsEncoding() instead. |
Request.Priority |
getPriority()
Returns the
Request.Priority of this request; Request.Priority.NORMAL by default. |
RetryPolicy |
getRetryPolicy()
Returns the retry policy that should be used for this request.
|
int |
getSequence()
Returns the sequence number of this request.
|
java.lang.Object |
getTag()
Returns this request's tag.
|
int |
getTimeoutMs()
Returns the socket timeout in milliseconds per retry attempt.
|
int |
getTrafficStatsTag() |
java.lang.String |
getUrl()
Returns the URL of this request.
|
boolean |
hasHadResponseDelivered()
Returns true if this request has had a response delivered for it.
|
boolean |
isCanceled()
Returns true if this request has been canceled.
|
void |
markDelivered()
Mark this request as having a response delivered on it.
|
protected VolleyError |
parseNetworkError(VolleyError volleyError)
Subclasses can override this method to parse 'networkError' and return a more specific error.
|
protected abstract Response<T> |
parseNetworkResponse(NetworkResponse response)
Subclasses must implement this to parse the raw network response
and return an appropriate response type.
|
Request<?> |
setCacheEntry(Cache.Entry entry)
Annotates this request with an entry retrieved for it from cache.
|
Request<?> |
setRequestQueue(RequestQueue requestQueue)
Associates this request with the given queue.
|
Request<?> |
setRetryPolicy(RetryPolicy retryPolicy)
Sets the retry policy for this request.
|
Request<?> |
setSequence(int sequence)
Sets the sequence number of this request.
|
Request<?> |
setShouldCache(boolean shouldCache)
Set whether or not responses to this request should be cached.
|
Request<?> |
setTag(java.lang.Object tag)
Set a tag on this request.
|
boolean |
shouldCache()
Returns true if responses to this request should be cached.
|
java.lang.String |
toString() |
private static final java.lang.String DEFAULT_PARAMS_ENCODING
getParamsEncoding()
.private final VolleyLog.MarkerLog mEventLog
private final int mMethod
private final java.lang.String mUrl
private final int mDefaultTrafficStatsTag
android.net.TrafficStats
.private final Response.ErrorListener mErrorListener
private java.lang.Integer mSequence
private RequestQueue mRequestQueue
private boolean mShouldCache
private boolean mCanceled
private boolean mResponseDelivered
private long mRequestBirthTime
private static final long SLOW_REQUEST_THRESHOLD_MS
private RetryPolicy mRetryPolicy
private Cache.Entry mCacheEntry
private java.lang.Object mTag
@Deprecated public Request(java.lang.String url, Response.ErrorListener listener)
Request(int, String, com.android.volley.Response.ErrorListener)
.public Request(int method, java.lang.String url, Response.ErrorListener listener)
Request.Method
),
URL, and error listener. Note that the normal response listener is not provided here as
delivery of responses is provided by subclasses, who have a better idea of how to deliver
an already-parsed response.public int getMethod()
Request.Method
.public Request<?> setTag(java.lang.Object tag)
RequestQueue.cancelAll(Object)
.public java.lang.Object getTag()
setTag(Object)
public int getTrafficStatsTag()
android.net.TrafficStats#setThreadStatsTag(int)
private static int findDefaultTrafficStatsTag(java.lang.String url)
public Request<?> setRetryPolicy(RetryPolicy retryPolicy)
public void addMarker(java.lang.String tag)
void finish(java.lang.String tag)
Also dumps all events from this request's event log; for debugging.
public Request<?> setRequestQueue(RequestQueue requestQueue)
public final Request<?> setSequence(int sequence)
RequestQueue
.public final int getSequence()
public java.lang.String getUrl()
public java.lang.String getCacheKey()
public Request<?> setCacheEntry(Cache.Entry entry)
public Cache.Entry getCacheEntry()
public void cancel()
public boolean isCanceled()
public java.util.Map<java.lang.String,java.lang.String> getHeaders() throws AuthFailureError
AuthFailureError
as authentication may be required to
provide these values.AuthFailureError
- In the event of auth failure@Deprecated protected java.util.Map<java.lang.String,java.lang.String> getPostParams() throws AuthFailureError
getParams()
instead.AuthFailureError
as
authentication may be required to provide these values.
Note that only one of getPostParams() and getPostBody() can return a non-null value.
AuthFailureError
- In the event of auth failure@Deprecated protected java.lang.String getPostParamsEncoding()
getParamsEncoding()
instead.getPostParams()
into a raw POST body.
This controls both encodings:
@Deprecated public java.lang.String getPostBodyContentType()
getBodyContentType()
instead.@Deprecated public byte[] getPostBody() throws AuthFailureError
getBody()
instead.AuthFailureError
- In the event of auth failureprotected java.util.Map<java.lang.String,java.lang.String> getParams() throws AuthFailureError
AuthFailureError
as authentication may be required to provide these values.
Note that you can directly override getBody()
for custom data.
AuthFailureError
- in the event of auth failureprotected java.lang.String getParamsEncoding()
getParams()
into a raw POST or PUT body.
This controls both encodings:
public java.lang.String getBodyContentType()
public byte[] getBody() throws AuthFailureError
AuthFailureError
- in the event of auth failureprivate byte[] encodeParameters(java.util.Map<java.lang.String,java.lang.String> params, java.lang.String paramsEncoding)
params
into an application/x-www-form-urlencoded encoded string.public final Request<?> setShouldCache(boolean shouldCache)
public final boolean shouldCache()
public Request.Priority getPriority()
Request.Priority
of this request; Request.Priority.NORMAL
by default.public final int getTimeoutMs()
TimeoutError
error.public RetryPolicy getRetryPolicy()
public void markDelivered()
public boolean hasHadResponseDelivered()
protected abstract Response<T> parseNetworkResponse(NetworkResponse response)
response
- Response from the networkprotected VolleyError parseNetworkError(VolleyError volleyError)
The default implementation just returns the passed 'networkError'.
volleyError
- the error retrieved from the networkprotected abstract void deliverResponse(T response)
response
- The parsed response returned by
parseNetworkResponse(NetworkResponse)
public void deliverError(VolleyError error)
error
- Error detailspublic int compareTo(Request<T> other)
public java.lang.String toString()
toString
in class java.lang.Object