According to Servlet Specification Version 3.1, request.isAsyncStarted() should
return false after calling asyncContext.dispatch().request.isAsyncStarted()
return false in weblogic, but true in tomcat. Is tomcat's action right?
Java™ Servlet Specification Version 3.1------------------------------2.3.3.3
Asynchronous processing
ServletRequest
■ public boolean isAsyncStarted() - Returns true if async processing has
started on this request, and false otherwise. If this request has been
dispatched using one of the AsyncContext.dispatch methods since it was put
in asynchronous mode, or a call to AsynContext.complete is made, this
method returns false.
test envirment:------------------------------Tomcat 9.0.55
weblogic 12.2.1.4.0
JDK 1.8.0_261
test code:
------------------------------
import java.io.IOException;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(value = "/test", asyncSupported = true)
public class SimpleIssueServlet extends HttpServlet {
private static final long serialVersionUID = -2504425408734161943L;
private static final String CTX_RESULT = "CTX_RESULT";
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
String result = (String) request.getAttribute(CTX_RESULT);
if (result != null) {
response.getWriter().write(result);
return;
}
AsyncContext asyncContext = request.startAsync();
boolean isAsyncStarted01 = request.isAsyncStarted();
System.out.println("isAsyncStarted01:" + isAsyncStarted01);
// tomcat: isAsyncStarted01 = true;
// weblogic: isAsyncStarted01 = true;
{
// make result
String ret = "this is a test";
request.setAttribute(CTX_RESULT, ret);
asyncContext.dispatch();
}
boolean isAsyncStarted02 = request.isAsyncStarted();
System.out.println("isAsyncStarted02:" + isAsyncStarted02);
// tomcat: isAsyncStarted02 = true;
// weblogic: isAsyncStarted02 = false;
}
}