Solved

Sending an HTTP response after some time of processing

Posted on 2006-11-20
2
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Microsoft is moving in-place eDiscovery & hold from ECP to EOP console under Content Search in Search and Investigation Options.  In this post, I will be showing you how to export emails to a PST file using the Content Search Options.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 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