How to specify Http Request timeout parameter on Java servlet container

43,227

Solution 1

The timeout from a client (i.e. how long it waits for a response to an HTTP request) is determined at the client. For IE, see this, and for Firefox see this.

You can't control this timeout from the server.

Solution 2

Even though you can't control client timeout, you can make server very impatient :) For example, on Tomcat, you can do this in your connector,

<Connector port="8080"  
  ...
  connectionTimeout ="5000"
  disableUploadTimeout="false" />

This makes server only wait 5 seconds and close the connection. Browser will get a connection closed error. You can treat it the same as timeout in client.

Of course, this only works if the timeout is caused by the server, not connectivity issues between browser and server.

Solution 3

You cannot control the client timeout from the server. However you may be able to send data back to the client every now and then while your long running operation is busy. This will prevent the client from timing out and can be used to display progress to the user etc. Write data to the OutputStream or Writer obtained from the response and call flush to send partial data to the client.

Share:
43,227
Ittai
Author by

Ittai

Updated on July 29, 2020

Comments

  • Ittai
    Ittai almost 4 years

    I'm trying to understand where I can configure a request timeout for all requests arriving to a servlet of mine (or all of my servlets)? Is that, as I think, a container property? Also, how does this affect different browsers? Do they all comply to the parameter the container dictates? Or maybe the request timeout time isn't even something I can control and each browser decides on this on its own? (Just to be clear I'm not talking about session timeout)