ShallowEtagHeaderFilter does not work under WAS8 application server

org.springframework.web.filter.ShallowEtagHeaderFilter cannot set the response header under the WAS8 application server, stating " WARNING: cannot set the header. Response already made ." However, this works great when testing under the Tomcat server. ShallowEtagHeaderFilter does complete the original response to delay writing the response body, but still the response comes as fixed after a sequence of filters. Is this a possible mistake on the web? Any suggestion / workaround to solve this problem is welcome.

+5
source share
3 answers

I solved this problem by overriding the ServletResponse.flushBuffer method. Under WAS8, flushBuffer is called prematurely. Passing the HttpServletResponseWrapper with the no-operation flushBuffer to the 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 } } } 
+7
source

I think the above problem can be solved by adding this custom property

com.ibm.ws.webcontainer.invokeFlushAfterService = false

+1
source

I used the extremecomponents jar file using

 chain.doFilter(request, new ExportResponseWrapper((HttpServletResponse) response)) 

encounters β€œUnable to set header. Answer already done” in WAS8.

  @Override public void flushBuffer() throws IOException { } 

in class ExportResponseWrapper, saved my life.

Thanks a lot...:)

-1
source

Source: https://habr.com/ru/post/951757/


All Articles