I'm attempting build a simple logging system for when our client accesses out API. We're using Spring to wire up controllers and handlers. I'm looking at Spring's Interceptor functionality to write a postHandle() method. Unfortunately, unlike all the code samples I've seen here, HttpServletResponse does not have, for example, a getStatus() method. I'm supposing that we're using the wrong version of Java or something.
We need the body and response code from the HttpServletResponse object: how can I get those?
EDIT: We went with a filter:
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
RichHttpServletResponse richResponse=new RichHttpServletResponse((HttpServletResponse)response);
chain.doFilter(request, richResponse);
}
RichHttpServletResponse takes a servlet response as an argument in its constructor and overrides some of the methods, such as sendError() and passes the values through to the actual servlet response. The webmvc-config XML looks something like this:
<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
<sec:filter-chain-map path-type="ant">
<sec:filter-chain pattern="/**"
filters="requestObjectFilter" />
</sec:filter-chain-map>
</bean>
With a bean def below.