Skip to content

Commit fd5188a

Browse files
committed
minor fix
1 parent 2931b31 commit fd5188a

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
import org.apache.http.impl.client.CloseableHttpClient;
2828
import org.apache.http.impl.client.HttpClients;
2929
import org.apache.http.message.BasicNameValuePair;
30-
import org.junit.Ignore;
3130
import org.junit.Test;
3231

33-
@Ignore("need spring-rest module running")
32+
/*
33+
* NOTE : Need module spring-rest to be running
34+
*/
3435
public class HttpClientPostingLiveTest {
3536
private static final String SAMPLE_URL = "http://localhost:8080/spring-rest/users";
3637
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";

httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
package org.baeldung.httpclient;
22

3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.junit.Assert.assertThat;
5+
6+
import java.io.IOException;
7+
import java.security.GeneralSecurityException;
8+
import java.security.KeyManagementException;
9+
import java.security.KeyStoreException;
10+
import java.security.NoSuchAlgorithmException;
11+
12+
import javax.net.ssl.SSLContext;
13+
import javax.net.ssl.SSLException;
14+
315
import org.apache.http.HttpResponse;
416
import org.apache.http.client.methods.HttpGet;
517
import org.apache.http.conn.ClientConnectionManager;
618
import org.apache.http.conn.scheme.Scheme;
719
import org.apache.http.conn.scheme.SchemeRegistry;
8-
import org.apache.http.conn.ssl.*;
20+
import org.apache.http.conn.ssl.NoopHostnameVerifier;
21+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
22+
import org.apache.http.conn.ssl.SSLContextBuilder;
23+
import org.apache.http.conn.ssl.SSLContexts;
24+
import org.apache.http.conn.ssl.SSLSocketFactory;
25+
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
26+
import org.apache.http.conn.ssl.TrustStrategy;
927
import org.apache.http.impl.client.CloseableHttpClient;
1028
import org.apache.http.impl.client.DefaultHttpClient;
1129
import org.apache.http.impl.client.HttpClientBuilder;
1230
import org.apache.http.impl.client.HttpClients;
1331
import org.apache.http.impl.conn.PoolingClientConnectionManager;
1432
import org.junit.Test;
1533

16-
import javax.net.ssl.SSLContext;
17-
import javax.net.ssl.SSLException;
18-
import java.io.IOException;
19-
import java.security.GeneralSecurityException;
20-
import java.security.KeyManagementException;
21-
import java.security.KeyStoreException;
22-
import java.security.NoSuchAlgorithmException;
23-
24-
import static org.hamcrest.CoreMatchers.equalTo;
25-
import static org.junit.Assert.assertThat;
26-
2734
/**
2835
* This test requires a localhost server over HTTPS <br>
2936
* It should only be manually run, not part of the automated build
@@ -96,7 +103,7 @@ public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanCon
96103
@Test
97104
public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws IOException {
98105

99-
TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true;
106+
final TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true;
100107

101108
SSLContext sslContext = null;
102109
try {
@@ -106,8 +113,8 @@ public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect()
106113
e.printStackTrace();
107114
}
108115

109-
CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
110-
final HttpGet httpGet = new HttpGet("https://sesar3.geoinfogeochem.org/sample/igsn/ODP000002");
116+
final CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
117+
final HttpGet httpGet = new HttpGet(HOST_WITH_SSL);
111118
httpGet.setHeader("Accept", "application/xml");
112119

113120
final HttpResponse response = client.execute(httpGet);

httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientSandboxLiveTest.java

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

3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
36
import org.apache.http.HttpEntity;
47
import org.apache.http.auth.AuthScope;
58
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -11,9 +14,9 @@
1114
import org.apache.http.impl.client.HttpClientBuilder;
1215
import org.junit.Test;
1316

14-
import java.io.IOException;
15-
import java.io.InputStream;
16-
17+
/*
18+
* NOTE : Need module spring-security-rest-basic-auth to be running
19+
*/
1720
public class HttpClientSandboxLiveTest {
1821

1922
@Test
@@ -22,10 +25,10 @@ public final void givenGetRequestExecuted_whenAnalyzingTheResponse_thenCorrectSt
2225
final AuthScope authscp = new AuthScope("localhost", 8080);
2326
credentialsProvider.setCredentials(authscp, new UsernamePasswordCredentials("user1", "user1Pass"));
2427

25-
CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
28+
final CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
2629

2730
final HttpGet httpGet = new HttpGet("http://localhost:8080/spring-security-rest-basic-auth/api/foos/1");
28-
CloseableHttpResponse response = client.execute(httpGet);
31+
final CloseableHttpResponse response = client.execute(httpGet);
2932

3033
System.out.println(response.getStatusLine());
3134

httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
import org.junit.Before;
3131
import org.junit.Test;
3232

33+
/*
34+
* NOTE : Need module spring-security-rest-basic-auth to be running
35+
*/
36+
3337
public class HttpClientAuthLiveTest {
3438

3539
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8081/spring-security-rest-basic-auth/api/foos/1";

0 commit comments

Comments
 (0)