Package com.sodius.oslc.server.services
Class HttpFilter
- java.lang.Object
-
- com.sodius.oslc.server.services.HttpFilter
-
- All Implemented Interfaces:
Filter
- Direct Known Subclasses:
AccessLogFilter
,ContentSecurityPolicyFilter
,JSPCacheFilter
,LicenseFilter
,OAuthFilter
,SameSiteCookiesFilter
,XSSFilter
public abstract class HttpFilter extends Object implements Filter
A filter skeleton that ensures it is executed in an HTTP context. Subclasses must implementdoFilter(HttpServletRequest, HttpServletResponse, FilterChain)
and may override other methods, if needed.This filter serializes in the HTTP response an
OslcError
embedded in aOslcWebApplicationException
, if such exception is thrown by subclasses.- Since:
- 2.0.0
-
-
Constructor Summary
Constructors Constructor Description HttpFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 callsdoFilter(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.
-
-
-
Method Detail
-
init
public void init(FilterConfig filterConfig) throws ServletException
This implementation does nothing. Subclasses may override.- Specified by:
init
in interfaceFilter
- Parameters:
filterConfig
- the configuration of the filter.- Throws:
ServletException
- not thrown by this implementation.
-
doFilter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
Verifies the request and the response are HTTP ones and callsdoFilter(HttpServletRequest, HttpServletResponse, FilterChain)
.The method serializes in the HTTP response an
OslcError
embedded in aOslcWebApplicationException
thrown bydoFilter(HttpServletRequest, HttpServletResponse, FilterChain)
, if any.- Specified by:
doFilter
in interfaceFilter
- Parameters:
request
- the request.response
- the response.chain
- the filter chain to process.- Throws:
IOException
- if thrown bydoFilter(HttpServletRequest, HttpServletResponse, FilterChain)
.ServletException
- if not running in an HTTP context, or if thrown bydoFilter(HttpServletRequest, HttpServletResponse, FilterChain)
.
-
doFilter
protected abstract void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException
Processes this filter and either executes or blocks the chain.Subclasses may throw a
OslcWebApplicationException
to report anOslcError
. This filter will automatically serialize such error in the HTTP response.- Parameters:
request
- the request.response
- the response.chain
- the filter chain to process.- Throws:
IOException
- if an I/O error occurs.ServletException
- if the filter execution fails.
-
handleOslcError
protected void handleOslcError(HttpServletRequest request, HttpServletResponse response, OslcWebApplicationException exception, MediaType contentType) throws IOException
Handles the behavior of the filter when an OSLC Error occurred at running this filter, another filter in the chain or the servlet.This implementation:
- responds the
OslcError
description as HTML content whentext/html
is requested, - responds the
OslcError
entity as JSON, XML or Turtle, if such media type is requested, - responds the
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.
- Parameters:
request
- the received requestresponse
- the response to sendexception
- theOslcWebApplicationException
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
ortext/html
).- Throws:
IOException
- exception can be thrown when writing response
- responds the
-
-