[JAVA-15031] Upgraded code for apache httpclient + moved old version to apache-httpclient4 module. (#13830)

This commit is contained in:
panos-kakos
2023-04-14 16:18:26 +03:00
committed by GitHub
parent fa754156bd
commit 5b9e023fd3
4 changed files with 99 additions and 28 deletions

View File

@@ -1,8 +1,8 @@
package com.baeldung.httpclient.base;
import com.baeldung.httpclient.ResponseUtil;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -10,7 +10,6 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.junit.After;
import org.junit.Before;
@@ -73,30 +72,4 @@ public class HttpClientLiveTest {
assertThat(headers, not(emptyArray()));
}
// tests - cancel request
@Test
public final void whenRequestIsCanceled_thenCorrect() throws IOException {
instance = HttpClients.custom().build();
final HttpGet request = new HttpGet(SAMPLE_URL);
response = instance.execute(request);
try {
final HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
System.out.println("----------------------------------------");
// Do not feel like reading the response body
// Call abort on the request object
request.abort();
} finally {
response.close();
}
}
}