java ee - MessageBodyWriter vs. WriterInterceptor -
i bit confused exact intention of writerinterceptor interface of jax-rs 2.0 specification.
what know far:
writerinterceptorcalled beforemessagebodywriter- both interfaces grant access same variables
 messagebodywriterconcerned translatingobjectstream- arun gupta states in java ee 7 book writer/reader inteceptors concerned marshalling , unmarshalling of http bodies.
 
my questionis: intent should reader/writer interceptor used for?
on server-side can let message body writers entity marshalling , while interceptors can take care of:
- performing gzip compression of marshalled entity,
 - wrapping marshalled entity in digital signature enveloppe (reader interceptor verify signature before further processing),
 - adding cache control headers
 
for example:
@override void aroundwriteto(writerinterceptorcontext ctx) ... {     outputstream old = ctx.getoutputstream();     gzipoutputstream gzipoutputstream = new gzipoutputstream(old);     ctx.setoutputstream(gzipoutputstream);     updateheaders(ctx);     try {         ctx.proceed();     } {         gzipoutputstream.finish();         ctx.setoutputstream(old);     } }   (code above comes jax-rs 2.0 spec, section 6.3)
hth.
Comments
Post a Comment