Solved

Sending an HTTP response after some time of processing

Posted on 2006-11-20
2
176 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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hashcode is calculated on the basis of value object 2 94
String format issue 13 88
TreeSet comparator example 7 87
own marker interface 1 43
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now