I'm currently using below interceptor (implementing both
MessageBodyReaderInterceptor and PreProcessInterceptor) to dump incoming
requests to a log file.

I'm implementing them both because:
a) MessageBodyReaderInterceptor is not intercepting requests without body
(like a GET or OPTIONS request)
b) PreProcessInterceptor has no option to retrieve the request body.

Would there be a way to more or less 'combine' the 2 and only once call the
LOG.debug statement like
LOG.debug("Request:" + NEW_LINE + httpServletRequest + NEW_LINE + new

public class RequestDumperInterceptor implements
MessageBodyReaderInterceptor, PreProcessInterceptor {

private static final Log LOG =

private static final String NEW_LINE = System.getProperty("line.separator");

private HttpServletRequest httpServletRequest;

public Object read(MessageBodyReaderContext context) throws IOException,
WebApplicationException {
if (LOG.isDebugEnabled()) {
InputStream old = context.getInputStream();
try {
InputStreamToByteArray stream = new InputStreamToByteArray(old);
Object proceed = context.proceed();
byte[] body = stream.toByteArray();
LOG.debug("Body:" + NEW_LINE + new String(body));
return proceed;
} finally {
return context.proceed();

public ServerResponse preProcess(HttpRequest request, ResourceMethod
method) throws Failure, WebApplicationException {
if (LOG.isDebugEnabled()) {
LOG.debug("Request:" + NEW_LINE + httpServletRequest);
return null;
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
Resteasy-users mailing list

Reply via email to