Skip to content

Commit 1f5cf71

Browse files
author
eugenp
committed
final cleanup for tutorial
1 parent 2119981 commit 1f5cf71

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.baeldung.client;
22

3+
import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
34
import static org.hamcrest.Matchers.equalTo;
45
import static org.junit.Assert.assertThat;
56

6-
import java.io.IOException;
77
import java.security.GeneralSecurityException;
88
import java.security.cert.X509Certificate;
99

@@ -54,9 +54,8 @@ public final void whenHttpsUrlIsConsumed_thenException() {
5454
}
5555

5656
@Test
57-
public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenException() throws IOException, GeneralSecurityException {
58-
final RestTemplate newRestTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
59-
final HttpComponentsClientHttpRequestFactory requestFactory = (HttpComponentsClientHttpRequestFactory) newRestTemplate.getRequestFactory();
57+
public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenException() throws GeneralSecurityException {
58+
final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
6059
final DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient();
6160

6261
final TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
@@ -65,11 +64,11 @@ public final boolean isTrusted(final X509Certificate[] certificate, final String
6564
return true;
6665
}
6766
};
68-
final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
67+
final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, ALLOW_ALL_HOSTNAME_VERIFIER);
6968
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 8443, sf));
7069

7170
final String urlOverHttps = "https://localhost:8443/spring-security-rest-basic-auth/api/bars/1";
72-
final ResponseEntity<String> response = newRestTemplate.exchange(urlOverHttps, HttpMethod.GET, null, String.class);
71+
final ResponseEntity<String> response = new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class);
7372
assertThat(response.getStatusCode().value(), equalTo(200));
7473
}
7574

0 commit comments

Comments
 (0)