You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2017/06/07 18:04:18 UTC
[3/3] cxf git commit: Remove old commons-httpclient code
Remove old commons-httpclient code
# Conflicts:
# distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/client/Client.java
# distribution/src/main/release/samples/jax_rs/spring_security/src/main/java/demo/jaxrs/client/Client.java
# distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
# distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSCxfContinuationsTest.java
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
# systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/AbstractSpringSecurityTest.java
# systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4130Test.java
# systests/jaxws/src/test/java/org/apache/cxf/systest/provider/CXF4818Test.java
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d279286a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d279286a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d279286a
Branch: refs/heads/3.1.x-fixes
Commit: d279286ae875f0c3f1e37f2a7a6b597776646b05
Parents: d70f76b
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Wed Jun 7 17:10:22 2017 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Wed Jun 7 19:03:50 2017 +0100
----------------------------------------------------------------------
.../main/release/samples/jax_rs/basic/pom.xml | 10 +-
.../src/main/java/demo/jaxrs/client/Client.java | 43 +--
.../samples/jax_rs/content_negotiation/pom.xml | 10 +-
.../src/main/java/demo/jaxrs/client/Client.java | 41 +--
.../samples/jax_rs/description_swagger/pom.xml | 5 -
.../jax_rs/description_swagger2_spring/pom.xml | 5 -
.../main/release/samples/jax_rs/search/pom.xml | 16 +-
.../java/demo/jaxrs/search/client/Client.java | 112 ++++---
.../samples/jax_rs/spring_security/pom.xml | 8 +-
.../src/main/java/demo/jaxrs/client/Client.java | 69 ++---
.../samples/jax_rs/tracing_brave/pom.xml | 5 -
.../samples/jax_rs/tracing_brave_osgi/pom.xml | 5 -
.../samples/jax_rs/tracing_htrace/pom.xml | 5 -
.../samples/jaxws_tracing_brave_osgi/pom.xml | 5 -
.../release/samples/restful_dispatch/pom.xml | 6 -
parent/pom.xml | 11 -
rt/databinding/aegis/pom.xml | 5 -
systests/jaxrs/pom.xml | 5 -
.../jaxrs/AbstractJAXRSContinuationsTest.java | 19 +-
.../cxf/systest/jaxrs/JAXRSAtomBookTest.java | 65 ++--
.../jaxrs/JAXRSClientServerBookTest.java | 295 +++++++++----------
.../JAXRSClientServerNonSpringBookTest.java | 30 +-
.../jaxrs/JAXRSClientServerSpringBookTest.java | 43 +--
.../jaxrs/JAXRSClientServerStreamingTest.java | 19 +-
...AXRSClientServerUserResourceDefaultTest.java | 19 +-
.../JAXRSClientServerUserResourceTest.java | 31 +-
.../JAXRSCxfContinuationsServlet3Test.java | 17 +-
.../jaxrs/JAXRSCxfContinuationsTest.java | 30 +-
.../cxf/systest/jaxrs/JAXRSMultipartTest.java | 123 ++++----
.../cxf/systest/jaxrs/JAXRSSoapBookTest.java | 34 +--
.../security/AbstractSpringSecurityTest.java | 22 +-
systests/jaxws/pom.xml | 11 +-
.../cxf/systest/provider/CXF4130Test.java | 19 +-
.../cxf/systest/provider/CXF4818Test.java | 19 +-
systests/transports-ssl3/pom.xml | 5 -
systests/transports/pom.xml | 5 -
systests/uncategorized/pom.xml | 10 +-
.../cxf/systest/simple/SimpleFrontendTest.java | 15 +-
38 files changed, 575 insertions(+), 622 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/basic/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/basic/pom.xml b/distribution/src/main/release/samples/jax_rs/basic/pom.xml
index 9acfe20..01e6bff 100644
--- a/distribution/src/main/release/samples/jax_rs/basic/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/basic/pom.xml
@@ -30,7 +30,6 @@
</parent>
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
<profile>
@@ -98,13 +97,12 @@
<version>3.1.12-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>${httpclient.version}</version>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/basic/src/main/java/demo/jaxrs/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/basic/src/main/java/demo/jaxrs/client/Client.java b/distribution/src/main/release/samples/jax_rs/basic/src/main/java/demo/jaxrs/client/Client.java
index 4267b84..3452678 100644
--- a/distribution/src/main/release/samples/jax_rs/basic/src/main/java/demo/jaxrs/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/basic/src/main/java/demo/jaxrs/client/Client.java
@@ -23,15 +23,17 @@ import java.io.File;
import java.io.InputStream;
import java.net.URL;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.FileRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.resource.URIResolver;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
public final class Client {
@@ -67,16 +69,15 @@ public final class Client {
String inputFile = client.getClass().getResource("/update_customer.xml").getFile();
URIResolver resolver = new URIResolver(inputFile);
File input = new File(resolver.getURI());
- PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
- RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
- put.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ HttpPut put = new HttpPut("http://localhost:9000/customerservice/customers");
+ put.setEntity(new FileEntity(input, ContentType.TEXT_XML));
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
- int result = httpclient.executeMethod(put);
- System.out.println("Response status code: " + result);
+ CloseableHttpResponse response = httpClient.execute(put);
+ System.out.println("Response status code: " + response.getStatusLine().getStatusCode());
System.out.println("Response body: ");
- System.out.println(put.getResponseBodyAsString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
// Release current connection to the connection pool once you are
// done
@@ -89,17 +90,17 @@ public final class Client {
inputFile = client.getClass().getResource("/add_customer.xml").getFile();
resolver = new URIResolver(inputFile);
input = new File(resolver.getURI());
- PostMethod post = new PostMethod("http://localhost:9000/customerservice/customers");
- post.addRequestHeader("Accept", "text/xml");
- entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
- post.setRequestEntity(entity);
- httpclient = new HttpClient();
+
+ HttpPost post = new HttpPost("http://localhost:9000/customerservice/customers");
+ post.addHeader("Accept", "text/xml");
+ post.setEntity(new FileEntity(input, ContentType.TEXT_XML));
+ httpClient = HttpClientBuilder.create().build();
try {
- int result = httpclient.executeMethod(post);
- System.out.println("Response status code: " + result);
+ CloseableHttpResponse response = httpClient.execute(post);
+ System.out.println("Response status code: " + response.getStatusLine().getStatusCode());
System.out.println("Response body: ");
- System.out.println(post.getResponseBodyAsString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
// Release current connection to the connection pool once you are
// done
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/content_negotiation/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/content_negotiation/pom.xml b/distribution/src/main/release/samples/jax_rs/content_negotiation/pom.xml
index b21d0b6..f6745a4 100644
--- a/distribution/src/main/release/samples/jax_rs/content_negotiation/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/content_negotiation/pom.xml
@@ -30,7 +30,6 @@
</parent>
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
<profile>
@@ -107,13 +106,12 @@
<artifactId>jettison</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>${httpclient.version}</version>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/content_negotiation/src/main/java/demo/jaxrs/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/content_negotiation/src/main/java/demo/jaxrs/client/Client.java b/distribution/src/main/release/samples/jax_rs/content_negotiation/src/main/java/demo/jaxrs/client/Client.java
index f1c360d..c1a556a 100644
--- a/distribution/src/main/release/samples/jax_rs/content_negotiation/src/main/java/demo/jaxrs/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/content_negotiation/src/main/java/demo/jaxrs/client/Client.java
@@ -19,8 +19,11 @@
package demo.jaxrs.client;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
public final class Client {
@@ -30,15 +33,15 @@ public final class Client {
public static void main(String args[]) throws Exception {
// Sent HTTP GET request to query customer info, expect XML
System.out.println("Sent HTTP GET request to query customer info, expect XML");
- GetMethod get = new GetMethod("http://localhost:9000/customerservice/customers/123");
- get.addRequestHeader("Accept", "application/xml");
- HttpClient httpclient = new HttpClient();
+ HttpGet get = new HttpGet("http://localhost:9000/customerservice/customers/123");
+ get.addHeader("Accept", "application/xml");
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
- int result = httpclient.executeMethod(get);
- System.out.println("Response status code: " + result);
+ CloseableHttpResponse response = httpClient.execute(get);
+ System.out.println("Response status code: " + response.getStatusLine().getStatusCode());
System.out.println("Response body: ");
- System.out.println(get.getResponseBodyAsString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
get.releaseConnection();
}
@@ -46,15 +49,15 @@ public final class Client {
// Sent HTTP GET request to query customer info, expect JSON.
System.out.println("\n");
System.out.println("Sent HTTP GET request to query customer info, expect JSON");
- get = new GetMethod("http://localhost:9000/customerservice/customers/123");
- get.addRequestHeader("Accept", "application/json");
- httpclient = new HttpClient();
+ get = new HttpGet("http://localhost:9000/customerservice/customers/123");
+ get.addHeader("Accept", "application/json");
+ httpClient = HttpClientBuilder.create().build();
try {
- int result = httpclient.executeMethod(get);
- System.out.println("Response status code: " + result);
+ CloseableHttpResponse response = httpClient.execute(get);
+ System.out.println("Response status code: " + response.getStatusLine().getStatusCode());
System.out.println("Response body: ");
- System.out.println(get.getResponseBodyAsString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
get.releaseConnection();
}
@@ -64,14 +67,14 @@ public final class Client {
//The default behavior without setting Accept header explicitly is depending on your client.
//In the case of HTTP Client, the Accept header will be absent. The CXF server will treat this
//as "*/*", XML format is returned
- get = new GetMethod("http://localhost:9000/customerservice/customers/123");
- httpclient = new HttpClient();
+ get = new HttpGet("http://localhost:9000/customerservice/customers/123");
+ httpClient = HttpClientBuilder.create().build();
try {
- int result = httpclient.executeMethod(get);
- System.out.println("Response status code: " + result);
+ CloseableHttpResponse response = httpClient.execute(get);
+ System.out.println("Response status code: " + response.getStatusLine().getStatusCode());
System.out.println("Response body: ");
- System.out.println(get.getResponseBodyAsString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
get.releaseConnection();
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml b/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml
index 92b31a0..888486a 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger/pom.xml
@@ -31,7 +31,6 @@
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
@@ -148,10 +147,6 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/description_swagger2_spring/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/description_swagger2_spring/pom.xml b/distribution/src/main/release/samples/jax_rs/description_swagger2_spring/pom.xml
index fd8bd17..f986c79 100644
--- a/distribution/src/main/release/samples/jax_rs/description_swagger2_spring/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/description_swagger2_spring/pom.xml
@@ -31,7 +31,6 @@
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
@@ -83,10 +82,6 @@
<version>3.1.12-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/search/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/search/pom.xml b/distribution/src/main/release/samples/jax_rs/search/pom.xml
index d4a635b..913ef92 100644
--- a/distribution/src/main/release/samples/jax_rs/search/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/search/pom.xml
@@ -31,7 +31,6 @@
<properties>
<cxf.version>${project.version}</cxf.version>
<cxf.lucene.version>4.9.0</cxf.lucene.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
<profile>
@@ -146,16 +145,21 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpmime</artifactId>
+ <version>4.5.3</version>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/client/Client.java b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/client/Client.java
index 72ff45f..0d06900 100644
--- a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/client/Client.java
@@ -21,16 +21,16 @@ package demo.jaxrs.search.client;
import java.io.IOException;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
-import org.apache.commons.httpclient.methods.multipart.FilePart;
-import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
-import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.cxf.helpers.IOUtils;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.mime.MultipartEntity;
+import org.apache.http.entity.mime.content.ByteArrayBody;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
public final class Client {
private Client() {
@@ -38,8 +38,9 @@ public final class Client {
public static void main(String args[]) throws Exception {
final String url = "http://localhost:9000/catalog";
- final HttpClient httpClient = new HttpClient();
-
+
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+
uploadToCatalog(url, httpClient, "jsr339-jaxrs-2.0-final-spec.pdf");
uploadToCatalog(url, httpClient, "JavaWebSocketAPI_1.0_Final.pdf");
uploadToCatalog(url, httpClient, "apache-cxf-tika-lucene.odt");
@@ -58,34 +59,33 @@ public final class Client {
delete(url, httpClient);
}
- private static void list(final String url, final HttpClient httpClient)
- throws IOException, HttpException {
-
+ private static void list(final String url, final CloseableHttpClient httpClient)
+ throws IOException {
+
System.out.println("Sent HTTP GET request to query all books in catalog");
-
- final GetMethod get = new GetMethod(url);
+
+ final HttpGet get = new HttpGet(url);
try {
- int status = httpClient.executeMethod(get);
- if (status == 200) {
- System.out.println(get.getResponseBodyAsString());
+ CloseableHttpResponse response = httpClient.execute(get);
+ if (response.getStatusLine().getStatusCode() == 200) {
+ System.out.println(EntityUtils.toString(response.getEntity()));
}
} finally {
get.releaseConnection();
}
}
-
- private static void search(final String url, final HttpClient httpClient, final String expression)
- throws IOException, HttpException {
-
+
+ private static void search(final String url, final CloseableHttpClient httpClient, final String expression)
+ throws IOException {
+
System.out.println("Sent HTTP GET request to search the books in catalog: " + expression);
-
- final GetMethod get = new GetMethod(url + "/search");
- get.setQueryString("$filter=" + expression);
-
+
+ final HttpGet get = new HttpGet(url + "/search?$filter=" + expression);
+
try {
- int status = httpClient.executeMethod(get);
- if (status == 200) {
- System.out.println(get.getResponseBodyAsString());
+ CloseableHttpResponse response = httpClient.execute(get);
+ if (response.getStatusLine().getStatusCode() == 200) {
+ System.out.println(EntityUtils.toString(response.getEntity()));
}
} finally {
get.releaseConnection();
@@ -93,27 +93,23 @@ public final class Client {
}
- private static void uploadToCatalog(final String url, final HttpClient httpClient,
- final String filename) throws IOException, HttpException {
-
+ private static void uploadToCatalog(final String url, final CloseableHttpClient httpClient,
+ final String filename) throws IOException {
+
System.out.println("Sent HTTP POST request to upload the file into catalog: " + filename);
-
- final PostMethod post = new PostMethod(url);
- final Part[] parts = {
- new FilePart(filename,
- new ByteArrayPartSource(filename,
- IOUtils.readBytesFromStream(Client.class.getResourceAsStream("/" + filename))
- )
- )
- };
-
- post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
-
+
+ final HttpPost post = new HttpPost(url);
+ MultipartEntity entity = new MultipartEntity();
+ byte[] bytes = IOUtils.readBytesFromStream(Client.class.getResourceAsStream("/" + filename));
+ entity.addPart(filename, new ByteArrayBody(bytes, filename));
+
+ post.setEntity(entity);
+
try {
- int status = httpClient.executeMethod(post);
- if (status == 201) {
- System.out.println(post.getResponseHeader("Location"));
- } else if (status == 409) {
+ CloseableHttpResponse response = httpClient.execute(post);
+ if (response.getStatusLine().getStatusCode() == 201) {
+ System.out.println(response.getFirstHeader("Location"));
+ } else if (response.getStatusLine().getStatusCode() == 409) {
System.out.println("Document already exists: " + filename);
}
@@ -121,17 +117,17 @@ public final class Client {
post.releaseConnection();
}
}
-
- private static void delete(final String url, final HttpClient httpClient)
- throws IOException, HttpException {
-
+
+ private static void delete(final String url, final CloseableHttpClient httpClient)
+ throws IOException {
+
System.out.println("Sent HTTP DELETE request to remove all books from catalog");
-
- final DeleteMethod delete = new DeleteMethod(url);
+
+ final HttpDelete delete = new HttpDelete(url);
try {
- int status = httpClient.executeMethod(delete);
- if (status == 200) {
- System.out.println(delete.getResponseBodyAsString());
+ CloseableHttpResponse response = httpClient.execute(delete);
+ if (response.getStatusLine().getStatusCode() == 200) {
+ System.out.println(EntityUtils.toString(response.getEntity()));
}
} finally {
delete.releaseConnection();
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/spring_security/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_security/pom.xml b/distribution/src/main/release/samples/jax_rs/spring_security/pom.xml
index 2aa848c..2c4c25a 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_security/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/spring_security/pom.xml
@@ -103,10 +103,6 @@
<version>3.1.12-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
@@ -154,5 +150,9 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/spring_security/src/main/java/demo/jaxrs/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_security/src/main/java/demo/jaxrs/client/Client.java b/distribution/src/main/release/samples/jax_rs/spring_security/src/main/java/demo/jaxrs/client/Client.java
index 4dfac8b..d39b106 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_security/src/main/java/demo/jaxrs/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/spring_security/src/main/java/demo/jaxrs/client/Client.java
@@ -21,16 +21,18 @@ package demo.jaxrs.client;
import javax.ws.rs.core.Response;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-
import org.apache.cxf.common.util.Base64Utility;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
public final class Client {
@@ -70,8 +72,8 @@ public final class Client {
System.out.println("HTTP GET to query customer info, user : "
+ name + ", password : " + password);
- GetMethod get =
- new GetMethod("http://localhost:9002/customerservice/customers/" + id);
+ HttpGet get =
+ new HttpGet("http://localhost:9002/customerservice/customers/" + id);
setMethodHeaders(get, name, password);
handleHttpMethod(get);
}
@@ -80,12 +82,13 @@ public final class Client {
System.out.println("HTTP POST to add customer info, user : "
+ name + ", password : " + password);
- PostMethod post = new PostMethod("http://localhost:9002/customerservice/customers");
+ HttpPost post = new HttpPost("http://localhost:9002/customerservice/customers");
setMethodHeaders(post, name, password);
- RequestEntity entity = new InputStreamRequestEntity(
+ HttpEntity entity = new InputStreamEntity(
this.getClass().getClassLoader().getResourceAsStream("add_customer.xml"));
- post.setRequestEntity(entity);
+ post.setEntity(entity);
+
handleHttpMethod(post);
}
@@ -93,12 +96,12 @@ public final class Client {
System.out.println("HTTP PUT to update customer info, user : "
+ name + ", password : " + password);
- PutMethod put = new PutMethod("http://localhost:9002/customerservice/customers/123");
+ HttpPut put = new HttpPut("http://localhost:9002/customerservice/customers/123");
setMethodHeaders(put, name, password);
- RequestEntity entity = new InputStreamRequestEntity(
+ HttpEntity entity = new InputStreamEntity(
this.getClass().getClassLoader().getResourceAsStream("update_customer.xml"));
- put.setRequestEntity(entity);
-
+ put.setEntity(entity);
+
handleHttpMethod(put);
}
@@ -109,25 +112,26 @@ public final class Client {
System.out.println("Confirming a customer with id " + id + " exists first");
getCustomerInfo(name, password, id);
System.out.println("Deleting now...");
- DeleteMethod del =
- new DeleteMethod("http://localhost:9002/customerservice/customers/" + id);
+ HttpDelete del =
+ new HttpDelete("http://localhost:9002/customerservice/customers/" + id);
setMethodHeaders(del, name, password);
handleHttpMethod(del);
System.out.println("Confirming a customer with id " + id + " does not exist anymore");
getCustomerInfo(name, password, id);
}
- private static void handleHttpMethod(HttpMethod httpMethod) throws Exception {
- HttpClient client = new HttpClient();
+ private static void handleHttpMethod(HttpRequestBase httpMethod) throws Exception {
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
- int statusCode = client.executeMethod(httpMethod);
- System.out.println("Response status : " + statusCode);
+ CloseableHttpResponse response = httpClient.execute(httpMethod);
+ System.out.println("Response status : " + response.getStatusLine().getStatusCode());
- Response.Status status = Response.Status.fromStatusCode(statusCode);
+ Response.Status status =
+ Response.Status.fromStatusCode(response.getStatusLine().getStatusCode());
if (status == Response.Status.OK) {
- System.out.println(httpMethod.getResponseBodyAsString());
+ System.out.println(EntityUtils.toString(response.getEntity()));
} else if (status == Response.Status.FORBIDDEN) {
System.out.println("Authorization failure");
} else if (status == Response.Status.UNAUTHORIZED) {
@@ -141,13 +145,12 @@ public final class Client {
}
}
- private static void setMethodHeaders(HttpMethod httpMethod, String name, String password) {
- if (httpMethod instanceof PostMethod || httpMethod instanceof PutMethod) {
- httpMethod.setRequestHeader("Content-Type", "application/xml");
- }
- httpMethod.setDoAuthentication(false);
- httpMethod.setRequestHeader("Accept", "application/xml");
- httpMethod.setRequestHeader("Authorization",
+ private static void setMethodHeaders(HttpRequestBase httpMethod, String name, String password) {
+ if (httpMethod instanceof HttpPost || httpMethod instanceof HttpPut) {
+ httpMethod.addHeader("Content-Type", "application/xml");
+ }
+ httpMethod.addHeader("Accept", "application/xml");
+ httpMethod.addHeader("Authorization",
"Basic " + base64Encode(name + ":" + password));
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml b/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml
index e4f3777..acad7c2 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml
@@ -30,7 +30,6 @@
</parent>
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
<profile>
@@ -121,10 +120,6 @@
<artifactId>javax.json</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
index 7c1868b..5960b51 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/pom.xml
@@ -31,7 +31,6 @@
</parent>
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<dependencies>
<dependency>
@@ -74,10 +73,6 @@
<artifactId>johnzon-core</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml b/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
index 208afa3..4ed8d68 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
@@ -30,7 +30,6 @@
</parent>
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
<profile>
@@ -125,10 +124,6 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml
index b88e9d5..a17b56f 100644
--- a/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml
+++ b/distribution/src/main/release/samples/jaxws_tracing_brave_osgi/pom.xml
@@ -31,7 +31,6 @@
</parent>
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<dependencies>
<dependency>
@@ -56,10 +55,6 @@
<version>3.1.12-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/distribution/src/main/release/samples/restful_dispatch/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/restful_dispatch/pom.xml b/distribution/src/main/release/samples/restful_dispatch/pom.xml
index c0b06e2..6125409 100644
--- a/distribution/src/main/release/samples/restful_dispatch/pom.xml
+++ b/distribution/src/main/release/samples/restful_dispatch/pom.xml
@@ -29,7 +29,6 @@
</parent>
<properties>
<cxf.version>${project.version}</cxf.version>
- <httpclient.version>3.1</httpclient.version>
</properties>
<profiles>
<profile>
@@ -102,11 +101,6 @@
<version>3.1.12-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>${httpclient.version}</version>
- </dependency>
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 38126be..b9bd9da 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1383,17 +1383,6 @@
<version>${cxf.spring.version}</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-io</artifactId>
<version>${cxf.spring.osgi.version}</version>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/rt/databinding/aegis/pom.xml
----------------------------------------------------------------------
diff --git a/rt/databinding/aegis/pom.xml b/rt/databinding/aegis/pom.xml
index 63659f1..17bc4e3 100644
--- a/rt/databinding/aegis/pom.xml
+++ b/rt/databinding/aegis/pom.xml
@@ -112,11 +112,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/systests/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml
index 06b049d..3828613 100644
--- a/systests/jaxrs/pom.xml
+++ b/systests/jaxrs/pom.xml
@@ -463,11 +463,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
index 9bc9be8..e104800 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
@@ -29,12 +29,13 @@ import java.util.concurrent.TimeUnit;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
-
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
import org.junit.Ignore;
import org.junit.Test;
@@ -195,13 +196,13 @@ public abstract class AbstractJAXRSContinuationsTest extends AbstractBusClientSe
}
private void checkBook(String address, String id, String expected) throws Exception {
- GetMethod get = new GetMethod(address);
- HttpClient httpclient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(address);
try {
- int result = httpclient.executeMethod(get);
- assertEquals(200, result);
+ CloseableHttpResponse response = client.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("Book description for id " + id + " is wrong",
- expected, IOUtils.toString(get.getResponseBodyAsStream()));
+ expected, EntityUtils.toString(response.getEntity()));
} finally {
// Release current connection to the connection pool once you are done
get.releaseConnection();
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
index 706df72..4903e49 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
@@ -30,14 +30,18 @@ import org.apache.abdera.model.Content;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
import org.codehaus.jettison.json.JSONObject;
import org.junit.BeforeClass;
@@ -112,18 +116,17 @@ public class JAXRSAtomBookTest extends AbstractBusClientServerTestBase {
Entry e = createBookEntry(256, "AtomBook");
StringWriter w = new StringWriter();
e.writeTo(w);
-
- PostMethod post = new PostMethod(endpointAddress);
- post.setRequestEntity(
- new StringRequestEntity(w.toString(), "application/atom+xml", null));
- HttpClient httpclient = new HttpClient();
-
+
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost(endpointAddress);
+ post.setEntity(new StringEntity(w.toString(), ContentType.APPLICATION_ATOM_XML));
+
String location = null;
try {
- int result = httpclient.executeMethod(post);
- assertEquals(201, result);
- location = post.getResponseHeader("Location").getValue();
- InputStream ins = post.getResponseBodyAsStream();
+ CloseableHttpResponse response = client.execute(post);
+ assertEquals(201, response.getStatusLine().getStatusCode());
+ location = response.getFirstHeader("Location").getValue();
+ InputStream ins = response.getEntity().getContent();
Document<Entry> entryDoc = abdera.getParser().parse(copyIn(ins));
assertEquals(entryDoc.getRoot().toString(), e.toString());
} finally {
@@ -170,13 +173,11 @@ public class JAXRSAtomBookTest extends AbstractBusClientServerTestBase {
private void getAndCompareJson(String address,
String resourcePath,
String type) throws Exception {
- GetMethod get = new GetMethod(address);
- get.setRequestHeader("Content-Type", "*/*");
- get.setRequestHeader("Accept", type);
- HttpClient httpClient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(address);
+ get.setHeader("Content-Type", "*/*");
+ get.setHeader("Accept", type);
try {
- httpClient.executeMethod(get);
- String jsonContent = getStringFromInputStream(get.getResponseBodyAsStream());
String expected = getStringFromInputStream(
getClass().getResourceAsStream(resourcePath));
expected = expected.replaceAll("9080", PORT);
@@ -216,15 +217,15 @@ public class JAXRSAtomBookTest extends AbstractBusClientServerTestBase {
}
private Feed getFeed(String endpointAddress, String acceptType) throws Exception {
- GetMethod get = new GetMethod(endpointAddress);
- get.setRequestHeader("Content-Type", "*/*");
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(endpointAddress);
+ get.setHeader("Content-Type", "*/*");
if (acceptType != null) {
- get.setRequestHeader("Accept", acceptType);
+ get.setHeader("Accept", acceptType);
}
- HttpClient httpClient = new HttpClient();
try {
- httpClient.executeMethod(get);
- Document<Feed> doc = abdera.getParser().parse(copyIn(get.getResponseBodyAsStream()));
+ CloseableHttpResponse response = client.execute(get);
+ Document<Feed> doc = abdera.getParser().parse(copyIn(response.getEntity().getContent()));
return doc.getRoot();
} finally {
get.releaseConnection();
@@ -232,15 +233,15 @@ public class JAXRSAtomBookTest extends AbstractBusClientServerTestBase {
}
private Entry getEntry(String endpointAddress, String acceptType) throws Exception {
- GetMethod get = new GetMethod(endpointAddress);
- get.setRequestHeader("Content-Type", "*/*");
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(endpointAddress);
+ get.setHeader("Content-Type", "*/*");
if (acceptType != null) {
- get.setRequestHeader("Accept", acceptType);
+ get.setHeader("Accept", acceptType);
}
- HttpClient httpClient = new HttpClient();
try {
- httpClient.executeMethod(get);
- Document<Entry> doc = abdera.getParser().parse(copyIn(get.getResponseBodyAsStream()));
+ CloseableHttpResponse response = client.execute(get);
+ Document<Entry> doc = abdera.getParser().parse(copyIn(response.getEntity().getContent()));
return doc.getRoot();
} finally {
get.releaseConnection();
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index c458902..e164d3b 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -52,14 +52,6 @@ import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.FileRequestEntity;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.feature.LoggingFeature;
import org.apache.cxf.helpers.IOUtils;
@@ -76,7 +68,18 @@ import org.apache.cxf.systest.jaxrs.BookStore.BookInfoInterface;
import org.apache.cxf.systest.jaxrs.BookStore.BookNotReturnedException;
import org.apache.cxf.systest.jaxrs.CustomFaultInInterceptor.CustomRuntimeException;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
-
+import org.apache.http.Header;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -949,18 +952,18 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
}
@Test
- public void testPropogateException() throws Exception {
- GetMethod get = new GetMethod("http://localhost:" + PORT + "/bookstore/propagate-exception");
- get.setRequestHeader("Accept", "application/xml");
- get.addRequestHeader("Cookie", "a=b;c=d");
- get.addRequestHeader("Cookie", "e=f");
- get.setRequestHeader("Accept-Language", "da;q=0.8,en");
- get.setRequestHeader("Book", "1,2,3");
- HttpClient httpClient = new HttpClient();
+ public void testPropogateException() throws Exception {
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet("http://localhost:" + PORT + "/bookstore/propagate-exception");
+ get.addHeader("Accept", "application/xml");
+ get.addHeader("Cookie", "a=b;c=d");
+ get.addHeader("Cookie", "e=f");
+ get.addHeader("Accept-Language", "da;q=0.8,en");
+ get.addHeader("Book", "1,2,3");
try {
- int result = httpClient.executeMethod(get);
- assertEquals(500, result);
- String content = getStringFromInputStream(get.getResponseBodyAsStream());
+ CloseableHttpResponse response = client.execute(get);
+ assertEquals(500, response.getStatusLine().getStatusCode());
+ String content = EntityUtils.toString(response.getEntity());
if (!StringUtils.isEmpty(content)) {
assertTrue(content, content.contains("Error") && content.contains("500"));
}
@@ -1082,7 +1085,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
@Test
public void testAddBookProxyResponse() {
Book b = new Book("CXF rocks", 123L);
-
+
System.out.println(Arrays.deepToString(Arrays.asList(b, b).toArray()));
BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
Response r = store.addBook(b);
@@ -1558,23 +1561,22 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String s = r.readEntity(String.class);
assertTrue(s.equals(msg1) || s.equals(msg2));
}
-
- @SuppressWarnings("deprecation")
+
@Test
public void testNoMessageReaderFound() throws Exception {
String endpointAddress =
"http://localhost:" + PORT + "/bookstore/binarybooks";
- PostMethod post = new PostMethod(endpointAddress);
- post.setRequestHeader("Content-Type", "application/octet-stream");
- post.setRequestHeader("Accept", "text/xml");
- post.setRequestBody("Bar");
- HttpClient httpclient = new HttpClient();
-
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost(endpointAddress);
+ post.addHeader("Content-Type", "application/octet-stream");
+ post.addHeader("Accept", "text/xml");
+ post.setEntity(new StringEntity("Bar"));
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(415, result);
+ CloseableHttpResponse response = client.execute(post);
+ assertEquals(415, response.getStatusLine().getStatusCode());
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
@@ -1586,14 +1588,14 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress =
"http://localhost:" + PORT + "/bookstore/unsupportedcontenttype";
- PostMethod post = new PostMethod(endpointAddress);
- post.setRequestHeader("Content-Type", "application/bar");
- post.setRequestHeader("Accept", "text/xml");
- HttpClient httpclient = new HttpClient();
-
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost(endpointAddress);
+ post.addHeader("Content-Type", "application/bar");
+ post.addHeader("Accept", "text/xml");
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(415, result);
+ CloseableHttpResponse response = client.execute(post);
+ assertEquals(415, response.getStatusLine().getStatusCode());
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
@@ -1643,19 +1645,19 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
}
private void checkBook(String address, boolean expected) throws Exception {
- GetMethod get = new GetMethod(address);
- get.setRequestHeader("Accept", "text/plain");
- HttpClient httpclient = new HttpClient();
-
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(address);
+ get.addHeader("Accept", "text/plain");
+
try {
- int result = httpclient.executeMethod(get);
- assertEquals(200, result);
+ CloseableHttpResponse response = client.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
if (expected) {
assertEquals("Book must be available",
- "true", get.getResponseBodyAsString());
+ "true", EntityUtils.toString(response.getEntity()));
} else {
assertEquals("Book must not be available",
- "false", get.getResponseBodyAsString());
+ "false", EntityUtils.toString(response.getEntity()));
}
} finally {
// Release current connection to the connection pool once you are done
@@ -2274,13 +2276,13 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
@Test
public void testAddBookNoBody() throws Exception {
- PostMethod post = new PostMethod("http://localhost:" + PORT + "/bookstore/books");
- post.setRequestHeader("Content-Type", "application/xml");
- HttpClient httpclient = new HttpClient();
-
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost("http://localhost:" + PORT + "/bookstore/books");
+ post.addHeader("Content-Type", "application/xml");
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(400, result);
+ CloseableHttpResponse response = client.execute(post);
+ assertEquals(400, response.getStatusLine().getStatusCode());
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
@@ -2312,21 +2314,20 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
}
private void doAddBook(String address) throws Exception {
- File input = new File(getClass().getResource("resources/add_book.txt").toURI());
- PostMethod post = new PostMethod(address);
- post.setRequestHeader("Content-Type", "application/xml");
- RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
-
+ File input = new File(getClass().getResource("resources/add_book.txt").toURI());
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost(address);
+ post.addHeader("Content-Type", "application/xml");
+ post.setEntity(new FileEntity(input, ContentType.TEXT_XML));
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(200, result);
-
+ CloseableHttpResponse response = client.execute(post);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+
InputStream expected = getClass().getResourceAsStream("resources/expected_add_book.txt");
-
- assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
- stripXmlInstructionIfNeeded(post.getResponseBodyAsString()));
+
+ assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
+ stripXmlInstructionIfNeeded(EntityUtils.toString(response.getEntity())));
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
@@ -2351,17 +2352,16 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/books";
File input = new File(getClass().getResource("resources/update_book.txt").toURI());
- PutMethod put = new PutMethod(endpointAddress);
- RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
- put.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPut put = new HttpPut(endpointAddress);
+ put.setEntity(new FileEntity(input, ContentType.TEXT_XML));
try {
- int result = httpclient.executeMethod(put);
- assertEquals(200, result);
+ CloseableHttpResponse response = client.execute(put);
+ assertEquals(200, response.getStatusLine().getStatusCode());
InputStream expected = getClass().getResourceAsStream("resources/expected_update_book.txt");
- assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
- stripXmlInstructionIfNeeded(getStringFromInputStream(put.getResponseBodyAsStream())));
+ assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
+ stripXmlInstructionIfNeeded(EntityUtils.toString(response.getEntity())));
} finally {
// Release current connection to the connection pool once you are
// done
@@ -2374,14 +2374,13 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/bookswithdom";
File input = new File(getClass().getResource("resources/update_book.txt").toURI());
- PutMethod put = new PutMethod(endpointAddress);
- RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
- put.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPut put = new HttpPut(endpointAddress);
+ put.setEntity(new FileEntity(input, ContentType.TEXT_XML));
try {
- int result = httpclient.executeMethod(put);
- assertEquals(200, result);
- String resp = put.getResponseBodyAsString();
+ CloseableHttpResponse response = client.execute(put);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ String resp = EntityUtils.toString(response.getEntity());
InputStream expected = getClass().getResourceAsStream("resources/update_book.txt");
String s = getStringFromInputStream(expected);
//System.out.println(resp);
@@ -2399,17 +2398,16 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/bookswithjson";
File input = new File(getClass().getResource("resources/update_book_json.txt").toURI());
- PutMethod put = new PutMethod(endpointAddress);
- RequestEntity entity = new FileRequestEntity(input, "application/json; charset=ISO-8859-1");
- put.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPut put = new HttpPut(endpointAddress);
+ put.setEntity(new FileEntity(input, ContentType.APPLICATION_JSON));
try {
- int result = httpclient.executeMethod(put);
- assertEquals(200, result);
+ CloseableHttpResponse response = client.execute(put);
+ assertEquals(200, response.getStatusLine().getStatusCode());
InputStream expected = getClass().getResourceAsStream("resources/expected_update_book.txt");
- assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
- stripXmlInstructionIfNeeded(getStringFromInputStream(put.getResponseBodyAsStream())));
+ assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
+ stripXmlInstructionIfNeeded(EntityUtils.toString(response.getEntity())));
} finally {
// Release current connection to the connection pool once you are
// done
@@ -2422,21 +2420,20 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress =
"http://localhost:" + PORT + "/bookstore/books";
- File input = new File(getClass().getResource("resources/update_book_not_exist.txt").toURI());
- PutMethod post = new PutMethod(endpointAddress);
- RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
-
+ File input = new File(getClass().getResource("resources/update_book_not_exist.txt").toURI());
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPut put = new HttpPut(endpointAddress);
+ put.setEntity(new FileEntity(input, ContentType.TEXT_XML));
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(304, result);
+ CloseableHttpResponse response = client.execute(put);
+ assertEquals(304, response.getStatusLine().getStatusCode());
} finally {
// Release current connection to the connection pool once you are done
- post.releaseConnection();
- }
- }
-
+ put.releaseConnection();
+ }
+ }
+
@Test
public void testGetCDs() throws Exception {
@@ -2456,23 +2453,22 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
"application/json", "application/json", 200);
}
-
- @SuppressWarnings("deprecation")
+
@Test
public void testGetPlainLong() throws Exception {
String endpointAddress =
"http://localhost:" + PORT + "/bookstore/booksplain";
- PostMethod post = new PostMethod(endpointAddress);
- post.addRequestHeader("Content-Type", "text/plain");
- post.addRequestHeader("Accept", "text/plain");
- post.setRequestBody("12345");
- HttpClient httpclient = new HttpClient();
-
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost(endpointAddress);
+ post.addHeader("Content-Type", "text/plain");
+ post.addHeader("Accept", "text/plain");
+ post.setEntity(new StringEntity("12345"));
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(200, result);
- assertEquals(post.getResponseBodyAsString(), "12345");
+ CloseableHttpResponse response = client.execute(post);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals(EntityUtils.toString(response.getEntity()), "12345");
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
@@ -2484,16 +2480,16 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress =
"http://localhost:" + PORT + "/bookstore/books/123";
- DeleteMethod post = new DeleteMethod(endpointAddress);
- HttpClient httpclient = new HttpClient();
-
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpDelete delete = new HttpDelete(endpointAddress);
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(200, result);
+ CloseableHttpResponse response = client.execute(delete);
+ assertEquals(200, response.getStatusLine().getStatusCode());
} finally {
// Release current connection to the connection pool once you are done
- post.releaseConnection();
- }
+ delete.releaseConnection();
+ }
}
@Test
@@ -2501,16 +2497,16 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress =
"http://localhost:" + PORT + "/bookstore/books/id?value=123";
- DeleteMethod post = new DeleteMethod(endpointAddress);
- HttpClient httpclient = new HttpClient();
-
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpDelete delete = new HttpDelete(endpointAddress);
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(200, result);
+ CloseableHttpResponse response = client.execute(delete);
+ assertEquals(200, response.getStatusLine().getStatusCode());
} finally {
// Release current connection to the connection pool once you are done
- post.releaseConnection();
- }
+ delete.releaseConnection();
+ }
}
@Test
@@ -2519,20 +2515,20 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String endpointAddress =
"http://localhost:" + PORT + "/bookstore/cds";
- GetMethod get = new GetMethod(endpointAddress);
- get.addRequestHeader("Accept", "application/json");
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(endpointAddress);
+ get.addHeader("Accept", "application/json");
- HttpClient httpclient = new HttpClient();
-
try {
- int result = httpclient.executeMethod(get);
- assertEquals(200, result);
+ CloseableHttpResponse response = client.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
InputStream expected123 = getClass().getResourceAsStream("resources/expected_get_cdsjson123.txt");
InputStream expected124 = getClass().getResourceAsStream("resources/expected_get_cdsjson124.txt");
-
- assertTrue(get.getResponseBodyAsString().indexOf(getStringFromInputStream(expected123)) >= 0);
- assertTrue(get.getResponseBodyAsString().indexOf(getStringFromInputStream(expected124)) >= 0);
+
+ String content = EntityUtils.toString(response.getEntity());
+ assertTrue(content.indexOf(getStringFromInputStream(expected123)) >= 0);
+ assertTrue(content.indexOf(getStringFromInputStream(expected124)) >= 0);
} finally {
// Release current connection to the connection pool once you are done
@@ -2716,28 +2712,29 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
String acceptType,
String expectedContentType,
int expectedStatus) throws Exception {
- GetMethod get = new GetMethod(address);
- get.setRequestHeader("Accept", acceptType);
- get.addRequestHeader("Cookie", "a=b;c=d");
- get.addRequestHeader("Cookie", "e=f");
- get.setRequestHeader("Accept-Language", "da;q=0.8,en");
- get.setRequestHeader("Book", "1,2,3");
- HttpClient httpClient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(address);
+ get.addHeader("Accept", acceptType);
+ get.addHeader("Cookie", "a=b;c=d");
+ get.addHeader("Cookie", "e=f");
+ get.addHeader("Accept-Language", "da;q=0.8,en");
+ get.addHeader("Book", "1,2,3");
+
try {
- int result = httpClient.executeMethod(get);
- assertEquals(expectedStatus, result);
- String content = getStringFromInputStream(get.getResponseBodyAsStream());
- assertEquals("Expected value is wrong",
+ CloseableHttpResponse response = client.execute(get);
+ assertEquals(expectedStatus, response.getStatusLine().getStatusCode());
+ String content = EntityUtils.toString(response.getEntity());
+ assertEquals("Expected value is wrong",
stripXmlInstructionIfNeeded(expectedValue), stripXmlInstructionIfNeeded(content));
if (expectedStatus == 200) {
- assertEquals("123", get.getResponseHeader("BookId").getValue());
- assertNotNull(get.getResponseHeader("Date"));
+ assertEquals("123", response.getFirstHeader("BookId").getValue());
+ assertNotNull(response.getFirstHeader("Date"));
}
if (expectedStatus == 405) {
- assertNotNull(get.getResponseHeader("Allow"));
+ assertNotNull(response.getFirstHeader("Allow"));
}
if (expectedContentType != null) {
- Header ct = get.getResponseHeader("Content-Type");
+ Header ct = response.getFirstHeader("Content-Type");
assertEquals("Wrong type of response", expectedContentType, ct.getValue());
}
} finally {
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
index dcfafba..81d3905 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
@@ -27,16 +27,18 @@ import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
-
+import org.apache.http.Header;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -242,19 +244,19 @@ public class JAXRSClientServerNonSpringBookTest extends AbstractBusClientServerT
String acceptType,
String expectedContentType,
int expectedStatus) throws Exception {
- GetMethod get = new GetMethod(address);
- get.setRequestHeader("Accept", acceptType);
- get.setRequestHeader("Accept-Language", "da;q=0.8,en");
- get.setRequestHeader("Book", "1,2,3");
- HttpClient httpClient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(address);
+ get.setHeader("Accept", acceptType);
+ get.setHeader("Accept-Language", "da;q=0.8,en");
+ get.setHeader("Book", "1,2,3");
try {
- int result = httpClient.executeMethod(get);
- assertEquals(expectedStatus, result);
- String content = getStringFromInputStream(get.getResponseBodyAsStream());
- assertEquals("Expected value is wrong",
+ CloseableHttpResponse response = client.execute(get);
+ assertEquals(expectedStatus, response.getStatusLine().getStatusCode());
+ String content = EntityUtils.toString(response.getEntity());
+ assertEquals("Expected value is wrong",
stripXmlInstructionIfNeeded(expectedValue), stripXmlInstructionIfNeeded(content));
if (expectedContentType != null) {
- Header ct = get.getResponseHeader("Content-Type");
+ Header ct = response.getFirstHeader("Content-Type");
assertEquals("Wrong type of response", expectedContentType, ct.getValue());
}
} finally {
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index 8adf83f..8a79a9c 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -49,10 +49,6 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.FileRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
@@ -64,6 +60,13 @@ import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
import org.apache.cxf.jaxrs.provider.aegis.AegisElementProvider;
import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
import org.apache.ws.commons.schema.constants.Constants;
import org.junit.BeforeClass;
@@ -90,7 +93,7 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
Book book = wc.replaceHeader("Accept", "application/xml").query("id", 1L).get(Book.class);
assertEquals("CXF", book.getName());
}
-
+
@Test
public void testGetDocuments() throws Exception {
String baseAddress = "http://localhost:" + PORT + "/the/thedocs/resource/doc";
@@ -172,13 +175,13 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform4";
doTestEchoBookForm(address);
}
-
+
@Test
public void testEchoBookForm5() throws Exception {
String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform5";
doTestEchoBookForm(address);
}
-
+
private void doTestEchoBookForm(String address) throws Exception {
WebClient wc = WebClient.create(address);
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
@@ -995,24 +998,22 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
private void doPost(String endpointAddress, int expectedStatus, String contentType,
String inResource, String expectedResource) throws Exception {
-
- File input = new File(getClass().getResource(inResource).toURI());
- PostMethod post = new PostMethod(endpointAddress);
- post.setRequestHeader("Content-Type", contentType);
- RequestEntity entity = new FileRequestEntity(input, "text/xml");
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
-
+ File input = new File(getClass().getResource(inResource).toURI());
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost(endpointAddress);
+ post.setHeader("Content-Type", contentType);
+ post.setEntity(new FileEntity(input, ContentType.TEXT_XML));
+
try {
- int result = httpclient.executeMethod(post);
- assertEquals(expectedStatus, result);
-
+ CloseableHttpResponse response = client.execute(post);
+ assertEquals(expectedStatus, response.getStatusLine().getStatusCode());
+
if (expectedStatus != 400) {
InputStream expected = getClass().getResourceAsStream(expectedResource);
- assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
- stripXmlInstructionIfNeeded(post.getResponseBodyAsString()));
+ assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
+ stripXmlInstructionIfNeeded(EntityUtils.toString(response.getEntity())));
} else {
- assertTrue(post.getResponseBodyAsString()
+ assertTrue(EntityUtils.toString(response.getEntity())
.contains("Cannot find the declaration of element"));
}
} finally {
http://git-wip-us.apache.org/repos/asf/cxf/blob/d279286a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
index ac940d0..492cbd1 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
@@ -37,8 +37,6 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLStreamWriter;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
@@ -47,7 +45,10 @@ import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
import org.apache.cxf.staxutils.CachingXmlEventWriter;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
-
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -128,13 +129,13 @@ public class JAXRSClientServerStreamingTest extends AbstractBusClientServerTestB
private void getAndCompare(String address,
String acceptType,
int expectedStatus) throws Exception {
- GetMethod get = new GetMethod(address);
- get.setRequestHeader("Accept", acceptType);
- HttpClient httpClient = new HttpClient();
+ CloseableHttpClient client = HttpClientBuilder.create().build();
+ HttpGet get = new HttpGet(address);
+ get.setHeader("Accept", acceptType);
try {
- int result = httpClient.executeMethod(get);
- assertEquals(expectedStatus, result);
- Book book = readBook(get.getResponseBodyAsStream());
+ CloseableHttpResponse response = client.execute(get);
+ assertEquals(expectedStatus, response.getStatusLine().getStatusCode());
+ Book book = readBook(response.getEntity().getContent());
assertEquals(123, book.getId());
assertEquals("CXF in Action", book.getName());
} finally {