From 1f5cf7151ee3b9fa7ca680f2ef8dbf8052840320 Mon Sep 17 00:00:00 2001 From: eugenp Date: Fri, 9 Aug 2013 16:37:37 +0300 Subject: [PATCH] final cleanup for tutorial --- .../test/java/org/baeldung/client/ClientLiveTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java b/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java index 1218a02045..e14fc1403e 100644 --- a/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java +++ b/spring-security-rest-basic-auth/src/test/java/org/baeldung/client/ClientLiveTest.java @@ -1,9 +1,9 @@ package org.baeldung.client; +import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; -import java.io.IOException; import java.security.GeneralSecurityException; import java.security.cert.X509Certificate; @@ -54,9 +54,8 @@ public class ClientLiveTest { } @Test - public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenException() throws IOException, GeneralSecurityException { - final RestTemplate newRestTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); - final HttpComponentsClientHttpRequestFactory requestFactory = (HttpComponentsClientHttpRequestFactory) newRestTemplate.getRequestFactory(); + public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenException() throws GeneralSecurityException { + final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); final DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient(); final TrustStrategy acceptingTrustStrategy = new TrustStrategy() { @@ -65,11 +64,11 @@ public class ClientLiveTest { return true; } }; - final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 8443, sf)); final String urlOverHttps = "https://localhost:8443/spring-security-rest-basic-auth/api/bars/1"; - final ResponseEntity response = newRestTemplate.exchange(urlOverHttps, HttpMethod.GET, null, String.class); + final ResponseEntity response = new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class); assertThat(response.getStatusCode().value(), equalTo(200)); }