Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShallowEtagHeaderFilter does not work under WAS8 app server

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.

like image 937
Somu Avatar asked Nov 07 '12 09:11

Somu


2 Answers

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
        }
    }
}
like image 177
Somu Avatar answered Nov 19 '22 21:11

Somu


i think the above problem can be resolved by adding this custom property

com.ibm.ws.webcontainer.invokeFlushAfterService = false

like image 23
gifty Avatar answered Nov 19 '22 21:11

gifty