On 05/06/2023 10:15, netye...@sina.com wrote:
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?

Tomcat is correct. WebLogic is wrong.

The specification states:

<quote>
If any of the dispatch methods are called before the container initiated dispatch that called startAsync has returned to the container, the following conditions must hold during that time between the invocation of dispatch and the return of control to the container:

i. any dispatch invocations invoked during that time will not take effect until after the container- initiated dispatch has returned to the container.

ii. any AsyncListener.onComplete(AsyncEvent), AsyncListener.onTimeout(AsyncEvent) and AsyncListener.onError(AsyncEvent) invocations will also be delayed until after the container- initiated dispatch has returned to the container.

iii. any calls to request.isAsyncStarted() must return true until after the container-initiated dispatch has returned to the container.

</quote>


Point iii is exactly the scenario demonstrated by your sample code.

You should raise a specification compliance bug against WebLogic. You might also want to inquire how WebLogic managed to pass the Servlet TCK given that there is a test for this specific behavior.

Mark



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;
     }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to