diff --git a/httpclient-2/pom.xml b/httpclient-2/pom.xml
index 881b0407c3..a6b2ede900 100644
--- a/httpclient-2/pom.xml
+++ b/httpclient-2/pom.xml
@@ -26,6 +26,11 @@
+
+ org.apache.httpcomponents.client5
+ httpclient5
+ ${httpclient5.version}
+
org.springframework.boot
@@ -63,6 +68,7 @@
4.5.8
+ 5.1
11
11
2.1.7.RELEASE
diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java b/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java
new file mode 100644
index 0000000000..35b21789ef
--- /dev/null
+++ b/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java
@@ -0,0 +1,29 @@
+package com.baeldung.httpclient.readresponsebodystring;
+
+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.HttpClients;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.ParseException;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public class ApacheHttpClient5UnitTest {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ public static final String DUMMY_URL = "https://postman-echo.com/get";
+
+ @Test
+ public void whenUseApacheHttpClient_thenCorrect() throws IOException, ParseException {
+ HttpGet request = new HttpGet(DUMMY_URL);
+
+ try (CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpResponse response = client.execute(request)) {
+ HttpEntity entity = response.getEntity();
+ logger.debug("Response -> {}", EntityUtils.toString(entity));
+ }
+ }
+}
\ No newline at end of file
diff --git a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java b/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java
index 5a638b2bd5..7625b415f2 100644
--- a/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java
+++ b/httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClientUnitTest.java
@@ -7,10 +7,13 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
public class ApacheHttpClientUnitTest {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
public static final String DUMMY_URL = "https://postman-echo.com/get";
@Test
@@ -19,8 +22,7 @@ public class ApacheHttpClientUnitTest {
try (CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpResponse response = client.execute(request)) {
HttpEntity entity = response.getEntity();
- String result = EntityUtils.toString(entity);
- System.out.println("Response -> " + result);
+ logger.debug("Response -> {}", EntityUtils.toString(entity));
}
}
}
diff --git a/httpclient-2/src/test/resources/logback.xml b/httpclient-2/src/test/resources/logback.xml
new file mode 100644
index 0000000000..366a94e86e
--- /dev/null
+++ b/httpclient-2/src/test/resources/logback.xml
@@ -0,0 +1,15 @@
+
+
+
+ %date [%level] %logger - %msg %n
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file