我正在使用Jersey和Tomcat开发REST Web服务器,我有Jersey日志记录过滤器来记录请求和响应。我在我的web.xml中有这个并且它有效。
我想在记录PUT和POST的响应主体时禁用GET响应的日志响应主体。我该怎么做?
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.logging.DisableEntitylogging</param-name>
<param-value>false</param-value>
</init-param>
答案 0 :(得分:0)
我认为您可以像这样扩展过滤器:
public class MyFilter extends com.sun.jersey.api.container.filter.LoggingFilter {
// other (maybe fundamental) code omitted for brevity
@Override
public ContainerRequest filter(ContainerRequest request) {
if(!request.getMethod().equals("GET")) {
return super.filter(request);
}
return request;
}
}
然后更改您的web.xml以使用它而不是
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>