minor fix
This commit is contained in:
parent
2931b3114e
commit
fd5188aed2
@ -27,10 +27,11 @@ import org.apache.http.impl.auth.BasicScheme;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@Ignore("need spring-rest module running")
|
/*
|
||||||
|
* NOTE : Need module spring-rest to be running
|
||||||
|
*/
|
||||||
public class HttpClientPostingLiveTest {
|
public class HttpClientPostingLiveTest {
|
||||||
private static final String SAMPLE_URL = "http://localhost:8080/spring-rest/users";
|
private static final String SAMPLE_URL = "http://localhost:8080/spring-rest/users";
|
||||||
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";
|
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";
|
||||||
|
@ -1,28 +1,35 @@
|
|||||||
package org.baeldung.httpclient;
|
package org.baeldung.httpclient;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import static org.junit.Assert.assertThat;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
|
||||||
import org.apache.http.conn.ssl.*;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.SSLException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import javax.net.ssl.SSLContext;
|
||||||
import static org.junit.Assert.assertThat;
|
import javax.net.ssl.SSLException;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||||
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||||
|
import org.apache.http.conn.ssl.SSLContextBuilder;
|
||||||
|
import org.apache.http.conn.ssl.SSLContexts;
|
||||||
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
|
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||||
|
import org.apache.http.conn.ssl.TrustStrategy;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test requires a localhost server over HTTPS <br>
|
* This test requires a localhost server over HTTPS <br>
|
||||||
@ -96,7 +103,7 @@ public class HttpsClientSslLiveTest {
|
|||||||
@Test
|
@Test
|
||||||
public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws IOException {
|
public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws IOException {
|
||||||
|
|
||||||
TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true;
|
final TrustStrategy acceptingTrustStrategy = (certificate, authType) -> true;
|
||||||
|
|
||||||
SSLContext sslContext = null;
|
SSLContext sslContext = null;
|
||||||
try {
|
try {
|
||||||
@ -106,8 +113,8 @@ public class HttpsClientSslLiveTest {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
final CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
||||||
final HttpGet httpGet = new HttpGet("https://sesar3.geoinfogeochem.org/sample/igsn/ODP000002");
|
final HttpGet httpGet = new HttpGet(HOST_WITH_SSL);
|
||||||
httpGet.setHeader("Accept", "application/xml");
|
httpGet.setHeader("Accept", "application/xml");
|
||||||
|
|
||||||
final HttpResponse response = client.execute(httpGet);
|
final HttpResponse response = client.execute(httpGet);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.baeldung.httpclient.base;
|
package org.baeldung.httpclient.base;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.auth.AuthScope;
|
import org.apache.http.auth.AuthScope;
|
||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
@ -11,9 +14,9 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
/*
|
||||||
import java.io.InputStream;
|
* NOTE : Need module spring-security-rest-basic-auth to be running
|
||||||
|
*/
|
||||||
public class HttpClientSandboxLiveTest {
|
public class HttpClientSandboxLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -22,10 +25,10 @@ public class HttpClientSandboxLiveTest {
|
|||||||
final AuthScope authscp = new AuthScope("localhost", 8080);
|
final AuthScope authscp = new AuthScope("localhost", 8080);
|
||||||
credentialsProvider.setCredentials(authscp, new UsernamePasswordCredentials("user1", "user1Pass"));
|
credentialsProvider.setCredentials(authscp, new UsernamePasswordCredentials("user1", "user1Pass"));
|
||||||
|
|
||||||
CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
|
final CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
|
||||||
|
|
||||||
final HttpGet httpGet = new HttpGet("http://localhost:8080/spring-security-rest-basic-auth/api/foos/1");
|
final HttpGet httpGet = new HttpGet("http://localhost:8080/spring-security-rest-basic-auth/api/foos/1");
|
||||||
CloseableHttpResponse response = client.execute(httpGet);
|
final CloseableHttpResponse response = client.execute(httpGet);
|
||||||
|
|
||||||
System.out.println(response.getStatusLine());
|
System.out.println(response.getStatusLine());
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE : Need module spring-security-rest-basic-auth to be running
|
||||||
|
*/
|
||||||
|
|
||||||
public class HttpClientAuthLiveTest {
|
public class HttpClientAuthLiveTest {
|
||||||
|
|
||||||
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8081/spring-security-rest-basic-auth/api/foos/1";
|
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8081/spring-security-rest-basic-auth/api/foos/1";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user