You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/03/17 11:55:42 UTC
[camel] 14/15: CAMEL-18995: camel-cxf - Upgrade to HttpComponents 5.x
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch CAMEL-18995/upgrade-httpcomponents-5
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 2d49cc30a536bee6a6f2866ae6ac60dc693fa9ee
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Mar 17 12:38:12 2023 +0100
CAMEL-18995: camel-cxf - Upgrade to HttpComponents 5.x
---
components/camel-cxf/camel-cxf-rest/pom.xml | 13 +--
.../cxf/jaxrs/CxfRsConsumerWithBeanTest.java | 25 +++---
.../cxf/jaxrs/CxfRsConvertBodyToTest.java | 25 +++---
.../cxf/jaxrs/CxfRsResponseWithHeadersTest.java | 25 +++---
.../component/cxf/jaxrs/CxfRsStreamCacheTest.java | 27 +++---
.../CxfRsConsumerSimpleBindingImplTest.java | 20 ++---
.../CxfRsConsumerSimpleBindingTest.java | 79 +++++++++---------
components/camel-cxf/camel-cxf-soap/pom.xml | 6 +-
...t.java => CxfConsumerNamespacePayLoadTest.java} | 27 +++---
components/camel-cxf/camel-cxf-spring-rest/pom.xml | 13 +--
.../component/cxf/jaxrs/CxfRsConsumerTest.java | 39 ++++-----
.../cxf/jaxrs/CxfRsEndpointWithPropertiesTest.java | 18 ++--
.../camel/component/cxf/jaxrs/CxfRsRouterTest.java | 95 ++++++++--------------
.../cxf/jaxrs/CxfRsSpringConsumerTest.java | 19 ++---
.../CxfRsConsumerSimpleBindingImplTest.java | 20 ++---
.../CxfRsConsumerSimpleBindingTest.java | 79 +++++++++---------
components/camel-cxf/camel-cxf-spring-soap/pom.xml | 6 +-
.../cxf/CxfPayloadRouterContentLengthTest.java | 48 +++++------
18 files changed, 255 insertions(+), 329 deletions(-)
diff --git a/components/camel-cxf/camel-cxf-rest/pom.xml b/components/camel-cxf/camel-cxf-rest/pom.xml
index c971930c34a..fb7de2bfb62 100644
--- a/components/camel-cxf/camel-cxf-rest/pom.xml
+++ b/components/camel-cxf/camel-cxf-rest/pom.xml
@@ -163,16 +163,9 @@
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpclient4-version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpmime</artifactId>
- <version>${httpclient4-version}</version>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <version>${httpclient-version}</version>
<scope>test</scope>
</dependency>
diff --git a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
index 6a2ef98bb3e..8b067475d97 100644
--- a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
+++ b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
@@ -21,12 +21,13 @@ import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.component.cxf.jaxrs.testbean.ServiceUtil;
import org.apache.camel.spi.Registry;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpPut;
-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.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -63,17 +64,13 @@ public class CxfRsConsumerWithBeanTest extends CamelTestSupport {
private void sendPutRequest(String uri) throws Exception {
HttpPut put = new HttpPut(uri);
- StringEntity entity = new StringEntity("string");
- entity.setContentType("text/plain");
+ StringEntity entity = new StringEntity("string", ContentType.TEXT_PLAIN);
put.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(put)) {
+ assertEquals(200, response.getCode());
assertEquals("c20string", EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
}
diff --git a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java
index da32417f645..8f9814124fd 100644
--- a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java
+++ b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConvertBodyToTest.java
@@ -23,12 +23,13 @@ import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpPut;
-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.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -63,18 +64,14 @@ public class CxfRsConvertBodyToTest extends CamelTestSupport {
mock.message(0).body().isInstanceOf(Customer.class);
HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
- StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
- entity.setContentType("text/xml; charset=ISO-8859-1");
+ StringEntity entity = new StringEntity(PUT_REQUEST, ContentType.parse("text/xml; charset=ISO-8859-1"));
put.addHeader("test", "header1;header2");
put.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(put)) {
+ assertEquals(200, response.getCode());
assertEquals("", EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
diff --git a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java
index 80cec6ae71d..818646360da 100644
--- a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java
+++ b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsResponseWithHeadersTest.java
@@ -20,12 +20,13 @@ import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpPut;
-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.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -54,17 +55,13 @@ public class CxfRsResponseWithHeadersTest extends CamelTestSupport {
@Test
public void testPutConsumer() throws Exception {
HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
- StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
- entity.setContentType("text/xml; charset=ISO-8859-1");
+ StringEntity entity = new StringEntity(PUT_REQUEST, ContentType.parse("text/xml; charset=ISO-8859-1"));
put.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(put);
- assertEquals(404, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(put)) {
+ assertEquals(404, response.getCode());
assertEquals("Cannot find customer", EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
diff --git a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java
index a7829a3af0f..3070a4fb98d 100644
--- a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java
+++ b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsStreamCacheTest.java
@@ -24,12 +24,13 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.spi.Synchronization;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpPut;
-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.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -40,8 +41,8 @@ public class CxfRsStreamCacheTest extends CamelTestSupport {
private static final String CXT = CXFTestSupport.getPort1() + CONTEXT;
private static final String RESPONSE = "<pong xmlns=\"test/service\"/>";
- private String cxfRsEndpointUri = "cxfrs://http://localhost:" + CXT + "/rest?synchronous=" + isSynchronous()
- + "&dataFormat=PAYLOAD&resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
+ private final String cxfRsEndpointUri = "cxfrs://http://localhost:" + CXT + "/rest?synchronous=" + isSynchronous()
+ + "&dataFormat=PAYLOAD&resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -91,18 +92,14 @@ public class CxfRsStreamCacheTest extends CamelTestSupport {
onComplete.expectedMessageCount(1);
HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
- StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
- entity.setContentType("text/xml; charset=ISO-8859-1");
+ StringEntity entity = new StringEntity(PUT_REQUEST, ContentType.parse("text/xml; charset=ISO-8859-1"));
put.addHeader("test", "header1;header2");
put.setEntity(entity);
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpResponse response = httpclient.execute(put)) {
+ assertEquals(200, response.getCode());
assertEquals(RESPONSE, EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
mock.assertIsSatisfied();
diff --git a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
index 3e1fd441704..87e8f660d3a 100644
--- a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
+++ b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
@@ -29,12 +29,12 @@ import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Order;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Product;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -103,8 +103,8 @@ public class CxfRsConsumerSimpleBindingImplTest extends CamelTestSupport {
public void testGetCustomerOnlyHeaders() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getCode());
Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent());
assertEquals(123, entity.getId());
}
@@ -117,7 +117,7 @@ public class CxfRsConsumerSimpleBindingImplTest extends CamelTestSupport {
post.setEntity(new StringEntity(sw.toString()));
post.addHeader("Content-Type", "text/xml");
post.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
}
diff --git a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
index 767019c9498..f9fcca8c087 100644
--- a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
+++ b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
@@ -37,20 +37,19 @@ import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Order;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Product;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.cxf.message.MessageContentsList;
-import org.apache.http.Consts;
-import org.apache.http.HttpResponse;
-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.InputStreamEntity;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.MultipartEntityBuilder;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
+import org.apache.hc.client5.http.classic.methods.HttpDelete;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.InputStreamEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -213,8 +212,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
public void testGetCustomerOnlyHeaders() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getCode());
Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent());
assertEquals(123, entity.getId());
}
@@ -223,8 +222,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
public void testGetCustomerHttp404CustomStatus() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/456");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(404, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(404, response.getCode());
}
@Test
@@ -235,8 +234,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
put.setEntity(new StringEntity(sw.toString()));
put.addHeader("Content-Type", "text/xml");
put.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getCode());
}
@Test
@@ -247,8 +246,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
post.setEntity(new StringEntity(sw.toString()));
post.addHeader("Content-Type", "text/xml");
post.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -256,8 +255,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold");
get.addHeader("Content-Type", "text/xml");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getCode());
CustomerList cl = (CustomerList) jaxb.createUnmarshaller()
.unmarshal(new StringReader(EntityUtils.toString(response.getEntity())));
List<Customer> vips = cl.getCustomers();
@@ -274,16 +273,16 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
put.setEntity(new StringEntity(sw.toString()));
put.addHeader("Content-Type", "text/xml");
put.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getCode());
}
@Test
public void testDeleteVipCustomer() throws Exception {
HttpDelete delete = new HttpDelete("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold/123");
delete.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(delete);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(delete);
+ assertEquals(200, response.getCode());
}
@Test
@@ -291,9 +290,9 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_inputstream");
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
- post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100));
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100, null));
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -301,9 +300,9 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_datahandler");
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
- post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100));
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100, null));
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -317,10 +316,10 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
ContentType.create("image/jpeg"), "java.jpg");
StringWriter sw = new StringWriter();
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
- builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8));
+ builder.addTextBody("body", sw.toString(), ContentType.TEXT_XML);
post.setEntity(builder.build());
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -334,10 +333,10 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
ContentType.create("image/jpeg"), "java.jpg");
StringWriter sw = new StringWriter();
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
- builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8));
+ builder.addTextBody("body", sw.toString(), ContentType.TEXT_XML);
post.setEntity(builder.build());
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
}
diff --git a/components/camel-cxf/camel-cxf-soap/pom.xml b/components/camel-cxf/camel-cxf-soap/pom.xml
index 019935364ce..c3538ae0101 100644
--- a/components/camel-cxf/camel-cxf-soap/pom.xml
+++ b/components/camel-cxf/camel-cxf-soap/pom.xml
@@ -180,9 +180,9 @@
</dependency>
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpclient4-version}</version>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <version>${httpclient-version}</version>
<scope>test</scope>
</dependency>
diff --git a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConusmerNamespacePayLoadTest.java b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConsumerNamespacePayLoadTest.java
similarity index 79%
rename from components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConusmerNamespacePayLoadTest.java
rename to components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConsumerNamespacePayLoadTest.java
index 1fe8edf649f..a11b332011f 100644
--- a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConusmerNamespacePayLoadTest.java
+++ b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfConsumerNamespacePayLoadTest.java
@@ -16,19 +16,19 @@
*/
package org.apache.camel.component.cxf.jaxws;
-import org.apache.http.HttpResponse;
-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.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class CxfConusmerNamespacePayLoadTest extends CxfConsumerPayloadTest {
+public class CxfConsumerNamespacePayLoadTest extends CxfConsumerPayloadTest {
private static final String ECHO_RESPONSE = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body><ns1:echoResponse xmlns:ns1=\"http://jaxws.cxf.component.camel.apache.org/\">"
+ "<return xmlns=\"http://jaxws.cxf.component.camel.apache.org/\">echo Hello World!</return>"
@@ -43,7 +43,7 @@ public class CxfConusmerNamespacePayLoadTest extends CxfConsumerPayloadTest {
protected void checkRequest(String expect, String request) {
if (expect.equals(ECHO_REQUEST)) {
// just check the namespace of xsd
- assertTrue(request.indexOf("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"") > 0, "Expect to find the namesapce");
+ assertTrue(request.indexOf("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"") > 0, "Expect to find the namespace");
}
}
@@ -56,16 +56,13 @@ public class CxfConusmerNamespacePayLoadTest extends CxfConsumerPayloadTest {
StringEntity entity = new StringEntity(ECHO_REQUEST, ContentType.create("text/xml", "ISO-8859-1"));
post.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(post)) {
+ assertEquals(200, response.getCode());
String responseBody = EntityUtils.toString(response.getEntity());
assertEquals(ECHO_RESPONSE, responseBody, "Get a wrong response");
- } finally {
- httpclient.close();
}
}
diff --git a/components/camel-cxf/camel-cxf-spring-rest/pom.xml b/components/camel-cxf/camel-cxf-spring-rest/pom.xml
index 3172a6b8d02..012d4df4ceb 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/pom.xml
+++ b/components/camel-cxf/camel-cxf-spring-rest/pom.xml
@@ -157,16 +157,9 @@
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpclient4-version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpmime</artifactId>
- <version>${httpclient4-version}</version>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <version>${httpclient-version}</version>
<scope>test</scope>
</dependency>
diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
index 6f1d58acb8b..ac356a95696 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
+++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
@@ -45,13 +45,14 @@ import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.component.cxf.jaxrs.testbean.CustomerService;
import org.apache.camel.spi.Registry;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPut;
-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.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -106,15 +107,11 @@ public class CxfRsConsumerTest extends CamelTestSupport {
private void invokeGetCustomer(String uri, String expect) throws Exception {
HttpGet get = new HttpGet(uri);
get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
- assertEquals(expect,
- EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(get)) {
+ assertEquals(200, response.getCode());
+ assertEquals(expect, EntityUtils.toString(response.getEntity()));
}
}
@@ -209,18 +206,14 @@ public class CxfRsConsumerTest extends CamelTestSupport {
@Test
public void testPutConsumer() throws Exception {
HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
- StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
- entity.setContentType("text/xml; charset=ISO-8859-1");
+ StringEntity entity = new StringEntity(PUT_REQUEST, ContentType.parse("text/xml; charset=ISO-8859-1"));
put.addHeader("test", "header1;header2");
put.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(put)) {
+ assertEquals(200, response.getCode());
assertEquals("", EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithPropertiesTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithPropertiesTest.java
index 5f425439f16..cdc4040f1ce 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithPropertiesTest.java
+++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpointWithPropertiesTest.java
@@ -22,10 +22,10 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.component.cxf.spring.AbstractSpringBeanTestSupport;
import org.apache.cxf.feature.Feature;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -52,12 +52,10 @@ public class CxfRsEndpointWithPropertiesTest extends AbstractSpringBeanTestSuppo
assertEquals("aValue", endpointProps.get("aKey"), "Wrong property value");
HttpGet get = new HttpGet(testEndpoint.getAddress());
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(get);
- assertEquals(404, response.getStatusLine().getStatusCode());
- } finally {
- httpclient.close();
+
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(get)) {
+ assertEquals(404, response.getCode());
}
}
diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
index 31904e7e7cd..45fa5ea6531 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
+++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
@@ -18,15 +18,16 @@ package org.apache.camel.component.cxf.jaxrs;
import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
-import org.apache.http.HttpResponse;
-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.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
+import org.apache.hc.client5.http.classic.methods.HttpDelete;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -64,15 +65,12 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
public void testGetCustomer() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/123");
get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(get)) {
+ assertEquals(200, response.getCode());
assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
@@ -80,15 +78,12 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
public void testGetCustomerWithQuery() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers?id=123");
get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(get)) {
+ assertEquals(200, response.getCode());
assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
@@ -96,11 +91,10 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
public void testGetCustomers() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/");
get.addHeader("Accept", "application/xml");
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(get)) {
+ assertEquals(200, response.getCode());
// order returned can differ on OS so match for both orders
String s = EntityUtils.toString(response.getEntity());
assertNotNull(s);
@@ -112,8 +106,6 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
if (!m1 && !m2) {
fail("Not expected body returned: " + s);
}
- } finally {
- httpclient.close();
}
}
@@ -122,32 +114,25 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
HttpGet get = new HttpGet(
"http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/orders/223/products/323");
get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(get)) {
+ assertEquals(200, response.getCode());
assertEquals("{\"Product\":{\"description\":\"product 323\",\"id\":323}}",
EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
@Test
public void testPutConsumer() throws Exception {
HttpPut put = new HttpPut("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers");
- StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
- entity.setContentType("text/xml; charset=ISO-8859-1");
+ StringEntity entity = new StringEntity(PUT_REQUEST, ContentType.parse("text/xml; charset=ISO-8859-1"));
put.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(put)) {
+ assertEquals(200, response.getCode());
assertEquals("", EntityUtils.toString(response.getEntity()));
- } finally {
- httpclient.close();
}
}
@@ -155,14 +140,12 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
public void testPostConsumer() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers");
post.addHeader("Accept", "text/xml");
- StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
- entity.setContentType("text/xml; charset=ISO-8859-1");
+ StringEntity entity = new StringEntity(POST_REQUEST, ContentType.parse("text/xml; charset=ISO-8859-1"));
post.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build()) {
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
assertEquals(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>124</id><name>Jack</name></Customer>",
EntityUtils.toString(response.getEntity()));
@@ -171,9 +154,7 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
= new HttpDelete("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/124/");
response = httpclient.execute(del);
// need to check the response of delete method
- assertEquals(200, response.getStatusLine().getStatusCode());
- } finally {
- httpclient.close();
+ assertEquals(200, response.getCode());
}
}
@@ -183,14 +164,12 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
HttpPost post = new HttpPost(
"http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customersUniqueResponseCode");
post.addHeader("Accept", "text/xml");
- StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
- entity.setContentType("text/xml; charset=ISO-8859-1");
+ StringEntity entity = new StringEntity(POST_REQUEST, ContentType.parse("text/xml; charset=ISO-8859-1"));
post.setEntity(entity);
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(post);
- assertEquals(201, response.getStatusLine().getStatusCode());
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build()) {
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(201, response.getCode());
assertEquals(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>124</id><name>Jack</name></Customer>",
EntityUtils.toString(response.getEntity()));
@@ -199,9 +178,7 @@ public class CxfRsRouterTest extends CamelSpringTestSupport {
= new HttpDelete("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/124/");
response = httpclient.execute(del);
// need to check the response of delete method
- assertEquals(200, response.getStatusLine().getStatusCode());
- } finally {
- httpclient.close();
+ assertEquals(200, response.getCode());
}
}
}
diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java
index c01274b90b7..780fdd807f6 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java
+++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringConsumerTest.java
@@ -25,10 +25,10 @@ import org.apache.camel.component.cxf.jaxrs.testbean.CustomException;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -92,15 +92,12 @@ public class CxfRsSpringConsumerTest extends CamelSpringTestSupport {
private void doTestMappingException(String address) throws Exception {
HttpGet get = new HttpGet(address);
get.addHeader("Accept", "application/json");
- CloseableHttpClient httpclient = HttpClientBuilder.create().build();
- try {
- HttpResponse response = httpclient.execute(get);
- assertEquals(500, response.getStatusLine().getStatusCode(), "Get a wrong status code");
+ try (CloseableHttpClient httpclient = HttpClientBuilder.create().build();
+ CloseableHttpResponse response = httpclient.execute(get)) {
+ assertEquals(500, response.getCode(), "Get a wrong status code");
assertEquals("exception: Here is the exception", response.getHeaders("exception")[0].toString(),
- "Get a worng message header");
- } finally {
- httpclient.close();
+ "Get a wrong message header");
}
}
diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
index 3e1fd441704..87e8f660d3a 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
+++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingImplTest.java
@@ -29,12 +29,12 @@ import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Order;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Product;
import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -103,8 +103,8 @@ public class CxfRsConsumerSimpleBindingImplTest extends CamelTestSupport {
public void testGetCustomerOnlyHeaders() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getCode());
Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent());
assertEquals(123, entity.getId());
}
@@ -117,7 +117,7 @@ public class CxfRsConsumerSimpleBindingImplTest extends CamelTestSupport {
post.setEntity(new StringEntity(sw.toString()));
post.addHeader("Content-Type", "text/xml");
post.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
}
diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
index 767019c9498..f9fcca8c087 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
+++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/simplebinding/CxfRsConsumerSimpleBindingTest.java
@@ -37,20 +37,19 @@ import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Order;
import org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Product;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.apache.cxf.message.MessageContentsList;
-import org.apache.http.Consts;
-import org.apache.http.HttpResponse;
-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.InputStreamEntity;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.MultipartEntityBuilder;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
+import org.apache.hc.client5.http.classic.methods.HttpDelete;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.InputStreamEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -213,8 +212,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
public void testGetCustomerOnlyHeaders() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getCode());
Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent());
assertEquals(123, entity.getId());
}
@@ -223,8 +222,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
public void testGetCustomerHttp404CustomStatus() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/456");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(404, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(404, response.getCode());
}
@Test
@@ -235,8 +234,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
put.setEntity(new StringEntity(sw.toString()));
put.addHeader("Content-Type", "text/xml");
put.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getCode());
}
@Test
@@ -247,8 +246,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
post.setEntity(new StringEntity(sw.toString()));
post.addHeader("Content-Type", "text/xml");
post.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -256,8 +255,8 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold");
get.addHeader("Content-Type", "text/xml");
get.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(get);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getCode());
CustomerList cl = (CustomerList) jaxb.createUnmarshaller()
.unmarshal(new StringReader(EntityUtils.toString(response.getEntity())));
List<Customer> vips = cl.getCustomers();
@@ -274,16 +273,16 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
put.setEntity(new StringEntity(sw.toString()));
put.addHeader("Content-Type", "text/xml");
put.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(put);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(put);
+ assertEquals(200, response.getCode());
}
@Test
public void testDeleteVipCustomer() throws Exception {
HttpDelete delete = new HttpDelete("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold/123");
delete.addHeader("Accept", "text/xml");
- HttpResponse response = httpclient.execute(delete);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(delete);
+ assertEquals(200, response.getCode());
}
@Test
@@ -291,9 +290,9 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_inputstream");
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
- post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100));
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100, null));
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -301,9 +300,9 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_datahandler");
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
- post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100));
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100, null));
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -317,10 +316,10 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
ContentType.create("image/jpeg"), "java.jpg");
StringWriter sw = new StringWriter();
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
- builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8));
+ builder.addTextBody("body", sw.toString(), ContentType.TEXT_XML);
post.setEntity(builder.build());
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
@Test
@@ -334,10 +333,10 @@ public class CxfRsConsumerSimpleBindingTest extends CamelTestSupport {
ContentType.create("image/jpeg"), "java.jpg");
StringWriter sw = new StringWriter();
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
- builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8));
+ builder.addTextBody("body", sw.toString(), ContentType.TEXT_XML);
post.setEntity(builder.build());
- HttpResponse response = httpclient.execute(post);
- assertEquals(200, response.getStatusLine().getStatusCode());
+ CloseableHttpResponse response = httpclient.execute(post);
+ assertEquals(200, response.getCode());
}
}
diff --git a/components/camel-cxf/camel-cxf-spring-soap/pom.xml b/components/camel-cxf/camel-cxf-spring-soap/pom.xml
index 1e607f1acce..3099abc7220 100644
--- a/components/camel-cxf/camel-cxf-spring-soap/pom.xml
+++ b/components/camel-cxf/camel-cxf-spring-soap/pom.xml
@@ -164,9 +164,9 @@
</dependency>
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpclient4-version}</version>
+ <groupId>org.apache.httpcomponents.client5</groupId>
+ <artifactId>httpclient5</artifactId>
+ <version>${httpclient-version}</version>
<scope>test</scope>
</dependency>
diff --git a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfPayloadRouterContentLengthTest.java b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfPayloadRouterContentLengthTest.java
index a3146e15948..e6be92b431a 100644
--- a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfPayloadRouterContentLengthTest.java
+++ b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfPayloadRouterContentLengthTest.java
@@ -28,14 +28,14 @@ import org.apache.camel.component.cxf.common.CXFTestSupport;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
import org.apache.camel.util.IOHelper;
-import org.apache.http.HttpEntity;
-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.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Request;
@@ -91,7 +91,7 @@ public class CxfPayloadRouterContentLengthTest extends CamelSpringTestSupport {
public void setUp() throws Exception {
/*
* We start a Jetty for the service in order to have better control over
- * the response The response must contain only a Content-Type and a
+ * the response. The response must contain only a Content-Type and a
* Content-Length but no other header
*/
LOG.info("Starting jetty server at port {}", JETTY_PORT);
@@ -149,28 +149,20 @@ public class CxfPayloadRouterContentLengthTest extends CamelSpringTestSupport {
}
@Test
- public void testInvokeRouter() throws IOException {
+ public void testInvokeRouter() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
long contentLength = 0;
boolean isChunked = false;
String receivedContent = null;
- try {
- HttpPost httppost = new HttpPost("http://localhost:" + CXFTestSupport.getPort1() + "/TEST/PROXY");
- StringEntity reqEntity = new StringEntity(REQUEST_MESSAGE, ContentType.TEXT_XML);
- reqEntity.setChunked(false);
- httppost.setEntity(reqEntity);
- CloseableHttpResponse response = httpclient.execute(httppost);
- try {
- HttpEntity respEntity = response.getEntity();
- contentLength = respEntity.getContentLength();
- isChunked = respEntity.isChunked();
- receivedContent = EntityUtils.toString(respEntity);
- EntityUtils.consume(response.getEntity());
- } finally {
- response.close();
- }
- } finally {
- httpclient.close();
+ HttpPost httppost = new HttpPost("http://localhost:" + CXFTestSupport.getPort1() + "/TEST/PROXY");
+ StringEntity reqEntity = new StringEntity(REQUEST_MESSAGE, ContentType.TEXT_XML, false);
+ httppost.setEntity(reqEntity);
+ try (httpclient; CloseableHttpResponse response = httpclient.execute(httppost)) {
+ HttpEntity respEntity = response.getEntity();
+ contentLength = respEntity.getContentLength();
+ isChunked = respEntity.isChunked();
+ receivedContent = EntityUtils.toString(respEntity);
+ EntityUtils.consume(response.getEntity());
}
assertNotNull(receivedContent);
// chunked encoding is fine, we don't need to check the content length
@@ -181,7 +173,7 @@ public class CxfPayloadRouterContentLengthTest extends CamelSpringTestSupport {
"[" + receivedContent + "] does not contain [" + RESPONSE_STRING + "]");
// check whether the response was cut off by the client because the
// Content-Length was wrong
- assertTrue(receivedContent.matches(".*\\</.*:Envelope\\>"),
+ assertTrue(receivedContent.matches(".*</.*:Envelope>"),
"[" + receivedContent + "] does not contain the closing Envelope tag.");
}