Skip to content

Commit 6e96338

Browse files
author
eugenp
committed
http async client cleanup
1 parent bbe2806 commit 6e96338

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎httpclient/pom.xml‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
32
<modelVersion>4.0.0</modelVersion>
43
<groupId>org.baeldung</groupId>
54
<artifactId>httpclient</artifactId>
@@ -36,11 +35,11 @@
3635
</exclusion>
3736
</exclusions>
3837
</dependency>
39-
<dependency>
40-
<groupId>org.apache.httpcomponents</groupId>
41-
<artifactId>httpcore</artifactId>
42-
<version>${httpcore.version}</version>
43-
</dependency>
38+
<!-- <dependency> -->
39+
<!-- <groupId>org.apache.httpcomponents</groupId> -->
40+
<!-- <artifactId>httpcore</artifactId> -->
41+
<!-- <version>${httpcore.version}</version> -->
42+
<!-- </dependency> -->
4443

4544
<dependency>
4645
<groupId>org.apache.httpcomponents</groupId>
@@ -61,9 +60,9 @@
6160
</dependency>
6261

6362
<dependency>
64-
<groupId>org.apache.httpcomponents</groupId>
65-
<artifactId>httpasyncclient</artifactId>
66-
<version>4.1-beta1</version>
63+
<groupId>org.apache.httpcomponents</groupId>
64+
<artifactId>httpasyncclient</artifactId>
65+
<version>4.1-beta1</version> <!-- 4.0.2 --> <!-- 4.1-beta1 -->
6766
</dependency>
6867

6968
<!-- logging -->
@@ -179,7 +178,7 @@
179178
<mockito.version>1.10.8</mockito.version>
180179

181180
<httpcore.version>4.3.3</httpcore.version>
182-
<httpclient.version>4.3.6</httpclient.version>
181+
<httpclient.version>4.4-beta1</httpclient.version> <!-- 4.3.6 --> <!-- 4.4-beta1 -->
183182

184183
<rest-assured.version>2.4.0</rest-assured.version>
185184

‎httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientTest.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import static org.hamcrest.Matchers.equalTo;
44
import static org.junit.Assert.assertThat;
55

6+
import java.io.IOException;
67
import java.security.cert.X509Certificate;
8+
import java.util.concurrent.ExecutionException;
79
import java.util.concurrent.Future;
810

911
import javax.net.ssl.SSLContext;
@@ -44,14 +46,17 @@ public class HttpAsyncClientTest {
4446
private static final String COOKIE_DOMAIN = ".yuilibrary.com"; // ".github.com";
4547
private static final String COOKIE_NAME = "example"; // "JSESSIONID";
4648

49+
// tests
4750

4851
@Test
49-
public void whenUseHttpAsyncClient_thenCorrect() throws Exception {
52+
public void whenUseHttpAsyncClient_thenCorrect() throws InterruptedException, ExecutionException, IOException {
5053
final CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
51-
client.start();
54+
// client.start();
5255
final HttpGet request = new HttpGet(HOST);
56+
5357
final Future<HttpResponse> future = client.execute(request, null);
5458
final HttpResponse response = future.get();
59+
5560
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
5661
client.close();
5762
}
@@ -114,7 +119,6 @@ public final boolean isTrusted(final X509Certificate[] certificate, final String
114119
client.close();
115120
}
116121

117-
118122
@Test
119123
public void whenUseCookiesWithHttpAsyncClient_thenCorrect() throws Exception {
120124
final BasicCookieStore cookieStore = new BasicCookieStore();
@@ -138,8 +142,8 @@ public void whenUseCookiesWithHttpAsyncClient_thenCorrect() throws Exception {
138142
@Test
139143
public void whenUseAuthenticationWithHttpAsyncClient_thenCorrect() throws Exception {
140144
final CredentialsProvider provider = new BasicCredentialsProvider();
141-
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS);
142-
provider.setCredentials(AuthScope.ANY, credentials);
145+
final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS);
146+
provider.setCredentials(AuthScope.ANY, creds);
143147
final CloseableHttpAsyncClient client = HttpAsyncClients.custom().setDefaultCredentialsProvider(provider).build();
144148

145149
final HttpGet request = new HttpGet(URL_SECURED_BY_BASIC_AUTHENTICATION);
@@ -175,4 +179,3 @@ public void run() {
175179

176180
}
177181
}
178-

0 commit comments

Comments
 (0)