ShallowEtagHeaderFilter does not work under WAS8 app server

戏子无情 提交于 2019-12-06 02:35:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!