当我使用异步servlet时,spring的ETag过滤器无效(spring 3.2)

时间:2013-08-26 08:23:36

标签: java spring servlet-3.0 etag

最近我们在使用spring 3.2的servlet 3.0中使用异步功能,但是我们的ShallowEtagHeaderFilter根本没有效果,我认为必须是框架在我的内容处理之前刷新响应... 怎么解决?有人有经验吗?

1 个答案:

答案 0 :(得分:0)

参考Spring 4.3.5中ShallowEtagFilter的代码片段,

protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {

    HttpServletResponse responseToUse = response;
    if (!isAsyncDispatch(request) && !(response instanceof ContentCachingResponseWrapper)) {
        responseToUse = new HttpStreamingAwareContentCachingResponseWrapper(response, request);
    }

    filterChain.doFilter(request, responseToUse);

    if (!isAsyncStarted(request) && !isContentCachingDisabled(request)) {
        updateResponse(request, responseToUse);
    }
}

/**
     * Whether request processing is in asynchronous mode meaning that the
     * response will not be committed after the current thread is exited.
     * @param request the current request
     * @since 3.2
     * @see WebAsyncManager#isConcurrentHandlingStarted()
     */
    protected boolean isAsyncStarted(HttpServletRequest request) {
        return WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted();
    }

当您使用异步servlet时,不会满足条件,这意味着不会调用生成etag的业务逻辑。