java ee - MessageBodyWriter vs. WriterInterceptor -


i bit confused exact intention of writerinterceptor interface of jax-rs 2.0 specification.

what know far:

  • writerinterceptor called before messagebodywriter
  • both interfaces grant access same variables
  • messagebodywriter concerned translating object stream
  • 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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -