How to access request headers in a WriterInterceptor interface implementation in JAX-RS?
context.getHeaders(); //This line gives a set of response headers(not request headers) in the WriterInterceptor implementation.
Full code below:
public class GzipFilterWriterInterceptor implements WriterInterceptor { private static final Logger LOG = LoggerFactory.getLogger(GzipFilterWriterInterceptor.class); @Override public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { MultivaluedMap<String,Object> headers = context.getHeaders(); headers.add("Content-Encoding", "gzip"); final OutputStream outputStream = context.getOutputStream(); context.setOutputStream(new GZIPOutputStream(outputStream)); context.proceed(); } }
java jax-rs
Shubham kumar
source share