0

I have a spring app which exposes REST API's implemented in CXF. I'm trying to implement long polling for which I used AsyncResponse Along with Suspended. If I run this peice of code in tomcat (maven plugin or standalone) it works. But if I run the same code in jetty using maven plugin (mvn jetty:run) it fails. CXF throws NPE. i have debugged it and saw that ContinuationProvider was not set for the request. So on further debugging I found that jetty internally was setting AsyncSupport boolean variable in the Request object as false before applying filter and then in finally block setting it true again. But the filter chain contains the servlet also, So causing the servlet to interpret the request with AsyncSupport false.

jetty maven plugin version 9.1.3vxxxxxx ServletHandler.java from jetty codebase

 @Override
    public void doFilter(ServletRequest request, ServletResponse response)
        throws IOException, ServletException
    {
        final Request baseRequest=(request instanceof Request)?((Request)request):HttpChannel.getCurrentHttpChannel().getRequest();

        // pass to next filter
        if (_filterHolder!=null)
        {
            if (LOG.isDebugEnabled())
                LOG.debug("call filter " + _filterHolder);
            Filter filter= _filterHolder.getFilter();
            if (_filterHolder.isAsyncSupported())
                filter.doFilter(request, response, _next);
            else
            {
                final boolean suspendable=baseRequest.isAsyncSupported();
                if (suspendable)
                {
                    try
                    {
                        baseRequest.setAsyncSupported(false);
                        filter.doFilter(request, response, _next);
                    }
                    finally
                    {
                        baseRequest.setAsyncSupported(true);
                    }
                }
                else
                    filter.doFilter(request, response, _next);
            }
            return;
        }

Why does the filter chain contain the servlet ? Why the reuest is begin modified before doFilter ? How do I get it working in jetty maven plugin ?

high-voltage
  • 123
  • 5

1 Answers1

0

Found the problem. It was with Log4jServletContainerInitializer which automatically registers a filter (Log4jServletFilter) for all the requests. The problem here was with the version I was using. Log4j2.0-beta-9 (problematic), the problem was that when the Log4jServletFilter was registered it was not registered with AsyncSupport (i.e async-supported true) . So I upgrade to log4j2.0-rc1 which sloved the problem. :)

high-voltage
  • 123
  • 5