Skip to content

Commit 3f11433

Browse files
author
Stephane Landelle
committed
Clean up reconnectsAfterFailedCertificationPath, see AsyncHttpClient#810
1 parent 88628f8 commit 3f11433

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,23 @@ public void multipleSSLWithoutCacheTest() throws Exception {
8484

8585
@Test(groups = { "standalone", "default_provider" })
8686
public void reconnectsAfterFailedCertificationPath() throws Exception {
87-
AtomicBoolean trusted = new AtomicBoolean(false);
88-
try (AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build())) {
87+
88+
AtomicBoolean trust = new AtomicBoolean(false);
89+
try (AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trust)).build())) {
8990
String body = "hello there";
9091

9192
// first request fails because server certificate is rejected
9293
Throwable cause = null;
9394
try {
94-
c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
95+
client.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
9596
} catch (final ExecutionException e) {
9697
cause = e.getCause();
97-
if (cause instanceof ConnectException) {
98-
//assertNotNull(cause.getCause());
99-
assertTrue(cause.getCause() instanceof SSLHandshakeException, "Expected an SSLHandshakeException, got a " + cause.getCause());
100-
} else {
101-
assertTrue(cause instanceof IOException, "Expected an IOException, got a " + cause);
102-
}
10398
}
104-
assertNotNull(cause);
105-
106-
trusted.set(true);
99+
assertTrue(cause instanceof SSLHandshakeException, "Expected an SSLHandshakeException, got a " + cause);
107100

108101
// second request should succeed
109-
Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
102+
trust.set(true);
103+
Response response = client.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
110104

111105
assertEquals(response.getResponseBody(), body);
112106
}

0 commit comments

Comments
 (0)