由於這些類是如何構造的,我一直在處理這個問題。我不是Java專家,但它可能會幫助你,因爲我谷歌搜索幾天無濟於事。我不確定我們是否遇到了同樣的問題,但我偶爾會遇到'org.apache.http.NoHttpResponseException:目標服務器未能響應'在我的集成測試中,並且正在測試它,希望它能夠修復。
這可能是一種糟糕的做法,並沒有涵蓋所有入口點,但它可能適用於您。
子類HttpWebConnection一類叫做RetryHttpWebConnection並添加此覆蓋:
@Override
protected AbstractHttpClient createHttpClient() {
AbstractHttpClient client = super.createHttpClient();
// Set it to do some retrying in case of closed connection during test.
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(5, false));
return client;
}
子類Web客戶端,並在子類的構造函數中做到這一點:
// Override with new web connection that will do retries
// to avoid test failures due to network issues.
setWebConnection(new RetryHttpWebConnection(this));
編輯:我也期待爲http://pastebin.com/nmmRYqKN,這可能更適合我的特殊例外。
您可以使用yourWebClientVar.setTimeout(int timeout)設置超時; ...但我不知道如何停止基於重試號碼的連接,抱歉。 – XenoRo
我已經切換到HttpURLConnection來解決我的問題。 – user1375468