Sending an HTTP response after some time of processing
Posted on 2006-11-20
I have 3 tier application that relies on a Servlet to contact a third-party server, exchange informations, and finally printing a JSP page with the data obtained by this transaction.
The fact is, this process takes some time and the application must wait for a thread called "ConnectionReader" to receive the message with the informations from the remote server.
In order to retain the chance to write on the client's browser, I saved the PrintWriter which I obtain from the HttpServletResponse object inside a Hashtable and I call him back when I need to print the result.
In short, is something like this:
- I receive the Http Request, and the DoGet() method is invoked;
- from the HttpServletResponse object I obtain the PrintWriter, which I put inside a Hashtable with a unique ID;
- after some time, the Reader thread reads a message from my remote connection to the server;
- I then proceed to retrieve the PrintWriter I saved before and print the resulting informations on it.
...but this doesn't work, and my page is still blank. What am I doing wrong?
Consider that if I write on this PrintWriter immediately after obtaining it, it works and I can see on the browser the output of what I write.
Thanks in advance for the help.