public abstract class HttpFilter extends Object implements Filter
doFilter(HttpServletRequest, HttpServletResponse, FilterChain)
and may override other methods, if needed.
This filter serializes in the HTTP response an OslcError
embedded in a OslcWebApplicationException
,
if such exception is thrown by subclasses.
Constructor and Description |
---|
HttpFilter() |
Modifier and Type | Method and Description |
---|---|
void |
destroy()
This implementation does nothing.
|
protected abstract void |
doFilter(HttpServletRequest request,
HttpServletResponse response,
FilterChain chain)
Processes this filter and either executes or blocks the chain.
|
void |
doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
Verifies the request and the response are HTTP ones and calls
doFilter(HttpServletRequest, HttpServletResponse, FilterChain) . |
protected void |
handleOslcError(HttpServletRequest request,
HttpServletResponse response,
OslcWebApplicationException exception,
MediaType contentType)
Handles the behavior of the filter when an OSLC Error occurred at running this filter, another filter in the chain or the servlet.
|
void |
init(FilterConfig filterConfig)
This implementation does nothing.
|
public void init(FilterConfig filterConfig) throws ServletException
init
in interface Filter
filterConfig
- the configuration of the filter.ServletException
- not thrown by this implementation.public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
doFilter(HttpServletRequest, HttpServletResponse, FilterChain)
.
The method serializes in the HTTP response an OslcError
embedded in a OslcWebApplicationException
thrown by doFilter(HttpServletRequest, HttpServletResponse, FilterChain)
, if any.
doFilter
in interface Filter
request
- the request.response
- the response.chain
- the filter chain to process.IOException
- if thrown by doFilter(HttpServletRequest, HttpServletResponse, FilterChain)
.ServletException
- if not running in an HTTP context, or if thrown by doFilter(HttpServletRequest, HttpServletResponse, FilterChain)
.protected abstract void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException
Subclasses may throw a OslcWebApplicationException
to report an OslcError
.
This filter will automatically serialize such error in the HTTP response.
request
- the request.response
- the response.chain
- the filter chain to process.IOException
- if an I/O error occurs.ServletException
- if the filter execution fails.protected void handleOslcError(HttpServletRequest request, HttpServletResponse response, OslcWebApplicationException exception, MediaType contentType) throws IOException
This implementation:
OslcError
description as HTML content when text/html
is requested,OslcError
entity as JSON, XML or Turtle, if such media type is requested,OslcError
message as plain text if any other media type is requested.Subclasses may override this method to adapt the response to particular cases, for example to render a different type of HTML content (or redirect to an HTML page) or to handle specific media types.
request
- the received requestresponse
- the response to sendexception
- the OslcWebApplicationException
thrown by the filter, another filter in the chain or the servlet. At this stage the
exception is known to embed an OslcError.contentType
- the desired content type for the response (e.g. application/json
or text/html
).IOException
- exception can be thrown when writing response