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:40:20 UTC
[camel] 02/19: CAMEL-18995: camel-itest - 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 293ae7ac748da2800dd527812c2215474c0c0253
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Mar 17 12:18:20 2023 +0100
CAMEL-18995: camel-itest - Upgrade to HttpComponents 5.x
---
tests/camel-itest/pom.xml | 6 +--
.../itest/http/HttpMaxConnectionPerHostTest.java | 23 +++------
.../apache/camel/itest/http/HttpTestServer.java | 56 ++++++++--------------
3 files changed, 28 insertions(+), 57 deletions(-)
diff --git a/tests/camel-itest/pom.xml b/tests/camel-itest/pom.xml
index aa4da7d9998..768d40c97df 100644
--- a/tests/camel-itest/pom.xml
+++ b/tests/camel-itest/pom.xml
@@ -329,9 +329,9 @@
<!-- for http component tests -->
<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>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
index b1376313038..80fe08bd179 100644
--- a/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpMaxConnectionPerHostTest.java
@@ -16,21 +16,15 @@
*/
package org.apache.camel.itest.http;
-import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringTest;
-import org.apache.http.Consts;
-import org.apache.http.HttpException;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -54,14 +48,9 @@ public class HttpMaxConnectionPerHostTest {
@BeforeAll
public static void setUp() throws Exception {
localServer = new HttpTestServer();
- localServer.register("/", new HttpRequestHandler() {
- public void handle(
- HttpRequest request, HttpResponse response,
- HttpContext context)
- throws HttpException, IOException {
- response.setStatusCode(HttpStatus.SC_OK);
- response.setEntity(new StringEntity("OK", Consts.ISO_8859_1));
- }
+ localServer.register("/", (request, response, context) -> {
+ response.setCode(HttpStatus.SC_OK);
+ response.setEntity(new StringEntity("OK", StandardCharsets.ISO_8859_1));
});
localServer.start();
}
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
index 5f9ed3614d5..ba78d1decae 100644
--- a/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
@@ -16,16 +16,16 @@
*/
package org.apache.camel.itest.http;
+import java.util.concurrent.TimeUnit;
+
import org.apache.camel.test.AvailablePortFinder;
-import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.config.SocketConfig;
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.bootstrap.HttpServer;
-import org.apache.http.impl.bootstrap.ServerBootstrap;
-import org.apache.http.localserver.EchoHandler;
-import org.apache.http.localserver.RandomHandler;
-import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.protocol.UriHttpRequestHandlerMapper;
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.apache.hc.core5.http.io.HttpRequestHandler;
+import org.apache.hc.core5.http.io.SocketConfig;
+import org.apache.hc.core5.util.Timeout;
/**
* Copy of org.apache.http.localserver.LocalTestServer to use a specific port.
@@ -35,9 +35,9 @@ public class HttpTestServer {
public static final int PORT = AvailablePortFinder.getNextAvailable();
/** The request handler registry. */
- private final UriHttpRequestHandlerMapper handlerRegistry;
+ private final ServerBootstrap bootstrap;
- private final HttpServer httpServer;
+ private HttpServer httpServer;
static {
//set them as system properties so Spring can use the property placeholder
@@ -50,43 +50,22 @@ public class HttpTestServer {
*
*/
public HttpTestServer() {
- this.handlerRegistry = new UriHttpRequestHandlerMapper();
-
SocketConfig socketConfig = SocketConfig.custom()
- .setSoTimeout(60000)
+ .setSoTimeout(Timeout.of(60, TimeUnit.SECONDS))
.setRcvBufSize(8 * 1024)
.setSndBufSize(8 * 1024)
.setTcpNoDelay(true)
.build();
-
- this.httpServer = ServerBootstrap.bootstrap()
+ this.bootstrap = ServerBootstrap.bootstrap()
.setListenerPort(PORT)
.setConnectionReuseStrategy(newConnectionReuseStrategy())
- .setHandlerMapper(handlerRegistry)
- .setSocketConfig(socketConfig)
- .setServerInfo("LocalTestServer/1.1")
- .create();
+ .setSocketConfig(socketConfig);
}
protected ConnectionReuseStrategy newConnectionReuseStrategy() {
return new DefaultConnectionReuseStrategy();
}
- /**
- * {@link #register Registers} a set of default request handlers.
- *
- * <pre>
- * URI pattern Handler
- * ----------- -------
- * /echo/* {@link EchoHandler EchoHandler}
- * /random/* {@link RandomHandler RandomHandler}
- * </pre>
- */
- public void registerDefaultHandlers() {
- handlerRegistry.register("/echo/*", new EchoHandler());
- handlerRegistry.register("/random/*", new RandomHandler());
- }
-
/**
* Registers a handler with the local registry.
*
@@ -94,13 +73,14 @@ public class HttpTestServer {
* @param handler the handler to apply
*/
public void register(String pattern, HttpRequestHandler handler) {
- handlerRegistry.register(pattern, handler);
+ bootstrap.register(pattern, handler);
}
/**
* Starts this test server.
*/
public void start() throws Exception {
+ httpServer = bootstrap.create();
httpServer.start();
}
@@ -108,6 +88,8 @@ public class HttpTestServer {
* Stops this test server.
*/
public void stop() {
- httpServer.stop();
+ if (httpServer != null) {
+ httpServer.stop();
+ }
}
}