It's good to hear it's possible but how to do that it's not clear. Are there a guidelines, documentation how this can be done?
Here is the code in our custom HttpServlet (the same is for doPost):
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String rBody = readRequestContent(request);
System.out.println(rBody);
request.startAsync(request, response);
AsyncContext acont = request.getAsyncContext();
class MT extends Thread {
AsyncContext acont;
public MT(AsyncContext acont) {
this.acont = acont;
}
@Override
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {}
HttpServletRequest req = (HttpServletRequest) acont.getRequest();
HttpServletResponse resp = (HttpServletResponse) acont.getResponse();
resp.setContentType("text/html");
resp.setStatus(HttpServletResponse.SC_OK);
try {
resp.getWriter().println("<h1>Hello from HelloServlet</h1>");
} catch (IOException e) {
e.printStackTrace();
}
acont.complete();
}
}
new MT(acont).start();
}
}
Our HTTP client sends several requests and doesn't wait for a response before sending the next request.
We expect to get into this method before sending a response after 2000 mseconds but it never happens.