admin管理员组

文章数量:1356953

I have a OncePerRequestFilter:

@Component
public class RestrictedSettingsFilter extends OncePerRequestFilter {
  @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
        try {
            filterChain.doFilter(request, responseWrapper);
            if (responseWrapper.isCommitted()) {
                log.warn("The response has already been committed, cannot modify it");
                return;
            }
            // ...
        } finally { responseWrapper.copyBodyToResponse(); }
}

and I manually register it (probably should be done by annotations, but the project is a bit old):

@Bean
public FilterRegistrationBean<Filter> restrictedSettingsFilter(RestrictedSettingsFilter restrictedSettingsFilter) {
        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(restrictedSettingsFilter);
        filterRegistrationBean.setOrder(Ordered.LOWEST_PRECEDENCE); 
        return filterRegistrationBean;
}

From what I understand, when I set its order to LOWEST_PRECEDENCE, it should be resolved last in pre-processing and first in post-processing. Therefore, the response should not be committed yet. But I get The response has already been committed, cannot modify it message. On the other hand, when I set the order to HIGHEST_PRECEDENCE, it started working again. How is it possible?

本文标签: