找出HttpClient超时的系统默认值

时间:2014-08-29 11:40:48

标签: java timeout apache-httpclient-4.x

如何找出HttpClient 4.3的实际超时值?我知道如何明确地设置它们,但是如果我不覆盖它们,我想知道哪些值是隐式使用的。

实施例

import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.params.HttpParams;

public class HttpClientDefaults
{

    public static void main(String[] args)
    {       
        RequestConfig config = RequestConfig.custom().build();
        System.out.println("ConnectionRequestTimeout: " + config.getConnectionRequestTimeout());
        System.out.println("ConnectTimeout: " + config.getConnectTimeout());
        System.out.println("SocketTimeout: " + config.getSocketTimeout());
        CloseableHttpClient client = HttpClientBuilder.create().setRetryHandler(new DefaultHttpRequestRetryHandler()).build();
        HttpParams params = client.getParams();
        System.out.println(params.getParameter("http.socket.timeout"));
    }

}

输出

ConnectionRequestTimeout: -1
ConnectTimeout: -1
SocketTimeout: -1
Exception in thread "main" java.lang.UnsupportedOperationException

client.getParams()抛出java.lang.UnsupportedOperationException异常。有人知道一种方法来读出将要使用的实际值吗?

1 个答案:

答案 0 :(得分:0)

套接字,连接和连接请求超时的默认值为0(无超时)