title: Get HttpServletRequest state in order to avoid IllegalStateException
body: <p>Sometimes the method <code>req.startAsync()</code> from <code>HttpServletRequest</code> throws an <code>IllegalStateException</code> (Response has been closed already). </p>
  
  <p>How can I check the request state in order to avoid <code>IllegalStateException</code>?</p>
  
  <p><code>req.isAsyncSupported()</code> returns true always.</p>
  
  <p>Relevant code:</p>
  
  <pre><code>final HttpSession httpSession = req.getSession(false);  
  if (httpSession == null) {  
      resp.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);  
      return;  
  }  
  final AsyncContext asynContext = req.startAsync(); //exception here`
  </code></pre>
  
  <p>Exception:</p>
  
  <blockquote>
    <p>12:28:12,735 ERROR
    [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/esus].[LongPollServlet]]
    (http-/0.0.0.0:8080-2) JBWEB000236: Servlet.service() for servlet
    LongPollServlet threw exception: java.lang.IllegalStateException:
    JBWEB000049: Response has been closed already     at
    org.apache.catalina.connector.Request.startAsync(Request.java:3180)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.connector.Request.startAsync(Request.java:3170)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:925)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    com.performer.framework.server.LongPollServlet.continueDoPost(LongPollServlet.java:75)
    [st10.framework.webserver.jar:]   at
    com.performer.framework.server.LongPollServlet.doPost(LongPollServlet.java:62)
    [st10.framework.webserver.jar:]   at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
    [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
      at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
    [jboss-as-jpa-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]  at
    org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
    [jboss-as-jpa-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]  at
    org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
    [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]  at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:915)
    [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]  at
    java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_34]</p>
  </blockquote>