diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java index 9c83e80108..8695f3e627 100644 --- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java +++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java @@ -143,7 +143,7 @@ public Map execute(final String defaultURI, final Map { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); - Assertions.assertEquals("some stuff", EntityUtils.toString(response.getEntity())); + Assertions.assertEquals("some stuff", + EntityUtils.toString(response.getEntity(), 1024)); return null; }); } catch (final Exception ex) { diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java index aecc6b83fb..b9c2f7f5b1 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicIntegrationTest.java @@ -43,6 +43,8 @@ import java.util.concurrent.CountDownLatch; import java.util.function.Consumer; +import javax.net.ssl.SSLSocket; + import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.ContentType; @@ -87,8 +89,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import javax.net.ssl.SSLSocket; - abstract class ClassicIntegrationTest { private static final Timeout TIMEOUT = Timeout.ofMinutes(1); @@ -146,7 +146,7 @@ void testSimpleBasicHttpRequests() throws Exception { for (int r = 0; r < reqNo; r++) { final BasicClassicHttpRequest get = new BasicClassicHttpRequest(Method.GET, "/?" + r); try (final ClassicHttpResponse response = client.execute(host, get, context)) { - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); final byte[] expected = testData.get(r); Assertions.assertEquals(expected.length, received.length); @@ -184,7 +184,7 @@ void testSimpleHttpPostsWithContentLength() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final byte[] data = EntityUtils.toByteArray(entity); + final byte[] data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, null)); } }); @@ -201,7 +201,7 @@ void testSimpleHttpPostsWithContentLength() throws Exception { post.setEntity(new ByteArrayEntity(data, null)); try (final ClassicHttpResponse response = client.execute(host, post, context)) { - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); final byte[] expected = testData.get(r); Assertions.assertEquals(expected.length, received.length); @@ -239,7 +239,7 @@ void testSimpleHttpPostsChunked() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final byte[] data = EntityUtils.toByteArray(entity); + final byte[] data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, null, true)); } }); @@ -256,7 +256,7 @@ void testSimpleHttpPostsChunked() throws Exception { post.setEntity(new ByteArrayEntity(data, null, true)); try (final ClassicHttpResponse response = client.execute(host, post, context)) { - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); final byte[] expected = testData.get(r); Assertions.assertEquals(expected.length, received.length); @@ -293,7 +293,7 @@ void testSimpleHttpPostsHTTP10() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final byte[] data = EntityUtils.toByteArray(entity); + final byte[] data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, null)); } }); @@ -312,7 +312,7 @@ void testSimpleHttpPostsHTTP10() throws Exception { post.setEntity(new ByteArrayEntity(data, null)); try (final ClassicHttpResponse response = client.execute(host, post, context)) { - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); final byte[] expected = testData.get(r); Assertions.assertEquals(expected.length, received.length); @@ -376,7 +376,7 @@ void testHttpPostsWithExpectContinue() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final byte[] data = EntityUtils.toByteArray(entity); + final byte[] data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, null, true)); } }); @@ -393,7 +393,7 @@ void testHttpPostsWithExpectContinue() throws Exception { post.setEntity(new ByteArrayEntity(data, null, true)); try (final ClassicHttpResponse response = client.execute(host, post, context)) { - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); final byte[] expected = testData.get(r); Assertions.assertEquals(expected.length, received.length); @@ -565,7 +565,7 @@ void testHttpContent() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final String line = EntityUtils.toString(entity); + final String line = EntityUtils.toString(entity, Integer.MAX_VALUE); final ContentType contentType = ContentType.parse(entity.getContentType()); final Charset charset = ContentType.getCharset(contentType, StandardCharsets.UTF_8); response.setEntity(new RepeatingEntity(line, charset, n, n % 2 == 0)); @@ -614,7 +614,7 @@ void testHttpPostNoEntity() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final byte[] data = EntityUtils.toByteArray(entity); + final byte[] data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, null)); } }); @@ -630,7 +630,7 @@ void testHttpPostNoEntity() throws Exception { try (final ClassicHttpResponse response = client.execute(host, post, context)) { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); Assertions.assertEquals(0, received.length); } } @@ -644,7 +644,7 @@ void testHttpPostNoContentLength() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final byte[] data = EntityUtils.toByteArray(entity); + final byte[] data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, null)); } }); @@ -666,7 +666,7 @@ void testHttpPostNoContentLength() throws Exception { try (final ClassicHttpResponse response = client.execute(host, post, context)) { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); Assertions.assertEquals(0, received.length); } } @@ -680,7 +680,7 @@ void testHttpPostIdentity() throws Exception { final HttpEntity entity = request.getEntity(); if (entity != null) { - final byte[] data = EntityUtils.toByteArray(entity); + final byte[] data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, null)); } }); @@ -748,7 +748,7 @@ void testEchoNoEntityRequest() throws Exception { try (final ClassicHttpResponse response = client.execute(host, post, context)) { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); if (response.getEntity() != null) { - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); Assertions.assertEquals(0, received.length); } } @@ -772,7 +772,7 @@ void testEchoEmptyEntity() throws Exception { try (final ClassicHttpResponse response = client.execute(host, post, context)) { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); Assertions.assertEquals(0, received.length); } } @@ -800,7 +800,7 @@ void testEchoLargeEntity() throws Exception { try (final ClassicHttpResponse response = client.execute(host, post, context)) { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); Assertions.assertArrayEquals(data, received); } } @@ -825,7 +825,7 @@ void testEchoManySmallRequests() throws Exception { try (final ClassicHttpResponse response = client.execute(host, post, context)) { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); - final byte[] received = EntityUtils.toByteArray(response.getEntity()); + final byte[] received = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); Assertions.assertArrayEquals(data, received); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java index c63145a300..393ddd8c10 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java @@ -137,7 +137,7 @@ void testTLSSuccess() throws Exception { request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) { Assertions.assertEquals(HttpStatus.SC_OK, response1.getCode()); - final String body1 = EntityUtils.toString(response1.getEntity()); + final String body1 = EntityUtils.toString(response1.getEntity(), Integer.MAX_VALUE); Assertions.assertEquals("some stuff", body1); } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/EchoHandler.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/EchoHandler.java index 85b49a1d6f..efffc3b3d9 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/EchoHandler.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/EchoHandler.java @@ -52,7 +52,7 @@ public void handle( final HttpEntity entity = request.getEntity(); final byte[] data; if (entity != null) { - data = EntityUtils.toByteArray(entity); + data = EntityUtils.toByteArray(entity, Integer.MAX_VALUE); response.setEntity(new ByteArrayEntity(data, ContentType.parse(entity.getContentType()))); } } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java index 31d49dd1f7..afa4b1d3af 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/compatibility/classic/ClassicHttpCompatTest.java @@ -93,7 +93,7 @@ void test_sequential_requests() throws Exception { .build(); requester.execute(target, request, TIMEOUT, context, response -> { Assertions.assertEquals(HttpStatus.SC_OK, response.getCode()); - final String body1 = EntityUtils.toString(response.getEntity()); + final String body1 = EntityUtils.toString(response.getEntity(), Integer.MAX_VALUE); Assertions.assertEquals(ContainerImages.AAA, body1); return null; }); @@ -123,7 +123,7 @@ void test_multi_threaded_requests() throws Exception { resultQueue.add(new Result<>( request, response, - EntityUtils.toString(response.getEntity()))); + EntityUtils.toString(response.getEntity(), Integer.MAX_VALUE))); return null; }); } catch (final Exception ex) { diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientAdapter.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientAdapter.java index c895f08c4f..a3910fe673 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientAdapter.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestClassicTestClientAdapter.java @@ -94,7 +94,7 @@ void executeBuildsRequestAndParsesResponse() throws Exception { : null); if (request.getEntity() != null) { captured.put("content-type", request.getEntity().getContentType()); - captured.put("body", EntityUtils.toString(request.getEntity())); + captured.put("body", EntityUtils.toString(request.getEntity(), Integer.MAX_VALUE)); } else { captured.put("content-type", null); captured.put("body", null); diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFrameworkRequestHandler.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFrameworkRequestHandler.java index 39f5a60a82..f50a34ef72 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFrameworkRequestHandler.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFrameworkRequestHandler.java @@ -126,7 +126,7 @@ void handleValidatesRequestAndBuildsResponse() throws Exception { handler.assertNothingThrown(); Assertions.assertEquals(201, response.getCode()); - Assertions.assertEquals("pong", EntityUtils.toString(response.getEntity())); + Assertions.assertEquals("pong", EntityUtils.toString(response.getEntity(), 1024)); Assertions.assertTrue(response.getEntity().getContentType().contains("text/plain")); Assertions.assertEquals("ok", response.getFirstHeader("X-Reply").getValue()); } diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java index 5e312e44c6..16b78b54c2 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java @@ -92,7 +92,7 @@ void test_request_handling_no_keep_alive(final int contentSize) throws Exception try (ClassicHttpResponse response = responseConsumer.blockWaiting()) { Assertions.assertEquals(200, response.getCode()); - final byte[] bytes = EntityUtils.toByteArray(response.getEntity()); + final byte[] bytes = EntityUtils.toByteArray(response.getEntity(), Integer.MAX_VALUE); Assertions.assertNotNull(bytes); Assertions.assertArrayEquals(temp, bytes); } diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java index e4c3c000f7..019acc4bd5 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java @@ -58,7 +58,6 @@ */ public final class EntityUtils { - // TODO Consider using a sane value, but what is sane? 1 GB? 100 MB? 10 MB? private static final int DEFAULT_ENTITY_RETURN_MAX_LENGTH = Integer.MAX_VALUE; private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; private static final int DEFAULT_CHAR_BUFFER_SIZE = 1024; @@ -128,7 +127,10 @@ static long checkContentLength(final EntityDetails entityDetails) { * {@link HttpEntity#getContent()} is null. * @throws IOException if an error occurs reading the input stream * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE + * + * @deprecated Use {@link #toByteArray(HttpEntity, int)} */ + @Deprecated public static byte[] toByteArray(final HttpEntity entity) throws IOException { Args.notNull(entity, "HttpEntity"); final int contentLength = toContentLength((int) checkContentLength(entity)); @@ -247,7 +249,10 @@ private static String toString(final HttpEntity entity, final ContentType conten * @throws IOException if an error occurs reading the input stream * @throws java.nio.charset.UnsupportedCharsetException Thrown when the named entity's charset is not available in * this instance of the Java virtual machine and no defaultCharset is provided. + * + * @deprecated Use {@link #toString(HttpEntity, Charset, int)}. */ + @Deprecated public static String toString( final HttpEntity entity, final Charset defaultCharset) throws IOException, ParseException { return toString(entity, defaultCharset, DEFAULT_ENTITY_RETURN_MAX_LENGTH); @@ -328,7 +333,10 @@ public static String toString( * @throws IOException if an error occurs reading the input stream * @throws java.nio.charset.UnsupportedCharsetException Thrown when the named charset is not available in * this instance of the Java virtual machine + * + * @deprecated Use {@link #toString(HttpEntity, Charset, int)}. */ + @Deprecated public static String toString( final HttpEntity entity, final String defaultCharset, final int maxResultLength) throws IOException, ParseException { return toString(entity, defaultCharset != null ? Charset.forName(defaultCharset) : null, maxResultLength); @@ -346,7 +354,10 @@ public static String toString( * @throws IOException if an error occurs reading the input stream * @throws java.nio.charset.UnsupportedCharsetException Thrown when the named charset is not available in * this instance of the Java virtual machine + * + * @deprecated Use {@link #toString(HttpEntity, Charset, int)}. */ + @Deprecated public static String toString(final HttpEntity entity) throws IOException, ParseException { return toString(entity, DEFAULT_ENTITY_RETURN_MAX_LENGTH); } @@ -383,7 +394,10 @@ public static String toString(final HttpEntity entity, final int maxResultLength * @return a list of {@link NameValuePair} as built from the URI's query portion. * @throws IOException * If there was an exception getting the entity's data. + * + * @deprecated Use {@link #parse(HttpEntity, int)} */ + @Deprecated public static List parse(final HttpEntity entity) throws IOException { return parse(entity, DEFAULT_ENTITY_RETURN_MAX_LENGTH); } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java index 9b4cea8ec3..31c90e4551 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java @@ -155,8 +155,8 @@ public void handle( final HttpEntity incomingEntity = request.getEntity(); if (incomingEntity != null) { - final byte[] entityContent = EntityUtils.toByteArray(incomingEntity); - System.out.println("Incoming incomingEntity content (bytes): " + entityContent.length); + EntityUtils.consume(incomingEntity); + System.out.println("Incoming incomingEntity content (bytes): " + incomingEntity.getContentLength()); } final File file = new File(this.docRoot, URLDecoder.decode(path, "UTF-8")); diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java index ab7de44b14..eb13fd79af 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java @@ -93,7 +93,7 @@ public void onExchangeComplete(final HttpConnection connection, final boolean ke .build(); try (ClassicHttpResponse response = httpRequester.execute(target, request, Timeout.ofSeconds(5), context)) { System.out.println(requestUri + "->" + response.getCode()); - System.out.println(EntityUtils.toString(response.getEntity())); + System.out.println(EntityUtils.toString(response.getEntity(), 1024)); System.out.println("=============="); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java index 49644d1042..81089cec41 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java @@ -113,7 +113,7 @@ public void onExchangeComplete(final HttpConnection connection, final boolean ke request.setEntity(requestBodies[i]); try (ClassicHttpResponse response = httpRequester.execute(target, request, Timeout.ofSeconds(5), context)) { System.out.println(requestUri + "->" + response.getCode()); - System.out.println(EntityUtils.toString(response.getEntity())); + System.out.println(EntityUtils.toString(response.getEntity(), 1024)); System.out.println("=============="); } } diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java index 3e566895bf..2c26d2b148 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java @@ -56,7 +56,7 @@ class TestEntityUtils { @Test void testNullEntityToByteArray() { Assertions.assertThrows(NullPointerException.class, () -> - EntityUtils.toByteArray(null)); + EntityUtils.toByteArray(null, 1024)); } @Test @@ -65,14 +65,14 @@ void testMaxIntContentToByteArray() { final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(content), Integer.MAX_VALUE + 100L, ContentType.TEXT_PLAIN.withCharset(StandardCharsets.US_ASCII)); Assertions.assertThrows(IllegalArgumentException.class, () -> - EntityUtils.toByteArray(entity)); + EntityUtils.toByteArray(entity, 1024)); } @Test void testUnknownLengthContentToByteArray() throws Exception { final byte[] bytes = "Message content".getBytes(StandardCharsets.US_ASCII); final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(bytes), -1, null); - final byte[] bytes2 = EntityUtils.toByteArray(entity); + final byte[] bytes2 = EntityUtils.toByteArray(entity, 1024); Assertions.assertNotNull(bytes2); Assertions.assertEquals(bytes.length, bytes2.length); for (int i = 0; i < bytes.length; i++) { @@ -84,7 +84,7 @@ void testUnknownLengthContentToByteArray() throws Exception { void testKnownLengthContentToByteArray() throws Exception { final byte[] bytes = "Message content".getBytes(StandardCharsets.US_ASCII); final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(bytes), bytes.length, null); - final byte[] bytes2 = EntityUtils.toByteArray(entity); + final byte[] bytes2 = EntityUtils.toByteArray(entity, 1024); Assertions.assertNotNull(bytes2); Assertions.assertEquals(bytes.length, bytes2.length); for (int i = 0; i < bytes.length; i++) { @@ -94,7 +94,7 @@ void testKnownLengthContentToByteArray() throws Exception { @Test void testNullEntityToString() { - Assertions.assertThrows(NullPointerException.class, () -> EntityUtils.toString(null)); + Assertions.assertThrows(NullPointerException.class, () -> EntityUtils.toString(null, 1024)); } @Test @@ -119,7 +119,7 @@ void testKnownLengthContentToString() throws Exception { final byte[] bytes = "Message content".getBytes(StandardCharsets.US_ASCII); final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(bytes), bytes.length, ContentType.TEXT_PLAIN.withCharset(StandardCharsets.US_ASCII)); - final String s = EntityUtils.toString(entity, StandardCharsets.US_ASCII); + final String s = EntityUtils.toString(entity, StandardCharsets.US_ASCII, 1024); Assertions.assertEquals("Message content", s); } @@ -147,7 +147,7 @@ void testNoCharsetContentToString() { final String content = constructString(SWISS_GERMAN_HELLO); final byte[] bytes = content.getBytes(StandardCharsets.UTF_8); final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(bytes), ContentType.TEXT_PLAIN); - Assertions.assertDoesNotThrow(() -> EntityUtils.toString(entity)); + Assertions.assertDoesNotThrow(() -> EntityUtils.toString(entity, 1024)); } @Test @@ -156,7 +156,7 @@ void testDefaultCharsetContentToString() throws Exception { final byte[] bytes = content.getBytes(Charset.forName("KOI8-R")); final BasicHttpEntity entity = new BasicHttpEntity(new ByteArrayInputStream(bytes), ContentType.parse("text/plain")); - final String s = EntityUtils.toString(entity, Charset.forName("KOI8-R")); + final String s = EntityUtils.toString(entity, Charset.forName("KOI8-R"), 1024); Assertions.assertEquals(content, s); } @@ -211,12 +211,12 @@ private static void assertNameValuePair ( @Test void testParseEntity() throws Exception { final StringEntity entity1 = new StringEntity("Name1=Value1", ContentType.APPLICATION_FORM_URLENCODED); - final List result = EntityUtils.parse(entity1); + final List result = EntityUtils.parse(entity1, 1024); Assertions.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name1", "Value1"); final StringEntity entity2 = new StringEntity("Name1=Value1", ContentType.parse("text/test")); - Assertions.assertTrue(EntityUtils.parse(entity2).isEmpty()); + Assertions.assertTrue(EntityUtils.parse(entity2, 1024).isEmpty()); } @Test @@ -233,7 +233,7 @@ void testParseUTF8Entity() throws Exception { "&swiss=Gr%C3%BCezi_z%C3%A4m%C3%A4", s); final StringEntity entity = new StringEntity(s, ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8)); - final List result = EntityUtils.parse(entity); + final List result = EntityUtils.parse(entity, 1024); Assertions.assertEquals(2, result.size()); assertNameValuePair(result.get(0), "russian", ru_hello); assertNameValuePair(result.get(1), "swiss", ch_hello); diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestStringEntity.java b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestStringEntity.java index f6e370a912..665945ebce 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestStringEntity.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestStringEntity.java @@ -89,11 +89,11 @@ void testNullCharset() throws Exception { StringEntity httpentity = new StringEntity(s, ContentType.create("text/plain", (Charset) null)); Assertions.assertNotNull(httpentity.getContentType()); Assertions.assertEquals("text/plain", httpentity.getContentType()); - Assertions.assertEquals(s, EntityUtils.toString(httpentity)); + Assertions.assertEquals(s, EntityUtils.toString(httpentity, 1024)); httpentity = new StringEntity(s, (Charset) null); Assertions.assertNotNull(httpentity.getContentType()); Assertions.assertEquals("text/plain", httpentity.getContentType()); - Assertions.assertEquals(s, EntityUtils.toString(httpentity)); + Assertions.assertEquals(s, EntityUtils.toString(httpentity, 1024)); } @Test diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/io/support/ClassicRequestBuilderTest.java b/httpcore5/src/test/java/org/apache/hc/core5/http/io/support/ClassicRequestBuilderTest.java index c5331f084f..3fc2dd3a5e 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/http/io/support/ClassicRequestBuilderTest.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/http/io/support/ClassicRequestBuilderTest.java @@ -266,7 +266,7 @@ void builderQuery() throws IOException { () -> assertEquals("/theUri", classicHttpRequest.getPath()), () -> assertNotNull(classicHttpRequest.getEntity()), () -> assertEquals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType(), ContentType.parse(classicHttpRequest.getEntity().getContentType()).getMimeType()), - () -> assertEquals("param1=value1¶m2=value2", EntityUtils.toString(classicHttpRequest.getEntity())) + () -> assertEquals("param1=value1¶m2=value2", EntityUtils.toString(classicHttpRequest.getEntity(), 1024)) ); }