4/09/2016

How to resolve async not supported issue on tomcat?

In tomcat based applications we might have encountered the issue like asyc is not supported. This is because by default its not supported in container level but we are trying to get the behavior that's when we used to get the below error.This kind of issue happens especially when you push the data from server to client.





Feb 05, 2016 2:18:08 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Push Servlet] in context with path [/bta] threw exception
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:1673)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1030)
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379)
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379)
at org.springframework.security.web.context.HttpSessionSecurityContextRepository$Servlet3SaveToSessionRequestWrapper.startAsync(HttpSessionSecurityContextRepository.java:246)
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379)
at org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.startAsync(HttpServlet3RequestFactory.java:173)
at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:724)
at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:93)
at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:68)
at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.doService(Tomcat7Servlet30SupportWithWebSocket.java:67)
at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:100)
at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:62)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2275)
at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:190)
at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:176)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

Possible Reasons:
1.Async support is not enabled in your container level
2.Aynce support is not enabled in framework level which your using.

Possible Solutions:
There are several ways to set the value of async supported is true.

1.In Web.xml we can define as like below

<servlet>
<servlet-class>com.MainServlet</servlet-class>
<servlet-name>AsyncServlet</servlet-name>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>AsyncServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

2. We define async support attribute through annotation as like below

@WebServlet(url="/test" asyncSupported=true)
class MainServlet extends HttpServlet{
}

3. In case of Atmosphere we can set as like below

<servlet>
<description>AtmosphereServlet</description>
<servlet-name>AtmosphereServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>


4. In case of JSF

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>

1 comments so far

CommentsComments