0
votes

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.

1
Your question is two-fold. This duplicates your first question: stackoverflow.com/questions/3242236/… This duplicates your second question: stackoverflow.com/questions/1302072/…BalusC

1 Answers

0
votes

You might be able to call getOutputStream() and read that, but I'd be concerned about it screwing up the stream. There are some reset methods, but I'm not familiar with what they do myself.