Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timeout and retry issue with URLHTTPRequest

 
Yogesh Devatraj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to use asynchronous HTTP.
read this article and see if it will work for you
http://www.javaworld.com/javaworld/jw-03-2008/jw-03-asynchhttp.html


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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does it mean that there is no way to disable URLConnection's retry once on timeout behavior ?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"));
....
179
180 if (retryPost != null) {
181 retryPostProp = Boolean.valueOf(retryPost).booleanValue();
182 } else
183 retryPostProp = true;
184
185 }
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic