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.
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
}
}
}
i think the above problem can be resolved by adding this custom property
com.ibm.ws.webcontainer.invokeFlushAfterService = false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With