public abstract class AbstractHttpRequest extends Object implements HttpRequest
HttpRequest. Basically it
only provides simple config storing like boolean values for caching and urlHttpRequest.CanceledListener, HttpRequest.PriorityChangedListener| Modifier and Type | Field and Description |
|---|---|
protected String |
url |
protected Map<String,String> |
urlParameters
The map of url parameters
|
CACHE_ALLOW_STALE, CACHE_FORCE, CACHE_FROM_DISK, CACHE_FROM_MEMORY, CACHE_OFFLINE_ALLOW_EXPIRED, CACHE_TO_DISK, CACHE_TO_MEMORY, HTTP_METHOD_DELETE, HTTP_METHOD_GET, HTTP_METHOD_POST, HTTP_METHOD_PUT, PRIORITY_HIGH, PRIORITY_HIGHEST, PRIORITY_LOW, PRIORITY_LOWEST, PRIORITY_NORMAL| Constructor and Description |
|---|
AbstractHttpRequest() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancel a
HttpRequest |
int |
compareTo(HttpRequest other) |
<T> void |
doAdditionalResponseProcessing(HttpResponse<T> response,
Cache<String,Object> object)
Its possible to do additional response processing, for example for image
transformation, scaling etc. or data sorting / manipulating.
|
boolean |
equals(Object obj) |
<T> CacheEntry<T> |
getCachedResultFor304() |
int |
getConnectingTimeout()
setConnectingTimeoutsetConnectingTimeout(int)
|
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
|
protected String |
getUrlParamsString()
Get the url parameters as string with "&" concatenated between each
parameter.
|
int |
hashCode() |
boolean |
isAllowStaleData() |
boolean |
isCanceled()
If this request has been canceled (by calling
HttpRequest.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
|
protected String |
putUrlParamAsString(String key,
String value) |
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
|
AbstractHttpRequest |
setForceFromCache(boolean fromCache)
Set it to true, if you explicit want to retrieve the desired data from
cache, ignoring the cache control.
|
AbstractHttpRequest |
setHttpMethod(String httpMethod)
Sets the http method, that is used by
HttpKit to execute this
request. |
void |
setOnOfflineAllowExpiredCacheValue(boolean allowExpired)
Set it to true, if you want to get expired results from cache, when the
user is offline (has no active internet connection).
|
AbstractHttpRequest |
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 overridenCacheControl)
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.
|
AbstractHttpRequest |
setParserWriter(ParserWriter<?> parserWriter) |
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.
|
AbstractHttpRequest |
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 |
AbstractHttpRequest |
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
|
String |
toString() |
protected String url
setUrl(String)public AbstractHttpRequest setUrl(String url)
HttpRequestsetUrl in interface HttpRequestpublic String getHttpMethod()
HttpRequestgetHttpMethod in interface HttpRequestpublic AbstractHttpRequest setHttpMethod(String httpMethod)
HttpRequestHttpKit to execute this
request. It should use the following constants:
setHttpMethod in interface HttpRequestpublic ParserWriter<?> getParserWriter()
HttpRequestgetParserWriter in interface HttpRequestpublic AbstractHttpRequest setParserWriter(ParserWriter<?> parserWriter)
public AbstractHttpRequest setForceFromCache(boolean fromCache)
HttpRequest
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
HttpRequest.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
HttpRequest.setWithoutCacheLookup(boolean).
setForceFromCache in interface HttpRequestpublic boolean isForceFromCache()
isForceFromCache in interface HttpRequestsetForceFromCache(boolean)public AbstractHttpRequest setWithoutCacheLookup(boolean withoutCache)
HttpRequestHttpRequest.setForceFromCache(boolean) to true, the
HttpRequest.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
setWithoutCacheLookup in interface HttpRequestpublic boolean isWithoutCacheLookup()
isWithoutCacheLookup in interface HttpRequestsetWithoutCacheLookup(boolean)public AbstractHttpRequest setOnOfflineFromCache(boolean offlineFromCache)
setOnOfflineFromCache in interface HttpRequestofflineFromCache - public boolean isOnOfflineFromCache()
isOnOfflineFromCache in interface HttpRequestHttpRequest.setOnOfflineFromCache(boolean)public Map<String,String> getHttpHeaders()
HttpRequestHttpRequest. 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.getHttpHeaders in interface HttpRequestpublic void setResponseContentType(String mimeType)
HttpRequestsetResponseContentType in interface HttpRequestMimeTypepublic String getResponseContentType()
getResponseContentType in interface HttpRequestHttpRequest.setResponseContentType(String)public void setOnOfflineAllowExpiredCacheValue(boolean allowExpired)
HttpRequestsetOnOfflineAllowExpiredCacheValue in interface HttpRequestallowExpired - true, if you want to allow on offline expired values from
cachepublic boolean isOnOfflineAllowExpiredCacheValue()
isOnOfflineAllowExpiredCacheValue in interface HttpRequestHttpRequest.setOnOfflineAllowExpiredCacheValue(boolean)public void setConnectingTimeout(int timeoutInMiliSeconds)
HttpRequestsetConnectingTimeout in interface HttpRequesttimeoutInMiliSeconds - in milisecondspublic int getConnectingTimeout()
getConnectingTimeout in interface HttpRequestHttpRequest.setConnectingTimeout(int)public void setReadingResponseTimeout(int timeoutInMiliSeconds)
HttpRequestsetReadingResponseTimeout in interface HttpRequestpublic int getReadingResponseTimeout()
getReadingResponseTimeout in interface HttpRequestHttpRequest.setReadingResponseTimeout(int)public void setResponseContentCharset(String charset)
HttpRequestsetResponseContentCharset in interface HttpRequestpublic String getResponseContentCharset()
getResponseContentCharset in interface HttpRequestHttpRequest.setResponseContentCharset(String)public void setPriority(int priority)
HttpRequestHttpRequest 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 (HttpRequest.getCreationTimestamp()
). Use the predefined constants:
setPriority in interface HttpRequestpriority - The priority. Use one of the priority listed abovepublic int getPriority()
HttpRequestgetPriority in interface HttpRequestHttpRequest.setPriority(int)public long getCreationTimestamp()
HttpRequestHttpRequest has
been createdgetCreationTimestamp in interface HttpRequestpublic void setPriorityChangedListener(HttpRequest.PriorityChangedListener listener)
HttpRequestHttpRequest.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.setPriorityChangedListener in interface HttpRequestHttpRequest.setPriority(int)public void cancel()
HttpRequestHttpRequestcancel in interface HttpRequestpublic void setCanceledListener(HttpRequest.CanceledListener listener)
HttpRequestGpsStatus.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.setCanceledListener in interface HttpRequestpublic int compareTo(HttpRequest other)
compareTo in interface Comparable<HttpRequest>public boolean isCanceled()
HttpRequestHttpRequest.cancel() ) this
method will return true, otherwise falseisCanceled in interface HttpRequestpublic void setFollowRedirection(boolean enabled)
HttpRequestsetFollowRedirection in interface HttpRequestpublic boolean isFollowRedirection()
isFollowRedirection in interface HttpRequestHttpRequest.setFollowRedirection(boolean)public void setCachedResultFor304(CacheEntry<?> cachedResult)
HttpRequestsetCachedResultFor304 in interface HttpRequestpublic <T> CacheEntry<T> getCachedResultFor304()
getCachedResultFor304 in interface HttpRequestsetCachedResultFor304(com.hannesdorfmann.httpkit.cache.CacheEntry)public void setOwner(Object owner)
HttpRequestsetOwner in interface HttpRequestpublic Object getOwner()
HttpRequestgetOwner in interface HttpRequestpublic <T> void doAdditionalResponseProcessing(HttpResponse<T> response, Cache<String,Object> object)
HttpRequestThis method gets called:
doAdditionalResponseProcessing in interface HttpRequestresponse - The response, that contains the data retrieved from the web
service or file cache. Manipulate this response object.object - 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!public void setParseCondition(ParseCondition condition)
HttpRequestParseCondition. 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 parsedsetParseCondition in interface HttpRequestpublic ParseCondition getParseCondition()
getParseCondition in interface HttpRequestHttpRequest.setParseCondition(ParseCondition)public void setParseInto(Class<?> clazz)
Class to where the result should be parsed. This is
typically used for json or xml parsing.setParseInto in interface HttpRequestclazz - public 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 flagsetParseInto in interface HttpRequestclazz - collectionType - public Class<?> getParseIntoClass()
getParseIntoClass in interface HttpRequestsetParseInto(Class)public int getParseIntoCollectionType()
getParseIntoCollectionType in interface HttpRequestsetParseInto(Class, int)public void setReadMemoryCache(boolean enabled)
setReadMemoryCache in interface HttpRequestenabled - public boolean isReadMemoryCache()
isReadMemoryCache in interface HttpRequestpublic void setReadDiskCache(boolean enabled)
setReadDiskCache in interface HttpRequestenabled - public boolean isReadDiskCache()
isReadDiskCache in interface HttpRequestpublic void setWriteMemoryCache(boolean enabled)
setWriteMemoryCache in interface HttpRequestenabled - public boolean isWriteMemoryCache()
isWriteMemoryCache in interface HttpRequestpublic void setWriteDiskCache(boolean enabled)
setWriteDiskCache in interface HttpRequestenabled - public boolean isWriteDiskCache()
isWriteDiskCache in interface HttpRequestpublic void setAllowStaleData(boolean allow)
setAllowStaleData in interface HttpRequestallow - public boolean isAllowStaleData()
isAllowStaleData in interface HttpRequestsetAllowStaleData(boolean)public void setUrlEncodingCharset(String charset)
URLEncoder to url encode
parameter key and valuesetUrlEncodingCharset in interface HttpRequestcharset - public String getUrlEncodingCharset()
getUrlEncodingCharset in interface HttpRequestpublic void putUrlParam(String key, String value)
putUrlParam in interface HttpRequestkey - value - public void putUrlParam(String key, int value)
putUrlParam in interface HttpRequestkey - value - public void putUrlParam(String key, long value)
putUrlParam in interface HttpRequestkey - value - public void putUrlParam(String key, boolean value)
putUrlParam in interface HttpRequestkey - value - public void putUrlParam(String key, float value)
putUrlParam in interface HttpRequestkey - value - public void putUrlParam(String key, double value)
putUrlParam in interface HttpRequestkey - value - public void putUrlParam(String key, char value)
putUrlParam in interface HttpRequestkey - value - protected String getUrlParamsString()
public String getUrl()
HttpRequestgetUrl in interface HttpRequestpublic void setOverrideResponseCacheControl(String overridenCacheControl)
HttpRequestsetOverrideResponseCacheControl in interface HttpRequestoverridenCacheControl - the desired cache controlpublic String getOverrideResponseCacheControl()
getOverrideResponseCacheControl in interface HttpRequestHttpRequest.setOverrideResponseCacheControl(String)Copyright © 2015 Hannes Dorfmann. All rights reserved.