Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DE018200B49 for ; Mon, 13 Jun 2016 11:51:27 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DCC4B160A19; Mon, 13 Jun 2016 09:51:27 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2C39C160A3C for ; Mon, 13 Jun 2016 11:51:27 +0200 (CEST) Received: (qmail 7328 invoked by uid 500); 13 Jun 2016 09:51:21 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 7175 invoked by uid 99); 13 Jun 2016 09:51:21 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Jun 2016 09:51:21 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 1081B2C1F68 for ; Mon, 13 Jun 2016 09:51:21 +0000 (UTC) Date: Mon, 13 Jun 2016 09:51:21 +0000 (UTC) From: "Christoffer Eide (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (HTTPCLIENT-1747) The "default request config" socket timeout is set to 0 if the deprecated HttpClientParams is used MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 13 Jun 2016 09:51:28 -0000 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Christoffer Eide closed HTTPCLIENT-1747. ---------------------------------------- Resolution: Fixed Looks good. Thanks! :) > The "default request config" socket timeout is set to 0 if the deprecated HttpClientParams is used > -------------------------------------------------------------------------------------------------- > > Key: HTTPCLIENT-1747 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1747 > Project: HttpComponents HttpClient > Issue Type: Bug > Affects Versions: 4.5.2 > Reporter: Christoffer Eide > Priority: Minor > Fix For: 4.5.3 > > > We have some legacy library code that uses the http client. > We pass in a well configured http client (with connection and socket timeouts) to the library. > The library calls the deprecated {{org.apache.http.client.params.HttpClientParams}}. This causes the timeouts to be set to 0 when the clients tries to connect to a socket. > The library calls: > {{HttpClientParams.setRedirecting(get.getParams(), true);}} > This makes the {{org.apache.http.impl.client.InternalHttpClient#doExecute}} call {{HttpClientParamConfig.getRequestConfig(params)}}. If {{HttpClientParamConfig}} does not find a value for the timeouts in {{params}}, it defaults to {{0}}. Perhaps it should get those default values from the configured default request config? > There is a junit test that demonstrates the behaviour: > {code:lang=java} > import org.apache.http.HttpHost; > import org.apache.http.client.config.RequestConfig; > import org.apache.http.client.methods.CloseableHttpResponse; > import org.apache.http.client.methods.HttpGet; > import org.apache.http.client.params.HttpClientParams; > import org.apache.http.config.SocketConfig; > import org.apache.http.conn.socket.LayeredConnectionSocketFactory; > import org.apache.http.conn.ssl.SSLConnectionSocketFactory; > import org.apache.http.impl.client.CloseableHttpClient; > import org.apache.http.impl.client.HttpClientBuilder; > import org.apache.http.protocol.HttpContext; > import org.junit.After; > import org.junit.Before; > import org.junit.Test; > import java.io.IOException; > import java.net.InetSocketAddress; > import java.net.Socket; > import java.net.UnknownHostException; > import static org.junit.Assert.assertEquals; > public final class HttpClientTest { > CloseableHttpClient client; > @Before > public void setUp() throws Exception { > final int timeout = 100; > SocketConfig socketConfig = SocketConfig.custom() > .setSoTimeout(timeout) > .build(); > RequestConfig requestConfig = RequestConfig.custom() > .setConnectionRequestTimeout(timeout) > .setConnectTimeout(timeout) > .setSocketTimeout(timeout) > .build(); > client = HttpClientBuilder.create() > .setDefaultSocketConfig(socketConfig) > .setDefaultRequestConfig(requestConfig) > .setSSLSocketFactory(new LayeredConnectionSocketFactory() { > @Override > public Socket createLayeredSocket(Socket socket, String target, int port, HttpContext context) throws IOException, UnknownHostException { > return SSLConnectionSocketFactory.getSystemSocketFactory() > .createLayeredSocket(socket, target, port, context); > } > @Override > public Socket createSocket(HttpContext context) throws IOException { > return SSLConnectionSocketFactory.getSystemSocketFactory() > .createSocket(context); > } > @Override > public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException { > assertEquals(connectTimeout, timeout); > throw new RuntimeException("expected"); > } > }) > .build(); > } > @After > public void tearDown() throws Exception { > client.close(); > } > @Test(expected = RuntimeException.class) > public void timeoutsIsCleared() throws Exception { > HttpGet get = new HttpGet("https://google.com"); > HttpClientParams.setRedirecting(get.getParams(), true); > try(CloseableHttpResponse response = client.execute(get)){ > } > } > @Test(expected = RuntimeException.class) > public void timeoutsIsRetained() throws Exception { > HttpGet get = new HttpGet("https://google.com"); > try(CloseableHttpResponse response = client.execute(get)){ > > } > } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org