• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timeout and retry issue with URLHTTPRequest

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 }
 
reply
    Bookmark Topic Watch Topic
  • New Topic