Class CachedResponse


  • public class CachedResponse
    extends java.lang.Object
    Represents an HTTP response that has been cached by the WebBrowser.

    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 using setHeader(String, String). If a request is sent to a Url which is cached (and hasn't expired), then no request will be made to the web server, and a Response object will be constructed from the stored CachedResponse 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 a CachedResponse object with the specified Url.
      CachedResponse​(java.lang.String url)
      Creates a CachedResponse object with the specified url.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearHeaders()
      Removes all the HTTP response headers from this CachedResponse.
      boolean containsHeader​(java.lang.String header)
      Returns true if this CachedResponse contains the specified HTTP header.
      void delete()  
      java.lang.String getCharEncoding()
      Gets the character encoding that is used to decode the data contained in this CachedResponse, 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 this CachedResponse.
      java.lang.String getHeaders()
      Gets the HTTP response headers for this CachedResponse.
      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 the Url that this CachedResponse represents a response to.
      java.lang.String getUserAgent()
      Gets the value of the "User-Agent" HTTP header.
      boolean hasReferer()
      Returns true if the "Referer" HTTP header has been set for this CachedResponse.
      void removeHeader​(java.lang.String header)
      Removes a specified HTTP response header from this CachedResponse.
      void setCharEncoding​(java.lang.String charEncoding)
      Sets the character encoding that is used to decode the data contained in this CachedResponse, 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 this CachedResponse, using the contents of the specified String.
      void setHeader​(java.lang.String header, java.lang.String value)
      Sets an HTTP response header for this CachedResponse, as a name/value pair.
      void setReferer​(Url url)
      Sets the value of the "Referer" HTTP header to the specified Url.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 object
        cMemoryOwn - indicates if this object is responsible for memory management of the CPP object
      • CachedResponse

        public CachedResponse​(java.lang.String url)
        Creates a CachedResponse object with the specified url.
        Parameters:
        url - the URL to use
      • CachedResponse

        public CachedResponse​(Url url)
        Creates a CachedResponse object with the specified Url.
        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 the Url that this CachedResponse represents a response to.
        Returns:
        the Url that this CachedResponse represents a response to
      • setHeader

        public void setHeader​(java.lang.String header,
                              java.lang.String value)
        Sets an HTTP response header for this CachedResponse, 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 name
        value - 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 this CachedResponse, using the contents of the specified String.

        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()
      • setReferer

        public void setReferer​(Url url)
        Sets the value of the "Referer" HTTP header to the specified Url.
        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)
        Returns true if this CachedResponse 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()
        Returns true if the "Referer" HTTP header has been set for this CachedResponse.
        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 this CachedResponse.
        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 this CachedResponse, 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 this CachedResponse, for example "UTF-8".
        Returns:
        the character encoding
        See Also:
        setCharEncoding(String)