I came across this issue today and based on @Sylvain Lecoy's answer I came up with this implementation of a servlet filter that acts in the way the Atlassian filter javadoc describes. Putting it before any filter that calls WebAsyncUtils.getAsyncManager(ServletRequest)
seems to fix any classloader/cross-context issues.
public class IgnoreWebAsyncManagerFilter implements Filter {
static class IgnoreWebAsyncManagerCacheServletRequest extends HttpServletRequestWrapper {
/**
* Creates a ServletRequest adaptor wrapping the given request object.
*
* @param request the {@link ServletRequest} to wrap.
* @throws IllegalArgumentException if the request is null
*/
IgnoreWebAsyncManagerCacheServletRequest(HttpServletRequest request) {
super(request);
}
/**
* {@inheritDoc}
*/
@Override
public void setAttribute(String name, Object o) {
if (!name.equals(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE)) {
super.setAttribute(name, o);
}
}
}
/**
* {@inheritDoc}
*/
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
/**
* {@inheritDoc}
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(new IgnoreWebAsyncManagerCacheServletRequest((HttpServletRequest) request), response);
}
/**
* {@inheritDoc}
*/
@Override
public void destroy() {
}
Note: This assumes all requests are HttpServletRequest instances but could be modified to be more safe.