net.sf.ehcache.constructs.web
Class PageInfo

java.lang.Object
  extended by net.sf.ehcache.constructs.web.PageInfo
All Implemented Interfaces:
Serializable

public class PageInfo
extends Object
implements Serializable

A Serializable representation of a HttpServletResponse.

Version:
$Id: PageInfo.java 744 2008-08-16 20:10:49Z gregluck $
Author:
Adam Murdoch, Greg Luck
See Also:
Serialized Form

Constructor Summary
PageInfo(int statusCode, String contentType, Collection cookies, byte[] body, boolean storeGzipped, long timeToLiveSeconds, Collection<Header<? extends Serializable>> headers)
          Creates a PageInfo object representing the "page".
PageInfo(int statusCode, String contentType, Collection headers, Collection cookies, byte[] body, boolean storeGzipped, long timeToLiveSeconds)
          Deprecated. use #PageInfo(int, String, Collection, Collection, Collection, Collection, byte[], boolean, long)
 
Method Summary
 String getContentType()
           
 Date getCreated()
          The Date this PageInfo object was created
 byte[] getGzippedBody()
           
 List<Header<? extends Serializable>> getHeaders()
           
 List getResponseHeaders()
          Deprecated. use getHeaders()
 List getSerializableCookies()
          Returns the cookies of the response.
 int getStatusCode()
          Returns the status code of the response.
 long getTimeToLiveSeconds()
          The time to live in seconds.
 byte[] getUngzippedBody()
           
 boolean hasGzippedBody()
           
 boolean hasUngzippedBody()
           
static boolean isGzipped(byte[] candidate)
          Checks the first two bytes of the candidate byte array for the magic number 0x677a.
 boolean isOk()
          Returns true if the response is Ok.
protected  void setTimeToLiveWithCheckForNeverExpires(long timeToLiveSeconds)
          See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html To mark a response as "never expires," an origin server sends an Expires date approximately one year from the time the response is sent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageInfo

@Deprecated
public PageInfo(int statusCode,
                           String contentType,
                           Collection headers,
                           Collection cookies,
                           byte[] body,
                           boolean storeGzipped,
                           long timeToLiveSeconds)
         throws AlreadyGzippedException
Deprecated. use #PageInfo(int, String, Collection, Collection, Collection, Collection, byte[], boolean, long)

Creates a PageInfo object representing the "page".

Parameters:
statusCode -
contentType -
headers -
cookies -
body -
storeGzipped - set this to false for images and page fragments which should never
timeToLiveSeconds - the time to Live in seconds. 0 means maximum, which is one year per RFC2616.
Throws:
AlreadyGzippedException

PageInfo

public PageInfo(int statusCode,
                String contentType,
                Collection cookies,
                byte[] body,
                boolean storeGzipped,
                long timeToLiveSeconds,
                Collection<Header<? extends Serializable>> headers)
         throws AlreadyGzippedException
Creates a PageInfo object representing the "page".

Parameters:
statusCode -
contentType -
cookies -
body -
storeGzipped - set this to false for images and page fragments which should never
timeToLiveSeconds - the time to Live in seconds. 0 means maximum, which is one year per RFC2616.
headers -
Throws:
AlreadyGzippedException
Method Detail

setTimeToLiveWithCheckForNeverExpires

protected void setTimeToLiveWithCheckForNeverExpires(long timeToLiveSeconds)
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html To mark a response as "never expires," an origin server sends an Expires date approximately one year from the time the response is sent. HTTP/1.1 servers SHOULD NOT send Expires dates more than one year in the future.

Parameters:
timeToLiveSeconds - accepts 0, which means eternal. If the time is 0 or > one year, it is set to one year in accordance with the RFC.

Note: PageInfo does not hold a reference to the ehcache Element and therefore does not know what the Element ttl is. It would normally make most sense to set the TTL to the same as the element expiry.


isGzipped

public static boolean isGzipped(byte[] candidate)
Checks the first two bytes of the candidate byte array for the magic number 0x677a. This magic number was obtained from /usr/share/file/magic. The line for gzip is:

>>14 beshort 0x677a (gzipped)

Parameters:
candidate - the byte array to check
Returns:
true if gzipped, false if null, less than two bytes or not gzipped

getContentType

public String getContentType()
Returns:
the content type of the response.

getGzippedBody

public byte[] getGzippedBody()
Returns:
the gzipped version of the body if the content is storeGzipped, otherwise null

getResponseHeaders

@Deprecated
public List getResponseHeaders()
Deprecated. use getHeaders()

Returns the headers of the response.


getHeaders

public List<Header<? extends Serializable>> getHeaders()
Returns:
All of the headers set on the page

getSerializableCookies

public List getSerializableCookies()
Returns the cookies of the response.


getStatusCode

public int getStatusCode()
Returns the status code of the response.


getUngzippedBody

public byte[] getUngzippedBody()
                        throws IOException
Returns:
the ungzipped version of the body. This gunzipped on demand when storedGzipped, otherwise the ungzipped body is returned.
Throws:
IOException

hasGzippedBody

public boolean hasGzippedBody()
Returns:
true if there is a non null gzipped body

hasUngzippedBody

public boolean hasUngzippedBody()
Returns:
true if there is a non null ungzipped body

isOk

public boolean isOk()
Returns true if the response is Ok.

Returns:
true if the response code is 200.

getCreated

public Date getCreated()
The Date this PageInfo object was created


getTimeToLiveSeconds

public long getTimeToLiveSeconds()
The time to live in seconds.

Returns:
the time to live, or 0 if the wrapping element is eternal


Copyright © 2003-2011 Terracotta, Inc.. All Rights Reserved.