You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Alexander, Ben" <BA...@arqule.com> on 2001/11/15 14:27:30 UTC

Responding to a disconnected client

Some of the tasks my stateful server performs take a while to complete, and
I want to respond gracefully if a user has killed their browser before I've
gotten around to sending a response.  To set the stage, I use an
architecture that has all user responses arriving at a single servlet
(unoriginally  named FrontController, ala Alur, Crupi and Malks), then after
some processing the output is sent out via a collection of JSPs.  Currently,
if the browser exits before I send something to it, I get an exception that
looks like this:

java.net.SocketException: Connection reset by peer: socket write error
 	at
org.apache.tomcat.core.BufferedServletOutputStream.reallyFlush(BufferedServl
etOutputStream.java:234)
 	at org.apache.tomcat.core.ResponseImpl.finish(ResponseImpl.java:206)
 	at
org.apache.tomcat.facade.RequestDispatcherImpl.forward(RequestDispatcherImpl
.java:215)
 	at alo.FrontController.dispatchme(FrontController.java:339)
 	at alo.FrontController.processRequest(FrontController.java:315)
 	at alo.FrontController.doPost(FrontController.java:65)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 	at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
 	at org.apache.tomcat.core.Handler.service(Handler.java:286)
 	at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
 	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
 	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
 	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
 	at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
 	at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
 	at java.lang.Thread.run(Thread.java:484) 

What I'd like to do is to run some test to see if the browser is open, and
if it isn't then save the output for display the next time the user returns.
Of course, this solution can fail too, so even better would be to fail over
in case of exception and save the output.  I would go ahead and save
everything on every request, but my examination of the mailing archives
makes it seem that getting JSP output is difficult or impossible.  Does
anyone have a better solution to my problem, so that I don't waste
processing time only to send information off into the ether?

Thanks,
Ben  

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: Responding to a disconnected client

Posted by Brett Knights <br...@tanner.com>.
Check out the long running servlet example in the Jason Hunter book.

Wrap the result holder/processor in a Session listener.

If the browser requests the result then get it from the session and return
it. If they eventually log off or their session expires you can reclaim the
result memory.

HTH

> -----Original Message-----
> From: Alexander, Ben [mailto:BAlexander@arqule.com]
> Sent: Thursday, November 15, 2001 5:28 AM
> To: 'Tomcat Users List'
> Subject: Responding to a disconnected client
>
>
>
> Some of the tasks my stateful server performs take a while to
> complete, and
> I want to respond gracefully if a user has killed their
> browser before I've
> gotten around to sending a response.  To set the stage, I use an
> architecture that has all user responses arriving at a single servlet
> (unoriginally  named FrontController, ala Alur, Crupi and
> Malks), then after
> some processing the output is sent out via a collection of
> JSPs.  Currently,
> if the browser exits before I send something to it, I get an
> exception that
> looks like this:
>
> java.net.SocketException: Connection reset by peer: socket write error
>  	at
> org.apache.tomcat.core.BufferedServletOutputStream.reallyFlush
> (BufferedServl
> etOutputStream.java:234)
>  	at
> org.apache.tomcat.core.ResponseImpl.finish(ResponseImpl.java:206)
>  	at
> org.apache.tomcat.facade.RequestDispatcherImpl.forward(Request
> DispatcherImpl
> .java:215)
>  	at alo.FrontController.dispatchme(FrontController.java:339)
>  	at alo.FrontController.processRequest(FrontController.java:315)
>  	at alo.FrontController.doPost(FrontController.java:65)
>  	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
>  	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>  	at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper
> .java:404)
>  	at org.apache.tomcat.core.Handler.service(Handler.java:286)
>  	at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
>  	at
> org.apache.tomcat.core.ContextManager.internalService(ContextM
> anager.java:79
> 7)
>  	at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
>  	at
> org.apache.tomcat.service.http.HttpConnectionHandler.processCo
> nnection(HttpC
> onnectionHandler.java:210)
>  	at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoin
> t.java:416)
>  	at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPo
> ol.java:498)
>  	at java.lang.Thread.run(Thread.java:484)
>
> What I'd like to do is to run some test to see if the browser
> is open, and
> if it isn't then save the output for display the next time
> the user returns.
> Of course, this solution can fail too, so even better would
> be to fail over
> in case of exception and save the output.  I would go ahead and save
> everything on every request, but my examination of the
> mailing archives
> makes it seem that getting JSP output is difficult or
> impossible.  Does
> anyone have a better solution to my problem, so that I don't waste
> processing time only to send information off into the ether?
>
> Thanks,
> Ben
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>