답변이 좀 늦었습니다.
상혁님께서 말씀하신 것 처럼
request body 데이터를 읽어 들여 저장해 놓는 객체를 생성해 놓은 후 이를 doFilter로 넘기는 것으로 해결하였습니다.
정답을 알고 나니 해답은 의외로 간단하네요.
HTTP request body 데이터를 읽어 들여 byte[]로 저장한 뒤 request.getInputStream 할 때마다 body[] 배열에 있는 값을 매번 읽어 들이면 되는 거였네요.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpRequestWrapper requestWrapper = new HttpRequestWrapper(httpServletRequest);
chain.doFilter(requestWrapper, response);
}
===============================
public class HttpRequestWrapper extends HttpServletRequestWrapper {
/** HTTP request body data */
private byte[] bodyData;
/**
* @param request
* @throws IOException
*/
public HttpRequestWrapper(HttpServletRequest request) throws IOException {
super(request);
InputStream is = super.getInputStream();
bodyData = IOUtils.toByteArray(is);
}
/**
* <pre>
* getInputStream
*
* <pre>
* @return
* @throws IOException
*/
@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream bis = new ByteArrayInputStream(bodyData);
return new ServletImpl(bis);
}
}
class ServletImpl extends ServletInputStream {
private InputStream is;
public ServletImpl(InputStream bis) {
is = bis;
}
@Override
public int read() throws IOException {
return is.read();
}
@Override
public int read(byte[] b) throws IOException {
return is.read(b);
}
}
@권남님
AOP를 이용하여 처리를 해볼까라는 생각을 했었지만 URI 패턴에 따라서 validation 체크를 해야 했고, interceptor 빈 초기화 시 DI로 주입해 주는 String 값들이 많아 배제하고 있었습니다. ㅠㅠ
다행히 HttpServletRequestWrapper를 재구현 하는 방법으로 문제를 해결하였습니다.
도움 주신 분들께 감사드립니다. (그나저나 상혁님, 권남님께서 답변을 달아주시니 예전 스프링 스터디 했던 시절이 생각나네요. ^^ 잘 지내고 계시죠?)