Package com.facilita.fc.web
Class CachedResponse
- java.lang.Object
-
- com.facilita.fc.web.CachedResponse
-
public class CachedResponse extends java.lang.Object
Represents an HTTP response that has been cached by theWebBrowser
.A
CachedResponse
can be added to the cache prior to sending a request to the web server. The HTTP headers"Expires"
and"Last-Modified"
must be set usingsetHeader(String, String)
. If a request is sent to aUrl
which is cached (and hasn't expired), then no request will be made to the web server, and aResponse
object will be constructed from the storedCachedResponse
object instead.See
WebBrowser.addResponseToCache(CachedResponse)
for more details.
-
-
Constructor Summary
Constructors Constructor Description CachedResponse(long cPtr, boolean cMemoryOwn)
For internal use only.CachedResponse(Url url)
Creates aCachedResponse
object with the specifiedUrl
.CachedResponse(java.lang.String url)
Creates aCachedResponse
object with the specifiedurl
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearHeaders()
Removes all the HTTP response headers from thisCachedResponse
.boolean
containsHeader(java.lang.String header)
Returnstrue
if thisCachedResponse
contains the specified HTTP header.void
delete()
java.lang.String
getCharEncoding()
Gets the character encoding that is used to decode the data contained in thisCachedResponse
, for example"UTF-8"
.java.lang.String
getContentType()
Gets the value of the"Content-Type"
HTTP header.static long
getCPtr(CachedResponse obj)
For internal use only.java.util.List<java.lang.String>
getHeaderKeys()
Gets a list of names of all the HTTP response headers set in thisCachedResponse
.java.lang.String
getHeaders()
Gets the HTTP response headers for thisCachedResponse
.java.lang.String
getHeaderValue(java.lang.String header)
Gets the value of the specified HTTP response header.java.lang.String
getReferer()
Gets the value of the"Referer"
HTTP header.Url
getUrl()
Gets theUrl
that thisCachedResponse
represents a response to.java.lang.String
getUserAgent()
Gets the value of the"User-Agent"
HTTP header.boolean
hasReferer()
Returnstrue
if the"Referer"
HTTP header has been set for thisCachedResponse
.void
removeHeader(java.lang.String header)
Removes a specified HTTP response header from thisCachedResponse
.void
setCharEncoding(java.lang.String charEncoding)
Sets the character encoding that is used to decode the data contained in thisCachedResponse
, for example"UTF-8"
.void
setContentType(java.lang.String contentType)
Sets the value of the"Content-Type"
HTTP header.void
setHeader(java.lang.String header)
Sets an HTTP response header for thisCachedResponse
, using the contents of the specifiedString
.void
setHeader(java.lang.String header, java.lang.String value)
Sets an HTTP response header for thisCachedResponse
, as a name/value pair.void
setReferer(Url url)
Sets the value of the"Referer"
HTTP header to the specifiedUrl
.void
setReferer(java.lang.String referer)
Sets the value of the"Referer"
HTTP header.void
setUserAgent(java.lang.String userAgent)
Sets the value of the"User-Agent"
HTTP header.void
unsetReferer()
Removes the"Referer"
HTTP header.
-
-
-
Constructor Detail
-
CachedResponse
public CachedResponse(long cPtr, boolean cMemoryOwn)
For internal use only. Of no interest to the user.- Parameters:
cPtr
- pointer to the CPP wrapped objectcMemoryOwn
- indicates if this object is responsible for memory management of the CPP object
-
CachedResponse
public CachedResponse(java.lang.String url)
Creates aCachedResponse
object with the specifiedurl
.- Parameters:
url
- the URL to use
-
-
Method Detail
-
getCPtr
public static long getCPtr(CachedResponse obj)
For internal use only. Of no interest to the user.- Parameters:
obj
- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
-
getUrl
public Url getUrl()
Gets theUrl
that thisCachedResponse
represents a response to.- Returns:
- the
Url
that thisCachedResponse
represents a response to
-
getHeaders
public java.lang.String getHeaders()
Gets the HTTP response headers for thisCachedResponse
.- Returns:
- the HTTP response headers for this
CachedResponse
- See Also:
setHeader(String, String)
,setHeader(String)
,getHeaderValue(String)
-
setHeader
public void setHeader(java.lang.String header, java.lang.String value)
Sets an HTTP response header for thisCachedResponse
, as a name/value pair.e.g.
CachedResponse cachedResponse = new CachedResponse("http://myDomain/weather/images/symbols/57x57/3.gif"); // Set the Expires response header cachedResponse.setHeader("Expires", "Fri, 22 Aug 2008 16:23:24 GMT");
- Parameters:
header
- the header namevalue
- the header value- See Also:
getHeaders()
,getHeaderValue(String)
,setHeader(String)
,removeHeader(String)
,clearHeaders()
-
setHeader
public void setHeader(java.lang.String header)
Sets an HTTP response header for thisCachedResponse
, using the contents of the specifiedString
.e.g.
CachedResponse cachedResponse = new CachedResponse("http://myDomain/weather/images/symbols/57x57/3.gif"); // Set the Expires response header cachedResponse.setHeader("Expires: Fri, 22 Aug 2008 16:23:24 GMT");
- Parameters:
header
- the header name and value- See Also:
getHeaders()
,getHeaderValue(String)
,setHeader(String, String)
,removeHeader(String)
,clearHeaders()
-
removeHeader
public void removeHeader(java.lang.String header)
Removes a specified HTTP response header from thisCachedResponse
.- Parameters:
header
- the name of the header to remove- See Also:
getHeaders()
,getHeaderValue(String)
,setHeader(String, String)
,clearHeaders()
-
clearHeaders
public void clearHeaders()
Removes all the HTTP response headers from thisCachedResponse
.
-
setReferer
public void setReferer(Url url)
Sets the value of the"Referer"
HTTP header to the specifiedUrl
.- Parameters:
url
- the value to set
-
setUserAgent
public void setUserAgent(java.lang.String userAgent)
Sets the value of the"User-Agent"
HTTP header.- Parameters:
userAgent
- the value to set
-
setReferer
public void setReferer(java.lang.String referer)
Sets the value of the"Referer"
HTTP header.- Parameters:
referer
- the value to set
-
unsetReferer
public void unsetReferer()
Removes the"Referer"
HTTP header.
-
containsHeader
public boolean containsHeader(java.lang.String header)
Returnstrue
if thisCachedResponse
contains the specified HTTP header.if (cachedResponse.containsHeader("Expires")) { writeMessage(String.format("Expires=%s", cachedResponse.getHeaderValue("Expires"))); }
- Parameters:
header
- the HTTP header to check for- Returns:
true
if the header was found
-
getHeaderValue
public java.lang.String getHeaderValue(java.lang.String header)
Gets the value of the specified HTTP response header.- Parameters:
header
- the header to get the value of- Returns:
- the value of the header
- See Also:
getHeaders()
,setHeader(String, String)
,removeHeader(String)
-
getUserAgent
public java.lang.String getUserAgent()
Gets the value of the"User-Agent"
HTTP header.- Returns:
- the value of the
"User-Agent"
HTTP header
-
getReferer
public java.lang.String getReferer()
Gets the value of the"Referer"
HTTP header.- Returns:
- the value of the
"Referer"
HTTP header
-
hasReferer
public boolean hasReferer()
Returnstrue
if the"Referer"
HTTP header has been set for thisCachedResponse
.- Returns:
true
if the"Referer"
header has been set
-
getContentType
public java.lang.String getContentType()
Gets the value of the"Content-Type"
HTTP header.- Returns:
- the value of the
"Content-Type"
HTTP header
-
getHeaderKeys
public java.util.List<java.lang.String> getHeaderKeys() throws com.facilita.exception.InternalError
Gets a list of names of all the HTTP response headers set in thisCachedResponse
.- Returns:
- a list of names of all the HTTP response headers set in this
CachedResponse
- Throws:
com.facilita.exception.InternalError
- An internal error occurred.
-
setContentType
public void setContentType(java.lang.String contentType)
Sets the value of the"Content-Type"
HTTP header.- Parameters:
contentType
- the value to set
-
setCharEncoding
public void setCharEncoding(java.lang.String charEncoding)
Sets the character encoding that is used to decode the data contained in thisCachedResponse
, for example"UTF-8"
.- Parameters:
charEncoding
- the character encoding to set- See Also:
getCharEncoding()
-
getCharEncoding
public java.lang.String getCharEncoding()
Gets the character encoding that is used to decode the data contained in thisCachedResponse
, for example"UTF-8"
.- Returns:
- the character encoding
- See Also:
setCharEncoding(String)
-
-