I tried to do…
Source
FilterHolder myHolder
= new FilterHolder(new Filter() {
public void init(FilterConfig fc) throws ServletException {
}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain fc) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) req;
HttpServletResponse httpResp = (HttpServletResponse) resp;
// HERE:
InputStream is = httpReq.getInputStream();
// (read is to a string and output it, works,
// but swallows all data forever)
fc.doFilter(httpReq, httpResp);
}
public void destroy() {
}
});
… but swallows all data and real servlets don’t get anything.
I just want to "read" POST request contents and output them for debugging.
NOTE 1: I don’t want to "intercept" requests, they should go through as before.
NOTE 2: An additional hint, how to do the same with POST responses would be very kind.
EDIT Replaced Reader with InputStream. Reader didn’t work at all.
Got it! I’m using a wrapper for InputStream and OutputStream each.
Tested. Works for both directions.
HttpRequestCopyFilter
HttpResponseCopyFilter