public interface HttpRequest extends Comparable<HttpRequest>
HttpRequest is basically a key-value Map values, that are
used to add Parameters to any HTTP request.
For a HTTP GET Request, the parameters are added to the url. For HTP POST, PUT, DELETE the parameters are written into the HTTP request body.
This class also contains a Map with HTTP Headers
getHttpHeaders() key-value information that are added to the HTTP
Request. A concrete scenario would be to set the content-type header
information for multipart etc.
Is essential important for the HttpExecutor that every
HttpRequestn overrides #equals(Object) and
#hashCode() to determine, if two HttpRequests do exactly the
same.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
HttpRequest.CanceledListener
Since a request can be canceled, we need a listener that get informed
when a
HttpRequest has been canceled. |
static interface |
HttpRequest.PriorityChangedListener
This is a simple listener that listen for priority changes
|
| Modifier and Type | Field and Description |
|---|---|
static int |
CACHE_ALLOW_STALE
Allow stale data to be returned from cache and to refresh data in background.
|
static int |
CACHE_FORCE
Set it if you explicity want to retrieve the desired data from
cache, ignoring the cache control.
|
static int |
CACHE_FROM_DISK
Allow to query the disk cache to retrieve the value from cache
|
static int |
CACHE_FROM_MEMORY
Allow to query the memory cache to retrieve the data
|
static int |
CACHE_OFFLINE_ALLOW_EXPIRED
If the users device is offline (has no avtive internet connection)
than the value can be retrieved from cache, even if its expired.
|
static int |
CACHE_TO_DISK
Write the fetched response value to the disk cache
|
static int |
CACHE_TO_MEMORY
Write the fetched response value to the memory cache
|
static String |
HTTP_METHOD_DELETE
The http method for an request is HTTP DELETE
|
static String |
HTTP_METHOD_GET
The http method for an request is HTTP GET
|
static String |
HTTP_METHOD_POST
The http method for an request is HTTP POST
|
static String |
HTTP_METHOD_PUT
The http method for an request is HTTP PUT
|
static int |
PRIORITY_HIGH
high priority
|
static int |
PRIORITY_HIGHEST
The highest priority
|
static int |
PRIORITY_LOW
low priority
|
static int |
PRIORITY_LOWEST
The lowest priority
|
static int |
PRIORITY_NORMAL
normal priority
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancel a
HttpRequest |
<T> void |
doAdditionalResponseProcessing(HttpResponse<T> response,
Cache<String,Object> cache)
Its possible to do additional response processing, for example for image
transformation, scaling etc. or data sorting / manipulating.
|
<T> CacheEntry<T> |
getCachedResultFor304() |
int |
getConnectingTimeout() |
long |
getCreationTimestamp()
The unix timestamp in UTC milisecnds, when this
HttpRequest has
been created |
Map<String,String> |
getHttpHeaders()
Get the http headers that are set for an
HttpRequest. |
String |
getHttpMethod()
Get the http method like GET, POST, PUT, DELETE.
|
String |
getOverrideResponseCacheControl() |
Object |
getOwner()
Get the owner
|
ParseCondition |
getParseCondition() |
Class<?> |
getParseIntoClass() |
int |
getParseIntoCollectionType()
get the collection type.
|
ParserWriter<?> |
getParserWriter()
Specify explicit which parser should be used for parsing the result of this request
|
int |
getPriority()
Get the priority
|
int |
getReadingResponseTimeout() |
String |
getResponseContentCharset() |
String |
getResponseContentType() |
String |
getUrl()
Get the complete url where this request is send to
|
String |
getUrlEncodingCharset()
Get the url encoding charset
|
boolean |
isAllowStaleData() |
boolean |
isCanceled()
If this request has been canceled (by calling
cancel() ) this
method will return true, otherwise false |
boolean |
isFollowRedirection() |
boolean |
isForceFromCache() |
boolean |
isOnOfflineAllowExpiredCacheValue() |
boolean |
isOnOfflineFromCache() |
boolean |
isReadDiskCache()
Is quering the disk cache enabled
|
boolean |
isReadMemoryCache()
Is quering the memory cache enabled?
|
boolean |
isWithoutCacheLookup() |
boolean |
isWriteDiskCache()
Is quering the disk cache enabled
|
boolean |
isWriteMemoryCache()
Is quering the memory cache enabled?
|
void |
putUrlParam(String key,
boolean value)
Add or override an existing url parameter
|
void |
putUrlParam(String key,
char value)
Add or override an existing url parameter
|
void |
putUrlParam(String key,
double value)
Add or override an existing url parameter
|
void |
putUrlParam(String key,
float value)
Add or override an existing url parameter
|
void |
putUrlParam(String key,
int value)
Add or override an existing url parameter
|
void |
putUrlParam(String key,
long value)
Add or override an existing url parameter
|
void |
putUrlParam(String key,
String value)
Add or override an existing url parameter
|
void |
setAllowStaleData(boolean allow)
Allow stale data to be returned from cache and to refresh data in background.
|
void |
setCachedResultFor304(CacheEntry<?> cachedResult)
If the cached result contains an ETag, than we need to revalidate it,
even if we have a cached result.
|
void |
setCanceledListener(HttpRequest.CanceledListener listener)
Set the cancel
GpsStatus.Listener, that will be informed when the
HttpRequest has been canceled. |
void |
setConnectingTimeout(int timeoutInMiliSeconds)
Sets the timeout of trying to connect the web service (in miliseconds).
|
void |
setFollowRedirection(boolean enabled)
Set it to true, if you automatically want to follow http redirections
|
HttpRequest |
setForceFromCache(boolean fromCache)
Set it to true, if you explicit want to retrieve the desired data from
cache, ignoring the cache control.
|
HttpRequest |
setHttpMethod(String httpMethod)
Sets the http method, that is used by
HttpKit to execute this
request. |
void |
setOnOfflineAllowExpiredCacheValue(boolean ignore)
Set it to true, if you want to get expired results from cache, when the
user is offline (has no active internet connection).
|
HttpRequest |
setOnOfflineFromCache(boolean offlineFromCache)
Set it to true, if you want try to get the data from the cache, if the
users device has currently no active internet connection
|
void |
setOverrideResponseCacheControl(String overriddenCacheControl)
Overrides the original cache control header of the response with this one.
|
void |
setOwner(Object owner)
Set the owner
|
void |
setParseCondition(ParseCondition condition)
Set a
ParseCondition. |
void |
setParseInto(Class<?> clazz)
Set the
Class to where the result should be parsed. |
void |
setParseInto(Class<?> clazz,
int collectionType)
Specfy here the class where to parse and set the collection type.
|
void |
setPriority(int priority)
HttpRequest are scheduled by an HttpExecutor. |
void |
setPriorityChangedListener(HttpRequest.PriorityChangedListener listener)
Set the
HttpRequest.PriorityChangedListener, that will be informed, when the
HttpRequest changes his priority. |
void |
setReadDiskCache(boolean enabled)
Should the disk cache be queried to retrieve a cached value
|
void |
setReadingResponseTimeout(int timeoutInMiliSeconds)
Set the timeout of trying to read data from the web service (as answer /
response of an request).
|
void |
setReadMemoryCache(boolean enabled)
Should the memory cache be queried to retrieve a cached value
|
void |
setResponseContentCharset(String charset)
If you work with an web service that does not deliver the content type
charset in the http header, than you can set it manually with this
method.
|
void |
setResponseContentType(String mimeType)
If you work with an web service that does not deliver the content type
(mime type) of the result, you can set it manually, what mime type the
response is.
|
HttpRequest |
setUrl(String url)
Set the url
|
void |
setUrlEncodingCharset(String charset)
Set the url encoding charset, used with
URLEncoder to url encode
parameter key and value |
HttpRequest |
setWithoutCacheLookup(boolean withoutCache)
Set this to true, if you want explicit to execute this http request,
without quering the cache.
|
void |
setWriteDiskCache(boolean enabled)
Should the disk cache be queried to retrieve a cached value
|
void |
setWriteMemoryCache(boolean enabled)
Should the memory cache be queried to retrieve a cached value
|
compareTostatic final String HTTP_METHOD_GET
static final String HTTP_METHOD_POST
static final String HTTP_METHOD_PUT
static final String HTTP_METHOD_DELETE
static final int PRIORITY_LOWEST
static final int PRIORITY_LOW
static final int PRIORITY_NORMAL
static final int PRIORITY_HIGH
static final int PRIORITY_HIGHEST
static final int CACHE_FROM_MEMORY
static final int CACHE_FROM_DISK
static final int CACHE_TO_MEMORY
static final int CACHE_TO_DISK
static final int CACHE_OFFLINE_ALLOW_EXPIRED
static final int CACHE_FORCE
static final int CACHE_ALLOW_STALE
String getUrl()
HttpRequest setUrl(String url)
String getHttpMethod()
ParserWriter<?> getParserWriter()
HttpRequest setHttpMethod(String httpMethod)
HttpKit to execute this
request. It should use the following constants:
Map<String,String> getHttpHeaders()
HttpRequest. The only
http header field you don't have to care about it, is the Http content
length and the cache control. This is http header fields are generated by
the HttpKit.HttpRequest setForceFromCache(boolean fromCache)
Example: Lets assume we have data in the cache, that has been retrieved
previously from the web server, with a last-modified field or an ETag. If
setForceFromCache(boolean) is set to true, the HttpKit
returns automatically the cached data, instead of contacting the web
server and query for last-modification or ETag changes.
The default value is false. This value has an higher priority as
setWithoutCacheLookup(boolean).
boolean isForceFromCache()
setForceFromCache(boolean)HttpRequest setWithoutCacheLookup(boolean withoutCache)
setForceFromCache(boolean) to true, the
setForceFromCache(boolean) value has the higher priority. So
withoutCache = true and firstFromCache = true will cause to execute this
request by trying to retrieve a value from cache.
The default value is false
boolean isWithoutCacheLookup()
setWithoutCacheLookup(boolean)void setAllowStaleData(boolean allow)
boolean isAllowStaleData()
setAllowStaleData(boolean)HttpRequest setOnOfflineFromCache(boolean offlineFromCache)
boolean isOnOfflineFromCache()
setOnOfflineFromCache(boolean)void setResponseContentType(String mimeType)
MimeTypeString getResponseContentType()
setResponseContentType(String)void setResponseContentCharset(String charset)
String getResponseContentCharset()
setResponseContentCharset(String)void setOnOfflineAllowExpiredCacheValue(boolean ignore)
ignore - true, if you want to allow on offline expired values from
cacheboolean isOnOfflineAllowExpiredCacheValue()
void setConnectingTimeout(int timeoutInMiliSeconds)
timeoutInMiliSeconds - in milisecondsint getConnectingTimeout()
setConnectingTimeout(int)void setReadingResponseTimeout(int timeoutInMiliSeconds)
int getReadingResponseTimeout()
setReadingResponseTimeout(int)void setPriority(int priority)
HttpRequest are scheduled by an HttpExecutor. The order
that the request are scheduled depends on the priority, which is set with
this method, and the creation timestamp (getCreationTimestamp()
). Use the predefined constants:
priority - The priority. Use one of the priority listed aboveint getPriority()
setPriority(int)long getCreationTimestamp()
HttpRequest has
been createdvoid setPriorityChangedListener(HttpRequest.PriorityChangedListener listener)
HttpRequest.PriorityChangedListener, that will be informed, when the
HttpRequest changes his priority. The HttpExecutor is
normally a HttpRequest.PriorityChangedListener and will be set himself as
HttpRequest.PriorityChangedListener when the HttpRequest has been
passed to the HttpExecutor and deregister after the
HttpRequest has been executed successful and a response / result
can be delivered.setPriority(int)void cancel()
HttpRequestvoid setCanceledListener(HttpRequest.CanceledListener listener)
GpsStatus.Listener, that will be informed when the
HttpRequest has been canceled. The HttpExecutor is
normally a HttpRequest.CanceledListener and will be set himself as a
HttpRequest.CanceledListener when the HttpRequest has been passed to
the HttpExecutor and deregister himself, after the
HttpRequest has been executed successful and a response / result
can be delivered.boolean isCanceled()
cancel() ) this
method will return true, otherwise falsevoid setFollowRedirection(boolean enabled)
boolean isFollowRedirection()
setFollowRedirection(boolean)void setCachedResultFor304(CacheEntry<?> cachedResult)
<T> CacheEntry<T> getCachedResultFor304()
getCachedResultFor304()void setOwner(Object owner)
Object getOwner()
<T> void doAdditionalResponseProcessing(HttpResponse<T> response, Cache<String,Object> cache)
This method gets called:
response - The response, that contains the data retrieved from the web
service or file cache. Manipulate this response object.cache - The cache used internally from the HttpKit. You should
not use this, because the response itself will be cached
automatically (if has cache flags) along the HttpKit
workflow, but in some special cases you may will override
other cache entries. Therefore the cache will be passed here.
Be careful when you do so!void setParseCondition(ParseCondition condition)
ParseCondition. If no ParseCondition is set (parse
condition == null), then the http response will be parsed. Otherwise the
http response will only be parsed, if the parse condition is fullfilled.
Otherwise the response will not be parsedParseCondition getParseCondition()
setParseCondition(ParseCondition)void setParseInto(Class<?> clazz)
Class to where the result should be parsed. This is
typically used for json or xml parsing.void setParseInto(Class<?> clazz, int collectionType)
ParserWriter.COLLECTION_TYPE_LIST etc. The internal default value
is ParserWriter.COLLECTION_TYPE_NONE. The default value will be
used if not set with this flagClass<?> getParseIntoClass()
setParseInto(Class)int getParseIntoCollectionType()
setParseInto(Class, int)void setReadMemoryCache(boolean enabled)
boolean isReadMemoryCache()
void setReadDiskCache(boolean enabled)
boolean isReadDiskCache()
void setWriteMemoryCache(boolean enabled)
boolean isWriteMemoryCache()
void setWriteDiskCache(boolean enabled)
boolean isWriteDiskCache()
void setUrlEncodingCharset(String charset)
URLEncoder to url encode
parameter key and valueString getUrlEncodingCharset()
void putUrlParam(String key, int value)
void putUrlParam(String key, long value)
void putUrlParam(String key, boolean value)
void putUrlParam(String key, float value)
void putUrlParam(String key, double value)
void putUrlParam(String key, char value)
void setOverrideResponseCacheControl(String overriddenCacheControl)
overriddenCacheControl - the desired cache controlString getOverrideResponseCacheControl()
setOverrideResponseCacheControl(String)Copyright © 2015 Hannes Dorfmann. All rights reserved.