Package com.facilita.fc.web
Class CachedResponse
- java.lang.Object
-
- com.facilita.fc.web.CachedResponse
-
public class CachedResponse extends java.lang.ObjectRepresents an HTTP response that has been cached by theWebBrowser.A
CachedResponsecan 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 aUrlwhich is cached (and hasn't expired), then no request will be made to the web server, and aResponseobject will be constructed from the storedCachedResponseobject 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 aCachedResponseobject with the specifiedUrl.CachedResponse(java.lang.String url)Creates aCachedResponseobject with the specifiedurl.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearHeaders()Removes all the HTTP response headers from thisCachedResponse.booleancontainsHeader(java.lang.String header)Returnstrueif thisCachedResponsecontains the specified HTTP header.voiddelete()java.lang.StringgetCharEncoding()Gets the character encoding that is used to decode the data contained in thisCachedResponse, for example"UTF-8".java.lang.StringgetContentType()Gets the value of the"Content-Type"HTTP header.static longgetCPtr(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.StringgetHeaders()Gets the HTTP response headers for thisCachedResponse.java.lang.StringgetHeaderValue(java.lang.String header)Gets the value of the specified HTTP response header.java.lang.StringgetReferer()Gets the value of the"Referer"HTTP header.UrlgetUrl()Gets theUrlthat thisCachedResponserepresents a response to.java.lang.StringgetUserAgent()Gets the value of the"User-Agent"HTTP header.booleanhasReferer()Returnstrueif the"Referer"HTTP header has been set for thisCachedResponse.voidremoveHeader(java.lang.String header)Removes a specified HTTP response header from thisCachedResponse.voidsetCharEncoding(java.lang.String charEncoding)Sets the character encoding that is used to decode the data contained in thisCachedResponse, for example"UTF-8".voidsetContentType(java.lang.String contentType)Sets the value of the"Content-Type"HTTP header.voidsetHeader(java.lang.String header)Sets an HTTP response header for thisCachedResponse, using the contents of the specifiedString.voidsetHeader(java.lang.String header, java.lang.String value)Sets an HTTP response header for thisCachedResponse, as a name/value pair.voidsetReferer(Url url)Sets the value of the"Referer"HTTP header to the specifiedUrl.voidsetReferer(java.lang.String referer)Sets the value of the"Referer"HTTP header.voidsetUserAgent(java.lang.String userAgent)Sets the value of the"User-Agent"HTTP header.voidunsetReferer()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 aCachedResponseobject 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 theUrlthat thisCachedResponserepresents a response to.- Returns:
- the
Urlthat thisCachedResponserepresents 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)
Returnstrueif thisCachedResponsecontains 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:
trueif 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()
Returnstrueif the"Referer"HTTP header has been set for thisCachedResponse.- Returns:
trueif 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.InternalErrorGets 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)
-
-