How can I set timeout for servlet response?
I work with resin servlet engine, but if it is impossible in resin, solutions for other engines also are welcome.
Of course, I can do this manualy (Timer, or just Thread with sleep()) but solution at config level is preferable.
For HTTP1.1 you can set status codes for response. (some browsers support for 1.0 also) You can call response.setStatus before sending any content via the PrintWriter.
For setting timeout , status code is "SC_GATEWAY_TIMEOUT" with value 504. You can call response.setStatus(504)for that. You call call response.sendError also. The advantage of sendError over setStatus is that, with sendError, the server automatically generates an error page showing the error message. In your case it will be :
response.sendError(response.SC_GATEWAY_TIMEOUT, "Timeout");[That doesn't answer the question directly; you still need to implement your own timeout in your servlet code before sending the 504 response. Is there a standard way to configure this irrespective of servlet code? -Alex]