Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid request set ASYNC_SUPPORTED=true to enable async servlet 3.0 processing on Tomcat 7?

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?

like image 873
Jérôme Verstrynge Avatar asked Oct 21 '11 21:10

Jérôme Verstrynge


People also ask

Is Tomcat asynchronous?

In case of Tomcat the latter approach uses Tomcat's thread pool defined in server. xml . Non-blocking IO (NIO); Although it is asynchronous as well it is a different story.

Which class is used to process the request asynchronously within the servlet?

servlet. AsyncContext class provides the functionality that you need to perform asynchronous processing inside service methods.

What protocol is used to execute asynchronously in the context of a thread?

An asynchronous procedure call (APC) is a function that executes asynchronously in the context of a particular thread.

What is Async servlet?

In short, an asynchronous servlet enables an application to process incoming requests in an asynchronous fashion: A given HTTP worker thread handles an incoming request and then passes the request to another background thread which in turn will be responsible for processing the request and send the response back to the ...


2 Answers

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">
like image 90
kschneid Avatar answered Nov 04 '22 03:11

kschneid


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.

like image 42
Christopher Schultz Avatar answered Nov 04 '22 03:11

Christopher Schultz