Previous Topic: ProxyFilter Interface

Next Topic: ProxyFilterException Class

BaseProxyFilter Abstract Implementation

The Filter API includes BaseProxyFilter, an abstract implementation of a proxy filter that can be implemented as a subclass to create ProxyFilters.

Note: It is recommended that you extend the BaseProxyFilter Abstract Implementation, rather than implementing the ProxyFilter interface.

A subclass of BaseProxyFilter must override at least one of the following methods:

The BaseProxyFilter includes filter initialization and separates pre-processing and post-processing hooks for inserting your own filters into SPS transactions, as listed in the following table.

Return Value

Method

Void

doFilter(ProxyRequest prequest,
ProxyResponse presponse) throws
ProxyFilterException

This implementation determines the state of the request processing and calls doPreFilter if it's in an inbound state otherwise it calls doPostFilter for outbound state. At the time the filters get called processing can only be in one of these states.

Specified by:

doFilter in interface ProxyFilter

Parameters:

request - the proxy request data

response - the proxy response data

Throws:

ProxyFilterException - thrown if failure processing filtering

Void

doPreFilter(ProxyRequest prequest,
ProxyResponse presponse) throws
ProxyFilterException

Performs pre-filtering. Override this method to perform filtering tasks before the request is sent to the target server.

Parameters:

request - the proxy request data

response - the proxy response data

Throws:

ProxyFilterException - thrown if failure processing filtering

Void

doPostFilter(ProxyRequest prequest,
ProxyResponse presponse) throws
ProxyFilterException

Performs post-filtering. Override this method to perform filtering tasks after the response is received from the target server.

Parameters:

request - the proxy request data

response - the proxy response data

Throws:

ProxyFilterException - thrown if failure processing filtering

ProxyFilterConfig

getFilterConfig()

Returns this filter's ProxyFilterConfig object.

Specified by:

getFilterConfig in interface ProxyFilter

Returns:

ProxyFilterConfig the ProxyFilterConfig object that initialized this filter.

Void

init(ProxyFilterConfig config) throws
ProxyFilterException

Called when the filter is created to perform any required initialization.

Note: When overriding this method, the first statement should call the parent init method "super.init(config);".

Specified by:

init in interface ProxyFilter

Parameters:

config - a ProxyFilterConfig object containing the filters's configuration and initialization parameters

Throws:

ProxyFilterException - thrown if failure initializing this filter.

ProxyFilterConfig Interface

Defines the interface to the configuration data available to a filter. The interface consists of the following methods:

Return Value

Method

java.lang.String

getFilterName()

Returns the name of this filter.

java.lang.String

getInitParameter(java.lang.String name)

Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

Parameters:

name - a String specifying the name of the initialization parameter

java.util.Enumeration

getInitParameterNames()

Returns the names of the filter's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the filter has no initialization parameters.

ProxyResponse Interface

Defines the interface that provides access to HTTP response information to be returned to the proxy client. The interface consists of the following methods:

Return Value

Method

void

addHeader(java.lang.String name, java.lang.String value)

Adds a header with the specified name and value. This method allows response headers to have multiple values.

Parameters:

name - a String specifying the header name

value - a String specifying the header value

byte[]

getContent()

Returns a byte array of the content of the response to the proxy request. This is the content to be returned to the proxy client.

java.lang.String

getHeader(java.lang.String name)

Returns the value of the specified header as a String. If the header does not exist, this method returns null. The header name is not case sensitive.

Parameters:

name - a String specifying the header name

java.util.Enumeration

getHeaderNames()

Returns an Enumeration of all the header names. If no headers exist, this method returns an empty Enumeration.

int

getStatusCode()

Returns the HTTP response status code of the response to the proxy request.

java.lang.String

removeHeader(java.lang.String name)

Removes the specified header. Returns the value of the removed header as a String. If the header does not exist, this method returns null. The header name is not case sensitive.

Parameters:

name - a String specifying the header name

void

setContent(byte[] content)

Sets the content of the response to the proxy request. This overwrites the content to be returned to the proxy client.

Parameters:

content - the byte array containing the content

void

setHeader(java.lang.String name, java.lang.String value)

Sets a header with the specified name and value. If a header with the same name exists it will be overwritten.

Parameters:

name - a String specifying the header name

value - a String specifying the header value