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?
本文标签:
版权声明:本文标题:java - Why is my response already committed in my lowest precedence filter in spring when using ContentCachingResponseWrapper? - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064854a2584799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论