2017-05-02 55 views
0

私は、以下の方法でのApacheのHttpClient 3.1とWebサービス・リクエストを実行しています:のApacheのHttpClient 3.1ソケットタイムアウト

private MultiThreadedHttpConnectionManager cm = null; 
private HttpClient client = null; 

// Setting up connection manager during init process 
cm = new MultiThreadedHttpConnectionManager(); 
int connectionTimeout = 12000; // it actually comes from config file, but this is the current value 
cm.getParams().setConnectionTimeout(connectionTimeout); 
cm.getParams().setTcpNoDelay(true); 
client = new HttpClient(cm); 

// method is prepared with request data earlier 
int socketTimeout = 30000; // it actually comes from config file, but this is the current value 
method.getParams().setSoTimeout(socketTimeout); 
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); 

logger.info("Starting request"); 
int statusCode = client.executeMethod(method); 
logger.info("StatusCode = " + statusCode); 
String response = method.getResponseBodyAsString(); 
logger.info("Response = " + response); 

ログファイルのタイムスタンプは、以下の通りである:

2017-05-02 08:50:03,881 Starting request 
2017-05-02 08:50:16,680 StatusCode = 200 
2017-05-02 08:50:46,708 java.net.SocketTimeoutException 

だから、たとえ接続タイムアウトは12秒に設定され、executeMethodコールはほぼ13秒かかりました。私はこれについて混乱しています。ドキュメントはここではっきりしていないので、executeMethodとgetResponseBodyAsStringの両方でソケットタイムアウトを個別に使用すると言っても間違いありませんか?だから、この場合、ソケットのタイムアウトは30秒なので、理論的には実行には60秒かかることがありますか?

答えて

2

接続タイムアウトは無関係です。ステータスコードが200で、接続が成功し、少なくとも一部のヘッダーを読み取ったことを意味します。 readタイムアウトは30秒に設定されています。つまり、サーバーは30秒以内に何も送信しませんでした。

+0

ありがとうございます。 –

関連する問題