Package org.wso2.carbon.mediator.cache
Class CachableResponse
- java.lang.Object
-
- org.wso2.carbon.mediator.cache.CachableResponse
-
- All Implemented Interfaces:
Serializable
public class CachableResponse extends Object implements Serializable
This object holds the cached response and the related properties of the cache per request and will be stored in to the cache. This holds the response envelope together with the request hash and the response hash. Apart from that this object holds the refresh time of the cache and the timeout period. This implements the Serializable interface to support the clustered caching.- See Also:
Serializable
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CachableResponse()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clean()
Sets the responsePayload and the headerProperties to nullMap<String,Object>
getHeaderProperties()
This method gives the HTTP Header Properties of the responseString
getHttpMethod()
String[]
getHTTPMethodsToCache()
This method gives the HTTP method that needs to be cached.int
getMaxMessageSize()
This method gives the maximum size of the messages to be cached in bytes.String
getProtocolType()
String
getRequestHash()
This method gives the hash value of the request payload stored in the cachePattern
getResponseCodePattern()
org.apache.axiom.soap.SOAPEnvelope
getResponseEnvelope()
long
getResponseFetchedTime()
This method returns the originated time of the response.byte[]
getResponsePayload()
This method gives the cached response payload for json as a byte arrayString
getStatusCode()
Object
getStatusReason()
long
getTimeout()
This method gives the timeout period in millisecondsboolean
isAddAgeHeaderEnabled()
This method returns whether an Age header needs to be included or not.boolean
isCacheControlEnabled()
This method returns whether cache-control is enabled or not.boolean
isJson()
void
setAddAgeHeaderEnabled(boolean addAgeHeaderEnabled)
This method sets whether an Age header needs to be included or not.void
setCacheControlEnabled(boolean cacheControlEnabled)
This method sets whether cache-control is enabled or not.void
setHeaderProperties(Map<String,Object> headerProperties)
This method sets the HTTP Header Properties of the responsevoid
setHttpMethod(String httpMethod)
void
setHTTPMethodsToCache(String... hTTPMethodToCache)
This sets the HTTP method that needs to be cached.void
setJson(boolean json)
Sets whether the response content-type is json or notvoid
setMaxMessageSize(int maxMessageSize)
This method sets the maximum size of the messages to be cached in bytes.void
setProtocolType(String protocolType)
This method sets protocolType of the messages.void
setRequestHash(String requestHash)
This method sets the hash of the request to the cachevoid
setResponseCodePattern(Pattern responseCodePattern)
This method sets the response codes that needs to be cached.void
setResponseEnvelope(org.apache.axiom.soap.SOAPEnvelope responseEnvelope)
void
setResponseFetchedTime(long responseFetchedTime)
This method sets the originated time of the response.void
setResponsePayload(byte[] responsePayload)
This method sets the response payload to the cache as a byte arrayvoid
setStatusCode(String statusCode)
Sets the HTTP status code number of the responsevoid
setStatusReason(String statusReason)
Sets the HTTP response's Reason-Phrase that is sent by the backend.void
setTimeout(long timeout)
This method sets the timeout period as milliseconds
-
-
-
Method Detail
-
clean
public void clean()
Sets the responsePayload and the headerProperties to null
-
getResponsePayload
public byte[] getResponsePayload()
This method gives the cached response payload for json as a byte array- Returns:
- byte[] representing the cached response payload for json
-
setResponsePayload
public void setResponsePayload(byte[] responsePayload)
This method sets the response payload to the cache as a byte array- Parameters:
responsePayload
- - response payload to be stored in to the cache as a byte array
-
getResponseEnvelope
public org.apache.axiom.soap.SOAPEnvelope getResponseEnvelope()
- Returns:
- The response
SOAPEnvelope
for xml response
-
setResponseEnvelope
public void setResponseEnvelope(org.apache.axiom.soap.SOAPEnvelope responseEnvelope)
- Parameters:
responseEnvelope
-SOAPEnvelope
for xml response
-
getRequestHash
public String getRequestHash()
This method gives the hash value of the request payload stored in the cache- Returns:
- String hash of the request payload
-
setRequestHash
public void setRequestHash(String requestHash)
This method sets the hash of the request to the cache- Parameters:
requestHash
- - hash of the request payload to be set as an String
-
getTimeout
public long getTimeout()
This method gives the timeout period in milliseconds- Returns:
- timeout in milliseconds
-
setTimeout
public void setTimeout(long timeout)
This method sets the timeout period as milliseconds- Parameters:
timeout
- - millisecond timeout period to be set
-
getHeaderProperties
public Map<String,Object> getHeaderProperties()
This method gives the HTTP Header Properties of the response- Returns:
- Map
representing the HTTP Header Properties
-
setHeaderProperties
public void setHeaderProperties(Map<String,Object> headerProperties)
This method sets the HTTP Header Properties of the response- Parameters:
headerProperties
- HTTP Header Properties to be stored in to cache as a map
-
isJson
public boolean isJson()
- Returns:
- whether the response is json or not
-
setJson
public void setJson(boolean json)
Sets whether the response content-type is json or not- Parameters:
json
- whether the response content-type is json or not
-
getStatusCode
public String getStatusCode()
- Returns:
- HTTP status code number of the response
-
setStatusCode
public void setStatusCode(String statusCode)
Sets the HTTP status code number of the response- Parameters:
statusCode
- HTTP status code number of the response
-
getStatusReason
public Object getStatusReason()
- Returns:
- HTTP response's Reason- Phrase that is sent by the backend.
-
setStatusReason
public void setStatusReason(String statusReason)
Sets the HTTP response's Reason-Phrase that is sent by the backend.- Parameters:
statusReason
- HTTP response's Reason-Phrase that is sent by the backend.
-
getHTTPMethodsToCache
public String[] getHTTPMethodsToCache()
This method gives the HTTP method that needs to be cached.- Returns:
- the HTTP method to be cached
-
setHTTPMethodsToCache
public void setHTTPMethodsToCache(String... hTTPMethodToCache)
This sets the HTTP method that needs to be cached.- Parameters:
hTTPMethodToCache
- the HTTP method to be cached
-
getProtocolType
public String getProtocolType()
- Returns:
- the protocol type of the messages
-
setProtocolType
public void setProtocolType(String protocolType)
This method sets protocolType of the messages.- Parameters:
protocolType
- protocol type of the messages.
-
getResponseCodePattern
public Pattern getResponseCodePattern()
- Returns:
- The regex expression of the HTTP response code of the messages to be cached
-
setResponseCodePattern
public void setResponseCodePattern(Pattern responseCodePattern)
This method sets the response codes that needs to be cached.- Parameters:
responseCodePattern
- the response codes pattern to be cached in regex form.
-
getMaxMessageSize
public int getMaxMessageSize()
This method gives the maximum size of the messages to be cached in bytes.- Returns:
- maximum size of the messages to be cached in bytes.
-
setMaxMessageSize
public void setMaxMessageSize(int maxMessageSize)
This method sets the maximum size of the messages to be cached in bytes.- Parameters:
maxMessageSize
- maximum size of the messages to be set in bytes.
-
getHttpMethod
public String getHttpMethod()
- Returns:
- the http method of the request
-
setHttpMethod
public void setHttpMethod(String httpMethod)
- Parameters:
httpMethod
- the http method of the request
-
getResponseFetchedTime
public long getResponseFetchedTime()
This method returns the originated time of the response.- Returns:
- the originated time of the response.
-
setResponseFetchedTime
public void setResponseFetchedTime(long responseFetchedTime)
This method sets the originated time of the response.- Parameters:
responseFetchedTime
- originated time of the response.
-
isCacheControlEnabled
public boolean isCacheControlEnabled()
This method returns whether cache-control is enabled or not.- Returns:
- whether cache-control is enabled or not.
-
setCacheControlEnabled
public void setCacheControlEnabled(boolean cacheControlEnabled)
This method sets whether cache-control is enabled or not.- Parameters:
cacheControlEnabled
- whether cache-control is enabled or not.
-
isAddAgeHeaderEnabled
public boolean isAddAgeHeaderEnabled()
This method returns whether an Age header needs to be included or not.- Returns:
- whether an Age header needs to be included or not.
-
setAddAgeHeaderEnabled
public void setAddAgeHeaderEnabled(boolean addAgeHeaderEnabled)
This method sets whether an Age header needs to be included or not.- Parameters:
addAgeHeaderEnabled
- whether an Age header needs to be included or not.
-
-