jQuery in Action, 3rd edition
The moose likes Sockets and Internet Protocols and the fly likes Timeout and retry issue with URLHTTPRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Timeout and retry issue with URLHTTPRequest" Watch "Timeout and retry issue with URLHTTPRequest" New topic

Timeout and retry issue with URLHTTPRequest

Yogesh Devatraj

Joined: Apr 07, 2010
Posts: 3
In my code i have created one URLHTTPConnection to deployed servlet. Here the request is very long running process and my connection will waiting for response from Servlet. I am facing problem with timeout and re-try behavior of URLConnection. Before throwing soket exception , URlconnection retries by requesting once again with same input.

We have a security code validation mechanism at servlet side which validates every request. As URL Connection sending same request with old security token , it is getting rejected by Servlet because of security token's short life time.

Again this problem is corrupting server side data because of multiple invocation.

Please let me how to overcome this problem.

I need to know how to disable with re- invocation. I have tried setting longer readTimeout property but it is not working.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

You may want to use asynchronous HTTP.
read this article and see if it will work for you

At the message level, asynchronous message handling means that an HTTP client performs a request without waiting for the server response. In contrast, when performing a synchronous call, the caller thread is suspended until the server response returns or a timeout is exceeded. At the application level, code execution is stopped, waiting for the response before further actions can be taken.
Yogesh Devatraj

Joined: Apr 07, 2010
Posts: 3
does it mean that there is no way to disable URLConnection's retry once on timeout behavior ?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6382788

Non-idempotent http POST requests are being automatically resent to the server if the server does not respond with a valid http response or an IOException occurs. This is incorrect according to the rfc. Only idempotent requests are supposed to be automatically resent.

As this has been the behavior of Sun's http client forever, some users may be relying on this behavior without even knowing it. So the solution is to allow this behavior to be configured through a system property, sun.net.http.retryPost.

sun.net.http.retryPost determines if the an unsuccessful http POST request will be automatically resent to the server. Unsuccessful in this case means the server did not send a valid http response or an IOException occurred. The default value is true to maintain backward compatibility.

does that help?
Yogesh Devatraj

Joined: Apr 07, 2010
Posts: 3
i have tried by setting System property sun.net.http.retryPost to false, but still retry is happening after fixed time . I have set System property using
System.getProperties().setProperty("sun.net.http.retryPost", "false" );
before opening the connection

am i missing something ?
Please help me
bernard berny

Joined: Dec 18, 2012
Posts: 1
You should better set property in command line of JVM (-Dsun.net.http.retryPost=false).

because httClient (http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/2d585507a41b/src/share/classes/sun/net/www/http/HttpClient.java)
use a static way to set this flag :
static {
171 String retryPost = java.security.AccessController.doPrivileged(
172 new sun.security.action.GetPropertyAction("sun.net.http.retryPost"));
180 if (retryPost != null) {
181 retryPostProp = Boolean.valueOf(retryPost).booleanValue();
182 } else
183 retryPostProp = true;
185 }
I agree. Here's the link: http://aspose.com/file-tools
subject: Timeout and retry issue with URLHTTPRequest
It's not a secret anymore!