Package net.toddm.comm
Class Response
- java.lang.Object
-
- net.toddm.comm.Response
-
- All Implemented Interfaces:
Serializable
public class Response extends Object implements Serializable
Represents a response resulting from an attempt to process aRequestinstance.- Author:
- Todd S. Murchison
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringgetContentEncoding(Map<String,List<String>> headers)Returns the value for the 'Content-Encoding' header from the given header collection, or NULL if no value can be resolved.StringgetETagFromHeaders()If we are able to resolve an ETag value form the headers of thisResponseinstance then the ETag value is returned, otherwise NULL is returned.Map<String,List<String>>getHeaders()The HTTP header values from the response.protected longgetInstanceCreationTime()Returns the epoch timestamp in milliseconds of when this instance ofResponsewas created.URIgetLocationFromHeaders(Request request)LonggetMaxStaleFromHeaders()If we are able to resolve a "max-stale" value form the Cache-Control headers of thisResponseinstance then the value is returned, otherwise NULL is returned.IntegergetRequestId()StringgetResponseBody()Returns the response body of this response as a String, or null if there is no response body or the response body bytes can not be interpreted as a UTF-8 string.byte[]getResponseBytes()Returns the response body of this response as raw bytes, or null if there is no response body.IntegergetResponseCode()Returns the HTTP Status Code for this response, or null if there isn't one.intgetResponseTimeMilliseconds()Returns the total amount of time, in milliseconds, that it took to get this response from the time it started processing.LonggetRetryAfter()If we are able to resolve a Retry-After value form the headers of thisResponseinstance then the Retry-After value is returned, otherwise NULL is returned.LonggetTtlFromHeaders()If we are able to resolve a TTL value form the Cache-Control headers ("max-age") of thisResponseinstance then the TTL value is returned, otherwise NULL is returned.booleanisFromCache()Returns true if thisResponsewas served from cache.booleanisSuccessful()Returns true if thisResponseinstance has an HTTP response code that we consider to indicate "success".booleanshouldNotCacheDueToNoCacheDirective()If the Cache-Control headers of thisResponseinstance contain the "no-cache" directive true is returned, otherwise false is returned.
-
-
-
Method Detail
-
getResponseBytes
public byte[] getResponseBytes()
Returns the response body of this response as raw bytes, or null if there is no response body.
-
getResponseBody
public String getResponseBody()
Returns the response body of this response as a String, or null if there is no response body or the response body bytes can not be interpreted as a UTF-8 string.
-
getResponseCode
public Integer getResponseCode()
Returns the HTTP Status Code for this response, or null if there isn't one.
-
getResponseTimeMilliseconds
public int getResponseTimeMilliseconds()
Returns the total amount of time, in milliseconds, that it took to get this response from the time it started processing.
-
isFromCache
public boolean isFromCache()
Returns true if thisResponsewas served from cache. Returns false if this Response was received via a network request.
-
isSuccessful
public boolean isSuccessful()
Returns true if thisResponseinstance has an HTTP response code that we consider to indicate "success". Currently this either 200 or 201.
-
getRequestId
public Integer getRequestId()
-
getInstanceCreationTime
protected long getInstanceCreationTime()
Returns the epoch timestamp in milliseconds of when this instance ofResponsewas created.
-
getContentEncoding
public static String getContentEncoding(Map<String,List<String>> headers)
Returns the value for the 'Content-Encoding' header from the given header collection, or NULL if no value can be resolved.
-
getRetryAfter
public Long getRetryAfter()
If we are able to resolve a Retry-After value form the headers of thisResponseinstance then the Retry-After value is returned, otherwise NULL is returned. The Retry-After value returned is in seconds. This method does support 'HTTP-date' values for Retry-After, but they are interpreted in relation to the current time and a simple value in seconds is still returned.
-
shouldNotCacheDueToNoCacheDirective
public boolean shouldNotCacheDueToNoCacheDirective()
If the Cache-Control headers of thisResponseinstance contain the "no-cache" directive true is returned, otherwise false is returned.
-
getTtlFromHeaders
public Long getTtlFromHeaders()
If we are able to resolve a TTL value form the Cache-Control headers ("max-age") of thisResponseinstance then the TTL value is returned, otherwise NULL is returned. The TTL value returned is in milliseconds.
-
getMaxStaleFromHeaders
public Long getMaxStaleFromHeaders()
If we are able to resolve a "max-stale" value form the Cache-Control headers of thisResponseinstance then the value is returned, otherwise NULL is returned. The "max-stale" value returned is in milliseconds.
-
-