Merge remote-tracking branch 'upstream/master'

This commit is contained in:
DOHA 2014-11-24 19:31:54 +02:00
commit d042d236f1
7 changed files with 76 additions and 43 deletions

View File

@ -1,5 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>apache-fop</artifactId>
@ -104,28 +103,48 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- new dependencies -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>1.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.dbdoclet</groupId>
<artifactId>dbdoclet</artifactId>
<version>8.0.2</version>
</dependency>
<dependency>
<groupId>net.sf.jtidy</groupId>
<artifactId>jtidy</artifactId>
<version>r938</version>
</dependency>
</dependencies>
<build>

View File

@ -57,10 +57,9 @@ public class HttpClientHeadersLiveTest {
// tests - headers - deprecated
@SuppressWarnings("deprecation")
@Test
public final void givenDeprecatedApi_whenClientUsesCustomUserAgent_thenCorrect() throws ClientProtocolException, IOException {
client = new DefaultHttpClient();
client = HttpClients.custom().build();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 Firefox/26.0");
HttpProtocolParams.setUserAgent(client.getParams(), "Mozilla/5.0 Firefox/26.0");
@ -86,16 +85,14 @@ public class HttpClientHeadersLiveTest {
// tests - headers - content type
@SuppressWarnings("deprecation")
@Test
public final void givenUsingDeprecatedApi_whenRequestHasCustomContentType_thenCorrect() throws ClientProtocolException, IOException {
client = new DefaultHttpClient();
client = HttpClients.custom().build();
final HttpGet request = new HttpGet(SAMPLE_URL);
request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
response = client.execute(request);
}
@SuppressWarnings("deprecation")
@Test
public final void givenRequestBuildWithBuilderWithDeprecatedApi_whenRequestHasCustomContentType_thenCorrect() throws ClientProtocolException, IOException {
final DefaultHttpClient client2 = new DefaultHttpClient();

View File

@ -55,7 +55,6 @@ public class HttpClientRedirectLiveTest {
// tests
@SuppressWarnings("deprecation")
@Test
public final void givenRedirectsAreDisabledViaDeprecatedApi_whenConsumingUrlWhichRedirects_thenNotRedirected() throws ClientProtocolException, IOException {
instance = new DefaultHttpClient();
@ -87,7 +86,6 @@ public class HttpClientRedirectLiveTest {
assertThat(response.getStatusLine().getStatusCode(), equalTo(301));
}
@SuppressWarnings("deprecation")
@Test
public final void givenRedirectingPOSTViaPre4_2Api_whenConsumingUrlWhichRedirectsWithPOST_thenRedirected() throws ClientProtocolException, IOException {
final DefaultHttpClient client = new DefaultHttpClient();
@ -110,7 +108,6 @@ public class HttpClientRedirectLiveTest {
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
}
@SuppressWarnings("deprecation")
@Test
public final void givenRedirectingPOSTVia4_2Api_whenConsumingUrlWhichRedirectsWithPOST_thenRedirected() throws ClientProtocolException, IOException {
final DefaultHttpClient client = new DefaultHttpClient();

View File

@ -43,7 +43,6 @@ public class HttpClientTimeoutLiveTest {
// tests
@SuppressWarnings("deprecation")
@Test
public final void givenUsingDeprecatedApi_whenSettingTimeoutViaRawParams_thenCorrect() throws ClientProtocolException, IOException {
final int timeout = 2;
@ -61,7 +60,6 @@ public class HttpClientTimeoutLiveTest {
client.close();
}
@SuppressWarnings("deprecation")
@Test
public final void givenUsingDeprecatedApi_whenSettingTimeoutViaHigherLevelApi_thenCorrect() throws ClientProtocolException, IOException {
final int timeout = 2;

View File

@ -1,6 +1,5 @@
package org.baeldung.client;
package org.baeldung.httpclient;
import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@ -28,10 +27,6 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* This test requires a localhost server over HTTPS <br>
@ -76,25 +71,6 @@ public class HttpsClientLiveManualTest {
httpClient.close();
}
@Test
public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenException() throws GeneralSecurityException {
final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
final CloseableHttpClient httpClient = (CloseableHttpClient) requestFactory.getHttpClient();
final TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
@Override
public final boolean isTrusted(final X509Certificate[] certificate, final String authType) {
return true;
}
};
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<String> response = new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class);
assertThat(response.getStatusCode().value(), equalTo(200));
}
@Test
public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException {
final SSLContextBuilder builder = new SSLContextBuilder();

View File

@ -63,7 +63,6 @@ public class HttpClientCookieLiveTest {
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
}
@SuppressWarnings("deprecation")
@Test
public final void givenUsingDeprecatedApi_whenSettingCookiesOnTheHttpClient_thenCorrect() throws ClientProtocolException, IOException {
final BasicCookieStore cookieStore = new BasicCookieStore();

View File

@ -0,0 +1,47 @@
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.security.GeneralSecurityException;
import java.security.cert.X509Certificate;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* This test requires a localhost server over HTTPS <br>
* It should only be manually run, not part of the automated build
* */
public class RestClientLiveManualTest {
// tests
@Test
public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenException() throws GeneralSecurityException {
final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
final CloseableHttpClient httpClient = (CloseableHttpClient) requestFactory.getHttpClient();
final TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
@Override
public final boolean isTrusted(final X509Certificate[] certificate, final String authType) {
return true;
}
};
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<String> response = new RestTemplate(requestFactory).exchange(urlOverHttps, HttpMethod.GET, null, String.class);
assertThat(response.getStatusCode().value(), equalTo(200));
}
}