如何使Web过滤器支持异步?

jan*_*ith 6 embedded-jetty resteasy servlet-filters

我正在使用RESTEasy异步支持.然而它打破了我的JSONPfilter.

public class JSONPFilter implements Filter {

    private static final Logger logger = LoggerFactory.getLogger(JSONPFilter.class);

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

        String callbackName = request.getParameter("callback");

        if (callbackName != null) {

            ServletOutputStream sos = response.getOutputStream();
            sos.print(callbackName + "(");
            chain.doFilter(request, response);
            sos.print(");");
        } else {

            chain.doFilter(request, response);
        }
    }


curl http://localhost:8088/v0/chat?callback=jsonp
jsonp();{"data":"hello world: 53","timestamp":"2012-11-26T05:04:26.000Z"}
Run Code Online (Sandbox Code Playgroud)

正确的结果应该是:

jsonp({"data":"hello world: 53","timestamp":"2012-11-26T05:04:26.000Z"});
Run Code Online (Sandbox Code Playgroud)

过滤器在非异步servlet上工作正常.我试过添加@WebFilter

@WebFilter(urlPatterns = "/*", asyncSupported = true)
public class JSONPFilter implements Filter {
Run Code Online (Sandbox Code Playgroud)

但似乎服务器无法识别@WebFilter,因为一旦我删除了web.xml中的条目,过滤器根本不起作用.

我试过添加

<async-supported>true</async-supported>
Run Code Online (Sandbox Code Playgroud)

到目前为止没有运气.

顺便说一句,我使用的是嵌入式Jetty v8.13