Solved

Sending an HTTP response after some time of processing

Posted on 2006-11-20
2
177 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Converting a Hibernate Query to use parameters 5 105
Help with LDAp login using jsp 6 113
stateless EJB with glassfish 2 71
listing all functions in JavaScript 19 180
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

27 Experts available now in Live!

Get 1:1 Help Now