The fix was to have XWikiServletResponse extends HttpServletResponseWrapper as this is checked by undertow, see https://github.com/undertow-io/undertow/blob/2.2.19.Final/servlet/src/main/java/io/undertow/servlet/spec/RequestDispatcherImpl.java#L162
See also: