Interface ResourceFilter
-
- All Superinterfaces:
PortletFilter
public interface ResourceFilter extends PortletFilter
TheResourceFilteris an object that performs filtering tasks on either the resource request to a portlet, or on the resource response from a portlet, or both.Filters perform filtering in the
doFiltermethod. Every Filter has access to aFilterConfigobject from which it can obtain its initialization parameters, a reference to the PortletContext which it can use, for example, to load resources needed for filtering tasks.Filters are configured in the portlet deployment descriptor of a portlet application.
Asynchronous Processing Considerations
If the
ResourceFilteris to support asynchronous mode, care must be taken regarding resource allocation and release. Any resources attached to theResourceRequestduring the inbound portion of thedoFilterinvocation and needed during asynchronous processing should not be released during outbound processing if asynchronous mode has been started.If resources must be allocated in this way during inbound processing, the portlet should use a
PortletAsyncListenerto release the resources upon request completion even when error conditions or timeouts occur.Alternatively, the portlet may use the
AsyncContext#dispatch()method at the end of asynchronous processing in order to cause the portlet resource method to be invoked again with the sameResourceRequestandResourceResponseobjects. The resources can be released during asynchronous dispatch outbound processing if asynchronous mode is not active.The
ResourceRequest#isAsyncStarted()method will returntrueif the portlet is currently in asynchronous mode. TheResourceRequest#igetDispatcherType()method will returnDispatcherType#REQUESTduring initial request processing andDipatcherType#ASYNCduring processing resulting from an asynchronous dispatch.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddoFilter(ResourceRequest request, ResourceResponse response, FilterChain chain)ThedoFiltermethod of the Filter is called by the portlet container each time a resource request/response pair is passed through the chain due to a client request for a portlet method at the end of the chain.-
Methods inherited from interface jakarta.portlet.filter.PortletFilter
destroy, init
-
-
-
-
Method Detail
-
doFilter
void doFilter(ResourceRequest request, ResourceResponse response, FilterChain chain) throws IOException, PortletException
ThedoFiltermethod of the Filter is called by the portlet container each time a resource request/response pair is passed through the chain due to a client request for a portlet method at the end of the chain.The
FilterChainpassed in to this method allows the Filter to pass on the resource request and response to the next component in the chain.The
doFiltermethod of a filter will typically be implemented following this or some subset of the following pattern:- The method examines the request information.
- The method may wrap the request object passed in to
its doFilter method with a customized implementation
the request wrapper
ResourceRequestWrapperin order to modify request data. - The method may wrap the response object passed in to its
doFiltermethod with a customized implementation of the response wrapperResourceResponseWrapperto modify response data. - The filter may invoke the next component in the filter chain.
The next component may be another filter, or if the filter
making the invocation is the last filter configured in the
deployment descriptor for this chain, the next component
is the target method of the portlet. The invocation of the
next component is effected by calling the
doFiltermethod on theFilterChainobject, and passing in the request and response with which it was called or passing in wrapped versions it may have created. The filter chain's implementation of thedoFiltermethod, provided by the portlet container, must locate the next component in the filter chain and invoke itsdoFiltermethod, passing in the appropriate request and response objects. Alternatively, the filter chain can block the request by not making the call to invoke the next component, leaving the filter responsible for filling out the response object. - After invocation of the next filter in the chain, the filter may examine the response data.
- Alternatively, the filter may have thrown an exception to
indicate an error in processing. If the filter throws an
UnavailableExceptionduring itsdoFilterprocessing, the portlet container must not attempt continued processing down the filter chain. It may choose to retry the whole chain at a later time if the exception is not marked permanent. - When the last filter in the chain has been invoked, the next component accessed is the target method on the portlet at the end of the chain.
- Parameters:
request- the current resource requestresponse- the current resource responsechain- the remaining filter chain- Throws:
IOException- if an IO error occurred in the filter processingPortletException- if a portlet exception occurred in the filter processing
-
-