use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project metis-framework by europeana.
the class StringHttpClientTest method createResult.
@Test
void createResult() throws URISyntaxException, IOException {
List<Closeable> closeables = new ArrayList<>();
HttpEntity responseEntity = new BasicHttpEntity(new ByteArrayInputStream("content".getBytes()), ContentType.TEXT_PLAIN);
final ContentRetriever contentRetriever = ContentRetriever.forNonCloseableContent(responseEntity == null ? InputStream::nullInputStream : responseEntity::getContent, closeables::add);
StringContent actualContent = stringHttpClient.createResult(new URI("/resource/provided"), new URI("/resource/actual"), "text/plain", 7L, contentRetriever);
assertEquals("content", actualContent.getContent());
assertEquals("text/plain", actualContent.getContentType());
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseContentEntityChunkedHTTP10.
@Test
public void testResponseContentEntityChunkedHTTP10() throws Exception {
final HttpContext context = new BasicHttpContext(null);
context.setProtocolVersion(HttpVersion.HTTP_1_0);
final BasicClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null, true));
final ResponseContent interceptor = new ResponseContent();
interceptor.process(response, response.getEntity(), context);
final Header h1 = response.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
Assertions.assertNull(h1);
final Header h2 = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
Assertions.assertNull(h2);
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseConnControlEntityUnknownContentLengthExplicitKeepAlive.
@Test
public void testResponseConnControlEntityUnknownContentLengthExplicitKeepAlive() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
request.addHeader(new BasicHeader(HttpHeaders.CONNECTION, "keep-alive"));
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null));
final ResponseConnControl interceptor = new ResponseConnControl();
interceptor.process(response, response.getEntity(), context);
final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
Assertions.assertNotNull(header);
Assertions.assertEquals("keep-alive", header.getValue());
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project httpcomponents-core by apache.
the class TestStandardInterceptors method testResponseConnControlEntityUnknownContentLengthHTTP10.
@Test
public void testResponseConnControlEntityUnknownContentLengthHTTP10() throws Exception {
final HttpContext context = new BasicHttpContext(null);
context.setProtocolVersion(HttpVersion.HTTP_1_0);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
request.addHeader(new BasicHeader(HttpHeaders.CONNECTION, "keep-alive"));
context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
final BasicClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
response.setEntity(new BasicHttpEntity(EmptyInputStream.INSTANCE, null));
final ResponseConnControl interceptor = new ResponseConnControl();
interceptor.process(response, response.getEntity(), context);
final Header header = response.getFirstHeader(HttpHeaders.CONNECTION);
Assertions.assertNotNull(header);
Assertions.assertEquals("close", header.getValue());
}
use of org.apache.hc.core5.http.io.entity.BasicHttpEntity in project JAuswertung by dennisfabri.
the class SimpleHttpClient method put.
public boolean put(String url, String resultsAsCsv) throws IOException {
HttpPut putRequest = new HttpPut(url);
putRequest.setEntity(new BasicHttpEntity(new ByteArrayInputStream(resultsAsCsv.getBytes(StandardCharsets.UTF_8)), ContentType.TEXT_PLAIN));
try (CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(putRequest)) {
log.debug("Upload with response code {}: {}", response.getCode(), response.getReasonPhrase());
return isValid(response.getCode());
}
}
Aggregations