Solved

Sending an HTTP response after some time of processing

Posted on 2006-11-20
2
179 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:Emanuele_Ciriachi
2 Comments
 
LVL 9

Expert Comment

by:owenli27
ID: 17980508
What Exception you got, java.lang.IllegalStateException: xxxx ?
Your response cannot be commited becasue of connection lost after a certain time or printWriter may auto flush and commited response already.
0
 
LVL 12

Accepted Solution

by:
enachemc earned 500 total points
ID: 17985940
you should consider using a worker thread launched from the doGet. Wait for this thread to finish or some time to pass (you can use Object.wait(long time)). If the timeout occurs, display a message, if the processing has completed, display whatever you want. You could use the wait in a loop and provide some kind of progress bar to the user.

Do not try to keep the writer after the doGet has finished.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to reset your Windows 10 password when you've forgotten it.
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question