[EMAIL PROTECTED] wrote:
Hello,
I am using httpclient 3.1. I am trying to make a http request that should
timeout when a response is not revceived within 2 minutes.
See definition of the socket timeout
Oleg
The requirement
is also to retry 3 times before throwing back an application exception.
When I set the socket timeout to >90,000 milliseconds, the timeout never
works. Sometimes, I see the connection waiting for more than 2 mins for a
response instead of throwing a SocketTimeoutException. Below is the code
sample that I am using to make the HttpRequest.
String proxyPortNumber=
(String)PropertiesUtil.getIonProps().getProperty(IonConstants.PROXYPORT);
String proxyServer =
(String)PropertiesUtil.getIonProps().getProperty(IonConstants.PROXYSERVER);
HttpClient client = new HttpClient();
client.getHostConfiguration().setProxy(proxyServer,
Integer.parseInt(proxyPortNumber));
Integer connWaitTime=new Integer("120000");
PostMethod postMethod = new PostMethod(url);
HttpMethodRetryHandler retryhandler = new
HttpMethodRetryHandler() {
public boolean retryMethod(
final HttpMethod method,
final IOException exception,
int executionCount) {
if (executionCount >= 3) {
// Do not retry if over max retry
count
return false;
}
System.out.println("Retrying Request::" +
executionCount);
if (exception instanceof
java.net.SocketTimeoutException) {
// Retry if the server dropped
connection on us
return true;
}
if (!method.isRequestSent()) {
// Retry if the request has not
been sent fully or
// if it's OK to retry methods
that have been sent
return true;
}
// otherwise do not retry
return false;
}
};
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
retryhandler);
//client.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,connWaitTime);
postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,connWaitTime);
System.out.println("ConnWaitTime ::" +
postMethod.getParams().getParameter(HttpMethodParams.SO_TIMEOUT));
postMethod.setRequestEntity(new
StringRequestEntity(xmlData, null, null));
postMethod.setRequestHeader("Content-type",
"text/xml");
int responseCode =
client.executeMethod(postMethod);
BufferedReader rd = new BufferedReader(new
InputStreamReader(postMethod.getResponseBodyAsStream()));
String line;
while ((line = rd.readLine()) != null)
{
response += line + "\n";
}
//System.out.println("responseBody " +
responseBody);
postMethod.releaseConnection();
I hope you can help me.
Thanks
-----------------------------------------
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]