From dd2c1fee7754f3f54f9e7f6f6b0b46f445bf8b78 Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Tue, 6 Dec 2022 18:49:44 +0000 Subject: [PATCH] Java 15017 (#13080) * [JAVA-15017] Upgraded httpClient version to 5.2 * [JAVA-15017] Added CustomResponseHandler in favour of upgrading deprecated execute() method * [JAVA-15017] Replaced CustomResponseHandler with BasicHttpClientResponseHandler Co-authored-by: panagiotiskakos --- .../ApacheHttpClient5UnitTest.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java index 35b21789ef..9a79cbf491 100644 --- a/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java +++ b/apache-httpclient-2/src/test/java/com/baeldung/httpclient/readresponsebodystring/ApacheHttpClient5UnitTest.java @@ -1,29 +1,27 @@ package com.baeldung.httpclient.readresponsebodystring; import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.BasicHttpClientResponseHandler; 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.junit.jupiter.api.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 { + public void whenUseApacheHttpClient_thenCorrect() throws IOException { 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)); + try (CloseableHttpClient client = HttpClients.createDefault()) { + String response = client.execute(request, new BasicHttpClientResponseHandler()); + logger.debug("Response -> {}", response); } } } \ No newline at end of file