Java Jersey如何阻止loggingFilter打印?

时间:2018-02-26 13:11:37

标签: java spring server jersey

我使用jersey loggingFilter类打印所有请求/回复内容。 这是过滤器连接代码:

import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spring.scope.RequestContextFilter;

import com.ladpc.mobile.util.CORSResponseFilter;
import com.ladpc.mobile.util.LoggingResponseFilter;

/**
 * Registers the components to be used by the JAX-RS application
 * 
 * @author ama
 *
 */
public class MobileApplication extends ResourceConfig {

    /**
     * Register JAX-RS application components.
     */
    public MobileApplication() {
        try {
            register(RequestContextFilter.class);
            register(TaskService.class);
            register(LookupService.class);
            register(UsersService.class);
            register(PropertyService.class);
            register(DocumentsPathService.class);
            register(DocumentsService.class);
            register(WorkPlanService.class);
            register(IssueService.class);
            register(ActionTypesService.class);
            register(JacksonFeature.class);
            register(LoggingResponseFilter.class);
            register(MyApplicationEventListener.class);
            registerInstances(new LoggingFilter(Logger.getLogger(MobileApplication.class.getName()), true));
            register(CORSResponseFilter.class);
            register(MultiPartFeature.class);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

问题:某些响应内容太长,因为它包含图像内容或pdf文件内容的字节数组,因此当客户端多次调用此服务时,日志文件会被填满并导致其原因很多跑步问题。 有一种方法可以阻止一些服务,这些服务的响应不是由loggingFilter类自动打印的吗?

谢谢。

0 个答案:

没有答案