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.
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.
Joined: Apr 07, 2010
does it mean that there is no way to disable URLConnection's retry once on timeout behavior ?
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?
Joined: Apr 07, 2010
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