小编Shu*_*mar的帖子

访问请求标头

如何在JAX-RS中实现WriterInterceptor接口时访问请求头?

context.getHeaders(); //This line gives a set of response headers(not request headers) in the WriterInterceptor implementation.
Run Code Online (Sandbox Code Playgroud)

完整代码如下:

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();
}

}
Run Code Online (Sandbox Code Playgroud)

java jax-rs

9
推荐指数
2
解决办法
5214
查看次数

标签 统计

java ×1

jax-rs ×1