Skip to content

Commits on Source 5

Release 4.5.10
-------------------
This is a maintenance release that fixes a number defects discovered since 4.5.9
and upgrades HttpCore dependency to version 4.4.12.
Changelog:
-------------------
* Refactor DefaultRedirectStrategy for subclassing.
Contributed by Gary Gregory <ggregory at apache.org>
* Improved handling of request cancellation.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* Fixed concurrent use of threading unsafe HttpUriRequest messages.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* HTTPCLIENT-1997: Return the last domain segment instead of normalized domain name
from PublicSuffixMatcher#getDomainRoot in case there is no match.
Contributed by jeromedemangel <jeromedemangel at gmail.com>
* Preserve original encoding of the URI path component if the URI is valid.
Contributed by Oleg Kalnichevski <olegk at apache.org>
Release 4.5.9
-------------------
......
httpcomponents-client (4.5.10-1) unstable; urgency=medium
* New upstream release
* Standards-Version updated to 4.4.1
-- Emmanuel Bourg <ebourg@apache.org> Sat, 05 Oct 2019 10:27:06 +0200
httpcomponents-client (4.5.9-1) unstable; urgency=medium
* Team upload.
......
......@@ -18,7 +18,7 @@ Build-Depends:
libmaven-javadoc-plugin-java,
libmockito-java,
maven-debian-helper
Standards-Version: 4.3.0
Standards-Version: 4.4.1
Vcs-Git: https://salsa.debian.org/java-team/httpcomponents-client.git
Vcs-Browser: https://salsa.debian.org/java-team/httpcomponents-client
Homepage: http://hc.apache.org/httpcomponents-client-ga/index.html
......
......@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcomponents-client</artifactId>
<version>4.5.9</version>
<version>4.5.10</version>
</parent>
<artifactId>fluent-hc</artifactId>
<name>Apache HttpClient Fluent API</name>
......
......@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcomponents-client</artifactId>
<version>4.5.9</version>
<version>4.5.10</version>
</parent>
<artifactId>httpclient-cache</artifactId>
<name>Apache HttpClient Cache</name>
......
......@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcomponents-client</artifactId>
<version>4.5.9</version>
<version>4.5.10</version>
</parent>
<artifactId>httpclient-osgi</artifactId>
<name>Apache HttpClient OSGi bundle</name>
......
......@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcomponents-client</artifactId>
<version>4.5.9</version>
<version>4.5.10</version>
</parent>
<artifactId>httpclient-win</artifactId>
<name>Apache HttpClient Windows features</name>
......
......@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcomponents-client</artifactId>
<version>4.5.9</version>
<version>4.5.10</version>
</parent>
<artifactId>httpclient</artifactId>
<name>Apache HttpClient</name>
......
......@@ -264,11 +264,10 @@ public class RequestConfig implements Cloneable {
/**
* Returns the timeout in milliseconds used when requesting a connection
* from the connection manager. A timeout value of zero is interpreted
* as an infinite timeout.
* from the connection manager.
* <p>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* A negative value is interpreted as undefined (system default if applicable).
* </p>
* <p>
* Default: {@code -1}
......@@ -280,10 +279,9 @@ public class RequestConfig implements Cloneable {
/**
* Determines the timeout in milliseconds until a connection is established.
* A timeout value of zero is interpreted as an infinite timeout.
* <p>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* A negative value is interpreted as undefined (system default if applicable).
* </p>
* <p>
* Default: {@code -1}
......@@ -299,7 +297,7 @@ public class RequestConfig implements Cloneable {
* a maximum period inactivity between two consecutive data packets).
* <p>
* A timeout value of zero is interpreted as an infinite timeout.
* A negative value is interpreted as undefined (system default).
* A negative value is interpreted as undefined (system default if applicable).
* </p>
* <p>
* Default: {@code -1}
......
......@@ -27,8 +27,7 @@
package org.apache.http.client.methods;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicMarkableReference;
import org.apache.http.HttpRequest;
import org.apache.http.client.utils.CloneUtils;
......@@ -41,13 +40,11 @@ import org.apache.http.message.AbstractHttpMessage;
public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage implements
HttpExecutionAware, AbortableHttpRequest, Cloneable, HttpRequest {
private final AtomicBoolean aborted;
private final AtomicReference<Cancellable> cancellableRef;
private final AtomicMarkableReference<Cancellable> cancellableRef;
protected AbstractExecutionAwareRequest() {
super();
this.aborted = new AtomicBoolean(false);
this.cancellableRef = new AtomicReference<Cancellable>(null);
this.cancellableRef = new AtomicMarkableReference<Cancellable>(null, false);
}
/**
......@@ -90,17 +87,19 @@ public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage
@Override
public void abort() {
if (this.aborted.compareAndSet(false, true)) {
final Cancellable cancellable = this.cancellableRef.getAndSet(null);
if (cancellable != null) {
cancellable.cancel();
while (!cancellableRef.isMarked()) {
final Cancellable actualCancellable = cancellableRef.getReference();
if (cancellableRef.compareAndSet(actualCancellable, actualCancellable, false, true)) {
if (actualCancellable != null) {
actualCancellable.cancel();
}
}
}
}
@Override
public boolean isAborted() {
return this.aborted.get();
return this.cancellableRef.isMarked();
}
/**
......@@ -108,8 +107,9 @@ public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage
*/
@Override
public void setCancellable(final Cancellable cancellable) {
if (!this.aborted.get()) {
this.cancellableRef.set(cancellable);
final Cancellable actualCancellable = cancellableRef.getReference();
if (!cancellableRef.compareAndSet(actualCancellable, cancellable, false, false)) {
cancellable.cancel();
}
}
......@@ -123,9 +123,12 @@ public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage
/**
* @since 4.2
*
* @deprecated Do not use.
*/
@Deprecated
public void completed() {
this.cancellableRef.set(null);
this.cancellableRef.set(null, false);
}
/**
......@@ -134,11 +137,16 @@ public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage
* @since 4.2
*/
public void reset() {
final Cancellable cancellable = this.cancellableRef.getAndSet(null);
if (cancellable != null) {
cancellable.cancel();
for (;;) {
final boolean marked = cancellableRef.isMarked();
final Cancellable actualCancellable = cancellableRef.getReference();
if (actualCancellable != null) {
actualCancellable.cancel();
}
if (cancellableRef.compareAndSet(actualCancellable, null, marked, false)) {
break;
}
}
this.aborted.set(false);
}
}
......@@ -217,15 +217,18 @@ public class URIUtils {
uribuilder.setFragment(null);
}
if (flags.contains(UriFlag.NORMALIZE)) {
final List<String> pathSegments = new ArrayList<String>(uribuilder.getPathSegments());
final List<String> originalPathSegments = uribuilder.getPathSegments();
final List<String> pathSegments = new ArrayList<String>(originalPathSegments);
for (final Iterator<String> it = pathSegments.iterator(); it.hasNext(); ) {
final String pathSegment = it.next();
if (pathSegment.isEmpty() && it.hasNext()) {
it.remove();
}
}
if (pathSegments.size() != originalPathSegments.size()) {
uribuilder.setPathSegments(pathSegments);
}
}
if (uribuilder.isPathEmpty()) {
uribuilder.setPathSegments("");
}
......
......@@ -166,7 +166,7 @@ public final class PublicSuffixMatcher {
result = segment;
segment = nextSegment;
}
return normalized;
return result;
}
/**
......
......@@ -44,13 +44,12 @@ public class DefaultBackoffStrategy implements ConnectionBackoffStrategy {
@Override
public boolean shouldBackoff(final Throwable t) {
return (t instanceof SocketTimeoutException
|| t instanceof ConnectException);
return t instanceof SocketTimeoutException || t instanceof ConnectException;
}
@Override
public boolean shouldBackoff(final HttpResponse resp) {
return (resp.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE);
return resp.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE;
}
}
......@@ -29,6 +29,7 @@ package org.apache.http.impl.client;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
......@@ -81,16 +82,26 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
public static final DefaultRedirectStrategy INSTANCE = new DefaultRedirectStrategy();
/**
* Redirectable methods.
*/
private static final String[] REDIRECT_METHODS = new String[] {
private final String[] redirectMethods;
public DefaultRedirectStrategy() {
this(new String[] {
HttpGet.METHOD_NAME,
HttpHead.METHOD_NAME
};
});
}
public DefaultRedirectStrategy() {
/**
* Constructs a new instance to redirect the given HTTP methods.
*
* @param redirectMethods The methods to redirect.
* @since 4.5.10
*/
public DefaultRedirectStrategy(final String[] redirectMethods) {
super();
final String[] tmp = redirectMethods.clone();
Arrays.sort(tmp);
this.redirectMethods = tmp;
}
@Override
......@@ -198,12 +209,7 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
* @since 4.2
*/
protected boolean isRedirectable(final String method) {
for (final String m: REDIRECT_METHODS) {
if (m.equalsIgnoreCase(method)) {
return true;
}
}
return false;
return Arrays.binarySearch(redirectMethods, method) >= 0;
}
@Override
......
......@@ -47,24 +47,13 @@ public class LaxRedirectStrategy extends DefaultRedirectStrategy {
public static final LaxRedirectStrategy INSTANCE = new LaxRedirectStrategy();
/**
* Redirectable methods.
*/
private static final String[] REDIRECT_METHODS = new String[] {
public LaxRedirectStrategy() {
super(new String[] {
HttpGet.METHOD_NAME,
HttpPost.METHOD_NAME,
HttpHead.METHOD_NAME,
HttpDelete.METHOD_NAME
};
@Override
protected boolean isRedirectable(final String method) {
for (final String m: REDIRECT_METHODS) {
if (m.equalsIgnoreCase(method)) {
return true;
}
}
return false;
});
}
}
......@@ -240,6 +240,8 @@ vic.au
wa.au
// 3LDs
act.edu.au
catholic.edu.au
eq.edu.au
nsw.edu.au
nt.edu.au
qld.edu.au
......@@ -255,6 +257,9 @@ sa.gov.au
tas.gov.au
vic.gov.au
wa.gov.au
// 4LDs
education.tas.edu.au
schools.nsw.edu.au
// aw : https://en.wikipedia.org/wiki/.aw
aw
......@@ -4334,8 +4339,6 @@ niepce.museum
norfolk.museum
north.museum
nrw.museum
nuernberg.museum
nuremberg.museum
nyc.museum
nyny.museum
oceanographic.museum
......@@ -6044,6 +6047,16 @@ org.so
// sr : https://en.wikipedia.org/wiki/.sr
sr
// ss : https://registry.nic.ss/
// Submitted by registry <technical@nic.ss>
ss
biz.ss
com.ss
edu.ss
gov.ss
net.ss
org.ss
// st : http://www.nic.st/html/policyrules/
st
co.st
......@@ -6786,6 +6799,9 @@ yt
// xn--e1a4c ("eu", Cyrillic) : EU
ею
// xn--mgbah1a3hjkrd ("Mauritania", Arabic) : MR
موريتانيا
// xn--node ("ge", Georgian Mkhedruli) : GE
გე
......@@ -7012,7 +7028,7 @@ xxx
// ye : http://www.y.net.ye/services/domain_name.htm
*.ye
// za : http://www.zadna.org.za/content/page/domain-information
// za : https://www.zadna.org.za/content/page/domain-information/
ac.za
agric.za
alt.za
......@@ -7024,6 +7040,7 @@ law.za
mil.za
net.za
ngo.za
nic.za
nis.za
nom.za
org.za
......@@ -7058,7 +7075,7 @@ org.zw
// newGTLDs
// List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2019-06-14T10:00:50-04:00
// List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2019-09-26T16:43:02Z
// This list is auto-generated, don't edit it manually.
// aaa : 2015-02-26 American Automobile Association, Inc.
aaa
......@@ -7423,9 +7440,6 @@ bms
// bmw : 2014-01-09 Bayerische Motoren Werke Aktiengesellschaft
bmw
// bnl : 2014-07-24 Banca Nazionale del Lavoro
bnl
// bnpparibas : 2014-05-29 BNP Paribas
bnpparibas
......@@ -7738,7 +7752,7 @@ community
// company : 2013-11-07 Binky Moon, LLC
company
// compare : 2015-10-08 iSelect Ltd
// compare : 2015-10-08 Registry Services, LLC
compare
// computer : 2013-10-24 Binky Moon, LLC
......@@ -7966,9 +7980,6 @@ duck
// dunlop : 2015-07-02 The Goodyear Tire & Rubber Company
dunlop
// duns : 2015-08-06 The Dun & Bradstreet Corporation
duns
// dupont : 2015-06-25 E. I. du Pont de Nemours and Company
dupont
......@@ -8083,7 +8094,7 @@ family
// fan : 2014-03-06 Dog Beach, LLC
fan
// fans : 2014-11-07 Fans TLD Limited
// fans : 2014-11-07 ZDNS International Limited
fans
// farm : 2013-11-07 Binky Moon, LLC
......@@ -8479,9 +8490,6 @@ homesense
// honda : 2014-12-18 Honda Motor Co., Ltd.
honda
// honeywell : 2015-07-23 Honeywell GTLD LLC
honeywell
// horse : 2013-11-21 Minds + Machines Group Limited
horse
......@@ -8599,9 +8607,6 @@ ipiranga
// irish : 2014-08-07 Binky Moon, LLC
irish
// iselect : 2015-02-11 iSelect Ltd
iselect
// ismaili : 2015-08-06 Fondation Aga Khan (Aga Khan Foundation)
ismaili
......@@ -8863,6 +8868,9 @@ lixil
// llc : 2017-12-14 Afilias Limited
llc
// llp : 2019-08-26 Dot Registry LLC
llp
// loan : 2014-11-20 dot Loan Limited
loan
......@@ -9031,9 +9039,6 @@ mma
// mobile : 2016-06-02 Dish DBS Corporation
mobile
// mobily : 2014-12-18 GreenTech Consultancy Company W.L.L.
mobily
// moda : 2013-11-07 Dog Beach, LLC
moda
......@@ -9508,7 +9513,7 @@ reit
// reliance : 2015-04-02 Reliance Industries Limited
reliance
// ren : 2013-12-12 Beijing Qianxiang Wangjing Technology Development Co., Ltd.
// ren : 2013-12-12 ZDNS International Limited
ren
// rent : 2014-12-04 XYZ.COM LLC
......@@ -9703,7 +9708,7 @@ security
// seek : 2014-12-04 Seek Limited
seek
// select : 2015-10-08 iSelect Ltd
// select : 2015-10-08 Registry Services, LLC
select
// sener : 2014-10-24 Sener Ingeniería y Sistemas, S.A.
......@@ -9835,6 +9840,9 @@ sony
// soy : 2014-01-23 Charleston Road Registry Inc.
soy
// spa : 2019-09-19 Asia Spa and Wellness Promotion Council Limited
spa
// space : 2014-04-03 DotSpace Inc.
space
......@@ -9862,9 +9870,6 @@ staples
// star : 2015-01-08 Star India Private Limited
star
// starhub : 2015-02-05 StarHub Ltd
starhub
// statebank : 2015-03-12 STATE BANK OF INDIA
statebank
......@@ -10126,7 +10131,7 @@ unicom
// university : 2014-03-06 Binky Moon, LLC
university
// uno : 2013-09-11 Dot Latin LLC
// uno : 2013-09-11 DotSite Inc.
uno
// uol : 2014-05-01 UBN INTERNET LTDA.
......@@ -10528,9 +10533,6 @@ xin
// xn--mgbab2bd : 2013-10-31 CORE Association
بازار
// xn--mgbb9fbpob : 2014-12-18 GreenTech Consultancy Company W.L.L.
موبايلي
// xn--mgbca7dzdo : 2015-07-30 Abu Dhabi Systems and Information Centre
ابوظبي
......@@ -10702,6 +10704,10 @@ barsy.ca
*.compute.estate
*.alces.network
// Altervista: https://www.altervista.org
// Submitted by Carlo Cannas <tech_staff@altervista.it>
altervista.org
// alwaysdata : https://www.alwaysdata.com
// Submitted by Cyril <admin@alwaysdata.com>
alwaysdata.net
......@@ -10815,6 +10821,12 @@ apigee.io
// Submitted by Thomas Orozco <thomas@aptible.com>
on-aptible.com
// ASEINet : https://www.aseinet.com/
// Submitted by Asei SEKIGUCHI <mail@aseinet.com>
user.aseinet.ne.jp
gv.vc
d.gv.vc
// Asociación Amigos de la Informática "Euskalamiga" : http://encounter.eus/
// Submitted by Hector Martin <marcan@euskalencounter.org>
user.party.eus
......@@ -11778,6 +11790,10 @@ gitlab.io
// Submitted by Mads Hartmann <mads@glitch.com>
glitch.me
// GMO Pepabo, Inc. : https://pepabo.com/
// Submitted by dojineko <admin@pepabo.com>
lolipop.io
// GOV.UK Platform as a Service : https://www.cloud.service.gov.uk/
// Submitted by Tom Whitwell <tom.whitwell@digital.cabinet-office.gov.uk>
cloudapps.digital
......@@ -11930,11 +11946,13 @@ ravendb.run
bpl.biz
orx.biz
ng.city
ng.ink
biz.gl
ng.ink
col.ng
firm.ng
gen.ng
ltd.ng
ng.school
sch.so
// Häkkinen.fi
......@@ -12070,6 +12088,10 @@ leadpages.co
lpages.co
lpusercontent.com
// Lelux.fi : https://lelux.fi/
// Submitted by Lelux Admin <publisuffix@lelux.site>
lelux.site
// Lifetime Hosting : https://Lifetime.Hosting/
// Submitted by Mike Fillator <support@lifetime.hosting>
co.business
......@@ -12401,12 +12423,14 @@ nom.al
nym.by
nym.bz
nom.cl
nym.ec
nom.gd
nom.ge
nom.gl
nym.gr
nom.gt
nym.gy
nym.hk
nom.hn
nym.ie
nom.im
......@@ -12658,11 +12682,6 @@ my-firewall.org
myfirewall.org
spdns.org
// SensioLabs, SAS : https://sensiolabs.com/
// Submitted by Fabien Potencier <fabien.potencier@sensiolabs.com>
*.s5y.io
*.sensiosite.cloud
// Service Online LLC : http://drs.ua/
// Submitted by Serhii Bulakh <support@drs.ua>
biz.ua
......@@ -12752,6 +12771,11 @@ temp-dns.com
applicationcloud.io
scapp.io
// Symfony, SAS : https://symfony.com/
// Submitted by Fabien Potencier <fabien@symfony.com>
*.s5y.io
*.sensiosite.cloud
// Syncloud : https://syncloud.org
// Submitted by Boris Rybalkin <syncloud@syncloud.it>
syncloud.it
......@@ -12772,6 +12796,7 @@ i234.me
myds.me
synology.me
vpnplus.to
direct.quickconnect.to
// TAIFUN Software AG : http://taifun-software.de
// Submitted by Bjoern Henke <dev-server@taifun-software.de>
......@@ -12905,6 +12930,10 @@ voorloper.cloud
// Submitted by Masayuki Note <masa@blade.wafflecell.com>
wafflecell.com
// WebHare bv: https://www.webhare.com/
// Submitted by Arnold Hendriks <info@webhare.com>
*.webhare.dev
// WeDeploy by Liferay, Inc. : https://www.wedeploy.com
// Submitted by Henrique Vicente <security@wedeploy.com>
wedeploy.io
......@@ -12935,6 +12964,12 @@ cistron.nl
demon.nl
xs4all.space
// Yandex.Cloud LLC: https://cloud.yandex.com
// Submitted by Alexander Lodin <security+psl@yandex-team.ru>
yandexcloud.net
storage.yandexcloud.net
website.yandexcloud.net
// YesCourse Pty Ltd : https://yescourse.com
// Submitted by Atul Bhouraskar <atul@yescourse.com>
official.academy
......@@ -12978,8 +13013,4 @@ virtualserver.io
site.builder.nu
enterprisecloud.nu
// Zone.id : https://zone.id/
// Submitted by Su Hendro <admin@zone.id>
zone.id
// ===END PRIVATE DOMAINS===
......@@ -82,6 +82,8 @@ public class TestURIUtils {
Assert.assertEquals("http://thishost/Fragment_identifier%23Examples",
URIUtils.rewriteURI(
URI.create("http://thishost/Fragment_identifier%23Examples")).toString());
Assert.assertEquals("http://thathost/foo%3Abar", URIUtils.rewriteURI(
URI.create("http://thishost/foo%3Abar"), target).toString());
}
@Test
......
......@@ -275,6 +275,18 @@ public class TestDefaultHostnameVerifier {
Assert.assertTrue(DefaultHostnameVerifier.matchIdentityStrict("mail.a.b.c.com", "m*.a.b.c.com"));
}
@Test
public void testHTTPCLIENT_1997() {
Assert.assertTrue(DefaultHostnameVerifier.matchIdentity(
"service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a"));
Assert.assertTrue(DefaultHostnameVerifier.matchIdentityStrict(
"service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a"));
Assert.assertTrue(DefaultHostnameVerifier.matchIdentity(
"service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a", publicSuffixMatcher));
Assert.assertTrue(DefaultHostnameVerifier.matchIdentityStrict(
"service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a", publicSuffixMatcher));
}
@Test // Check compressed IPv6 hostname matching
public void testHTTPCLIENT_1316() throws Exception{
final String host1 = "2001:0db8:aaaa:bbbb:cccc:0:0:0001";
......
......@@ -69,7 +69,9 @@ public class TestPublicSuffixMatcher {
Assert.assertEquals("blah.blah.tokyo.jp", matcher.getDomainRoot("blah.blah.tokyo.jp"));
Assert.assertEquals("blah.ac.jp", matcher.getDomainRoot("blah.blah.ac.jp"));
Assert.assertEquals("garbage", matcher.getDomainRoot("garbage"));
Assert.assertEquals("garbage.garbage", matcher.getDomainRoot("garbage.garbage"));
Assert.assertEquals("garbage", matcher.getDomainRoot("garbage.garbage"));
Assert.assertEquals("garbage", matcher.getDomainRoot("*.garbage.garbage"));
Assert.assertEquals("garbage", matcher.getDomainRoot("*.garbage.garbage.garbage"));
}
@Test
......
......@@ -27,14 +27,14 @@
package org.apache.http.impl.client.integration;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.IdleConnectionEvictor;
import org.apache.http.localserver.LocalServerTestBase;
import org.apache.http.util.EntityUtils;
......@@ -53,10 +53,10 @@ public class TestIdleConnectionEviction extends LocalServerTestBase {
this.connManager, 50, TimeUnit.MILLISECONDS);
idleConnectionMonitor.start();
final HttpGet httpget = new HttpGet("/random/1024");
final URI requestUri = new URI("/random/1024");
final WorkerThread[] workers = new WorkerThread[5];
for (int i = 0; i < workers.length; i++) {
workers[i] = new WorkerThread(httpclient, target, httpget, 200);
workers[i] = new WorkerThread(httpclient, target, requestUri, 200);
}
for (final WorkerThread worker : workers) {
worker.start();
......@@ -73,22 +73,22 @@ public class TestIdleConnectionEviction extends LocalServerTestBase {
static class WorkerThread extends Thread {
private final HttpClient httpclient;
private final CloseableHttpClient httpclient;
private final HttpHost target;
private final HttpUriRequest request;
private final URI requestUri;
private final int count;
private volatile Exception ex;
public WorkerThread(
final HttpClient httpclient,
final CloseableHttpClient httpclient,
final HttpHost target,
final HttpUriRequest request,
final URI requestUri,
final int count) {
super();
this.httpclient = httpclient;
this.target = target;
this.request = request;
this.requestUri = requestUri;
this.count = count;
}
......@@ -96,14 +96,18 @@ public class TestIdleConnectionEviction extends LocalServerTestBase {
public void run() {
try {
for (int i = 0; i < this.count; i++) {
final HttpResponse response = this.httpclient.execute(this.target, this.request);
final HttpGet httpget = new HttpGet(this.requestUri);
final CloseableHttpResponse response = this.httpclient.execute(this.target, httpget);
try {
final int status = response.getStatusLine().getStatusCode();
if (status != 200) {
this.request.abort();
throw new ClientProtocolException("Unexpected status code: " + status);
}
EntityUtils.consume(response.getEntity());
Thread.sleep(10);
} finally {
response.close();
}
}
} catch (final Exception ex) {
this.ex = ex;
......