Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalStateException: Not supported on AsyncContext.startAsync(req, res)

I have created a servlet 3.0 to explore asynchronous request processing:

@WebServlet(name="MyTest", urlPatterns={"/MyTest"}, asyncSupported=true)
public class MyTest extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {

        AsyncContext tmp = req.startAsync(req, res);
        ...

    }    

}

but I get an IllegalStateException when .startAsync(...) is called. I know the Javadoc mentions that exception, but I did explicitly enable async (c.f. WebServlet annotation). I am using Tomcat 7.0.11.0 delivered with NetBeans.

I could confirm that req.isAsyncSupported() is returning false. What am I doing wrong? What more do I need to do to enable async processing?

EDIT:

I tried to implement the following example and got the same issue.

like image 892
Jérôme Verstrynge Avatar asked Oct 13 '11 04:10

Jérôme Verstrynge


2 Answers

I checked out Tomcat's code and saw that the asyncSupported variable has to be explicitly set to true. That's why you are getting req.isAsyncSupported() == false.

You could try to set the async attribute in the HttpServletRequest object to true by one of the following methods.

req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);

or

((org.apache.catalina.connector.Request)req).setAsyncSupported(true);

Hope it helps.

like image 68
Efthymis Avatar answered Nov 20 '22 09:11

Efthymis


Please check if you have any request filter which is not enabled to support async. Either you can remove the filter (temporarily) or mark it to support async.

like image 8
Sanjay Singh Avatar answered Nov 20 '22 10:11

Sanjay Singh