13

Following an issue reported on this question, a solution was found:

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

This seems a bit strange and is not really 'portable' code (it won't hurt, but...). It seems specific to Tomcat 7. I am using Tomcat 7.0.14 as delivered by NetBeans 7.0.1.

I could not find documentation indicating it is necessary to enable async request processing in servlet 3.0 with a catalina attribute. I could not find documentation indicating something special was necessary at the Tomcat configuration level too.

Is there a way to avoid having to set ASYNC_SUPPORTED=true in each request to enable async servlet 3.0 processing in Tomcat 7?

Community
  • 1
  • 1
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • in Tomcat 7.0.27 `req.startAsync()` or `req.startAsync(req, res)` works without errors and additional settings. – user1516873 Dec 24 '12 at 15:21

3 Answers3

7

A couple of things to check first:

Make sure any filters that operate on the request also support async (as addressed in one of the answers to the question you referenced).

Make sure you're using a Servlet 3.0 web.xml - for example:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0"
         metadata-complete="true">
Community
  • 1
  • 1
kschneid
  • 5,626
  • 23
  • 31
4

Try upgrading.

  • Bug 53623 fixed in 7.0.30.
  • "Enable remaining valves for Servlet 3 asynchronous processing support." (fixed in 7.0.16)

Check the Tomcat 7 ChangeLog for complete details.

Also, if you want to use async, then you'll need to make sure that all of the filters and valves in the chain (as well as the servlet, of course) all support async. This is likely the problem in the original question, as well as with your case, here.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • I am using Tomcat 7.0.34, the servlet version in web.xml is indeed 3.0 and everything should be async enabled (since it's working with Jetty) – Eugen Dec 29 '12 at 14:27
  • @Eugen Jetty might interpret the spec slightly differently. "It works in Jetty" is not a rock-solid argument that Tomcat has a bug. – Christopher Schultz Dec 31 '12 at 20:47
  • +1 for the reference to recent bug fixes. There are many useful async bug fixes in the last 5 releases (7.0.30-35) – ricosrealm Jan 22 '13 at 09:11
1

I found that org.apache.catalina.ASYNC_SUPPORTED=true is only needed when you from one normal-servlet/jsp (internally) forward to an async-servlet! Example: In my index.jsp, I embed <jsp:forward page="/path/AsyncServlet" /> I promise the AsyncServlet works fine on both Tomcat7 and Glassfish3, when I directly trigger it from browser! However when I trigger it by index.jsp: Tomcat7 reports 500 for "Not supported" Glassfish3 reports 500 for "Request is within the scope of a filter or servlet that does not support asynchronous operations" If I embed <% request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true); %> before <jsp:forward> in index.jsp, Tomcat7 goes OK, but Glassfish3 still is BAD! So I found a solution for both Tomcat7 and Glassfish3 (without SYNC_SUPPORTED!): Just EXACTLY attach followings in web.xml:

<servlet>
    <servlet-name>indexPage</servlet-name>
    <jsp-file>/index.jsp</jsp-file>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>indexPage</servlet-name>
    <url-pattern>/index.jsp</url-pattern>
  </servlet-mapping>

Conclusion (for me): You can NOT forward from a normal-servlet/jsp/filter to an async-one! Since the async-request feature MUST be preset! So the common solution for a servlet/jsp/filter which needs to forward to an async-servlet is: Use <servlet>/<async-supported>true or @WebServlet(asyncSupported = true) for a pre-processed servlet; Use <servlet>/<async-supported>true for a pre-processed jsp Use <filter>/<async-supported>true or @WebFilter(asyncSupported = true) for a pre-processed filter; Hope this may help a little bit!

Zhu Fei
  • 21
  • 2