问题
org.springframework.web.filter.ShallowEtagHeaderFilter
is unable to set response header under WAS8 application server stating "WARNING: Cannot set header. Response already committed". However this works fine when tested under Tomcat server. ShallowEtagHeaderFilter
is indeed wrapping the original response to delay the writing of response body, but still the response comes as committed after the filter chain's execution. Is this a possible websphere bug? Any suggestion / workaround to overcome this issue is welcome.
回答1:
I solved this issue by overriding ServletResponse.flushBuffer
method. Under WAS8 flushBuffer
is getting called prematurely. Passing a HttpServletResponseWrapper
with a no-operation flushBuffer
method to ShallowEtagHeaderFilter
did the trick.
public class HttpCacheFilter extends ShallowEtagHeaderFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
HttpCacheResponseWrapper responseWrapper = new HttpCacheResponseWrapper(response);
super.doFilterInternal(request, responseWrapper, filterChain);
}
private static class HttpCacheResponseWrapper extends HttpServletResponseWrapper {
public HttpCacheResponseWrapper(HttpServletResponse response) {
super(response);
}
@Override
public void flushBuffer() throws IOException {
// NOOP
}
}
}
回答2:
i think the above problem can be resolved by adding this custom property
com.ibm.ws.webcontainer.invokeFlushAfterService = false
回答3:
I was using extremecomponents
jar file using
chain.doFilter(request, new ExportResponseWrapper((HttpServletResponse) response))
faced "Cannot set header. Response already committed" in WAS8 .
by
@Override
public void flushBuffer() throws IOException {
}
in ExportResponseWrapper class , saved my life.
Thanks a lot ... :)
来源:https://stackoverflow.com/questions/13266744/shallowetagheaderfilter-does-not-work-under-was8-app-server