- java.lang.Object
-
- org.omnifaces.filter.HttpFilter
-
- org.omnifaces.filter.MutableRequestFilter
-
- All Implemented Interfaces:
Filter
public class MutableRequestFilter extends HttpFilter
The
MutableRequestFilter
will wrap the incomingHttpServletRequest
in aMutableRequestFilter.MutableRequest
so that the developer can mutate the headers and parameters in such way that the outcome of among othersHttpServletRequest.getHeader(String)
andServletRequest.getParameter(String)
are influenced.Installation
To get this filter to run, map it as follows in
web.xml
:<filter> <filter-name>mutableRequestFilter</filter-name> <filter-class>org.omnifaces.filter.MutableRequestFilter</filter-class> </filter> <filter-mapping> <filter-name>mutableRequestFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
The ordering of the
<filter-mapping>
is significant. TheMutableRequestFilter.MutableRequest
is not available in any filter which is mapped before theMutableRequestFilter
.Usage
When inside
FacesContext
, useFaces.getMutableRequestHeaderMap()
orFaces.getMutableRequestParameterMap()
. Or when having only aHttpServletRequest
at hands, useServlets.getMutableRequestHeaderMap(HttpServletRequest)
orServlets.getMutableRequestParameterMap(HttpServletRequest)
.- Since:
- 3.14
- Author:
- Bauke Scholtz
- See Also:
HttpFilter
,MutableRequestFilter.MutableRequest
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MutableRequestFilter.MutableRequest
-
Field Summary
Fields Modifier and Type Field Description static String
MUTABLE_REQUEST
The name of the request attribute under which theMutableRequestFilter.MutableRequest
will be stored.
-
Constructor Summary
Constructors Constructor Description MutableRequestFilter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doFilter(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain chain)
Creates and sets the mutable request.static MutableRequestFilter.MutableRequest
getMutableRequest(HttpServletRequest request)
Returns the mutable request.void
init()
Tracks whether this filter is installed.-
Methods inherited from class org.omnifaces.filter.HttpFilter
destroy, doFilter, getFilterConfig, getInitParameter, getServletContext, init
-
-
-
-
Field Detail
-
MUTABLE_REQUEST
public static final String MUTABLE_REQUEST
The name of the request attribute under which theMutableRequestFilter.MutableRequest
will be stored.- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init() throws ServletException
Tracks whether this filter is installed.- Overrides:
init
in classHttpFilter
- Throws:
ServletException
- When filter's initialization failed.
-
doFilter
public void doFilter(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain chain) throws ServletException, IOException
Creates and sets the mutable request.- Specified by:
doFilter
in classHttpFilter
- Parameters:
request
- The HTTP request.response
- The HTTP response.session
- The HTTP session, if any, elsenull
.chain
- The filter chain to continue.- Throws:
ServletException
- As wrapper exception when something fails in the request processing.IOException
- Whenever something fails at I/O level.- See Also:
Filter.doFilter(ServletRequest, ServletResponse, FilterChain)
-
getMutableRequest
public static MutableRequestFilter.MutableRequest getMutableRequest(HttpServletRequest request)
Returns the mutable request.- Returns:
- The mutable request.
- Throws:
IllegalStateException
- When theMutableRequestFilter
is not installed or not invoked yet.- Since:
- 3.14
-
-