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 <panagiotis.kakos@libra-is.com>
This commit is contained in:
parent
0a0d532995
commit
dd2c1fee77
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue