-
1. Re: Multiple threads after response.sendredirect
pferraro Jun 8, 2019 9:19 AM (in response to zidoff)I've looked at your reproducer and have run it. Your expectations are simply incorrect.
Here is the code flow in your reproducer:
- /Redirection
- doGet(...)
- doPost(...)
- method2(...)
- method3(...)
- HttpResponse.sendRedirect("RedirectionTarget")
- method3(...)
- System.out.println("statemen1")
- System.out.println("statemen2")
- method2(...)
- doPost(...)
- doGet(...)
In this flow, your sendRedirect(...) happens before the System.out calls. Thus the System.out from RedirectionTarget will happen in parallel with the the System.out calls in your RedirectionSource.doPost(...) method.
- /Redirection
-
2. Re: Multiple threads after response.sendredirect
zidoff Jun 9, 2019 2:28 AM (in response to pferraro)Dear Paul
Be advised that my expectation are correct when running the provided project under Apache Tomcat, WebLogic and WebSphere.
Kindly try to run it under tomcat and check the output. is it possible that there's a Wildfly configuration to be applied in order to meet the expectation?
Thanks and Best Regards
-
3. Re: Multiple threads after response.sendredirect
pferraro Jun 10, 2019 7:34 AM (in response to zidoff)I refer you to section 5.5 of the servlet specification:
"[sendRedirect(...)] will have the side effect of committing the response, if it has not already been committed, and terminating it. No further output to the client should be made by the servlet after these methods are called. If data is written to the response after these methods are called, the data is ignored."
Therefore, following the sendRedirect(...) invocation, the client that initiated the request will receive a 302 response, sending another request to the redirection target. This second auto-initiated request might be processed by the same thread (if the previous thread has already completed), or it might happen in a second thread. This behavior is can vary between servlet container implementations. If there is logic that should execute before the redirected request is processed, then you should execute this logic before you call sendRedirect(...).