I am a bit confused about the exact intention of the WriterInterceptor
Interface of the JAX-RS 2.0 specification.
What I know so far:
WriterInterceptor
is called before MessageBodyWriter
MessageBodyWriter
is concerned with translating an object
into a streamMy questionis: For which intent should the Reader/Writer Interceptor be used for?
On the server-side you can let the Message Body Writers do the entity marshalling and while the Interceptors can take care of:
For example:
@Override
void aroundWriteTo(WriterInterceptorContext ctx) ... {
OutputStream old = ctx.getOutputStream();
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(old);
ctx.setOutputStream(gzipOutputStream);
updateHeaders(ctx);
try {
ctx.proceed();
} finally {
gzipOutputStream.finish();
ctx.setOutputStream(old);
}
}
(code above comes from the JAX-RS 2.0 spec, section 6.3)
HTH.