Skip to content

Commit 3abe37b

Browse files
committed
minor clean up
1 parent 3c25a42 commit 3abe37b

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,23 @@ public void testConnectionDoesNotGetClosed() throws Exception {
7575
assertEquals(response.getStatusCode(), 200);
7676
byte[] responseBody = response.getResponseBodyAsBytes();
7777
responseBody = response.getResponseBodyAsBytes();
78-
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server received payload length invalid");
79-
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client back payload length invalid");
80-
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server received payload MD5 invalid");
81-
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client back payload MD5 invalid");
78+
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server side payload length invalid");
79+
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client side payload length invalid");
80+
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server side payload MD5 invalid");
81+
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client side payload MD5 invalid");
8282
assertEquals(responseBody, LARGE_IMAGE_BYTES);
8383

8484
response = requestBuilder.execute().get();
8585
assertEquals(response.getStatusCode(), 200);
8686
responseBody = response.getResponseBodyAsBytes();
87-
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server received payload length invalid");
88-
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client back payload length invalid");
87+
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server side payload length invalid");
88+
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client side payload length invalid");
8989
try {
90-
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server received payload MD5 invalid");
91-
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client back payload MD5 invalid");
90+
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server side payload MD5 invalid");
91+
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client side payload MD5 invalid");
9292
assertEquals(responseBody, LARGE_IMAGE_BYTES);
9393
} catch (AssertionError e) {
94+
e.printStackTrace();
9495
for (int i = 0; i < LARGE_IMAGE_BYTES.length; i++) {
9596
assertEquals(responseBody[i], LARGE_IMAGE_BYTES[i], "Invalid response byte at position " + i);
9697
}

client/src/test/java/org/asynchttpclient/test/EchoHandler.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
package org.asynchttpclient.test;
1515

1616
import static io.netty.handler.codec.http.HttpHeaderNames.*;
17-
import io.netty.buffer.ByteBufUtil;
18-
import io.netty.buffer.Unpooled;
19-
import io.netty.util.internal.StringUtil;
2017

2118
import java.io.IOException;
2219
import java.util.Enumeration;
@@ -26,6 +23,7 @@
2623
import javax.servlet.http.HttpServletRequest;
2724
import javax.servlet.http.HttpServletResponse;
2825

26+
import org.apache.commons.io.IOUtils;
2927
import org.eclipse.jetty.server.Request;
3028
import org.eclipse.jetty.server.handler.AbstractHandler;
3129
import org.slf4j.Logger;
@@ -106,35 +104,17 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
106104
}
107105
}
108106

109-
String clientContentLength = httpRequest.getHeader("X-" + CONTENT_LENGTH);
110-
String clientMd5 = httpRequest.getHeader("X-" + CONTENT_MD5);
111-
112-
if (clientContentLength != null) {
113-
byte[] bytes = new byte[Integer.valueOf(clientContentLength)];
114-
int read = 0;
115-
int total = 0;
116-
while (read > -1) {
117-
read = httpRequest.getInputStream().read(bytes, total, 5000);
118-
if (read > 0) {
119-
total += read;
120-
}
121-
}
107+
String requestBodyLength = httpRequest.getHeader("X-" + CONTENT_LENGTH);
108+
109+
if (requestBodyLength != null) {
110+
byte[] requestBodyBytes = IOUtils.toByteArray(httpRequest.getInputStream());
111+
int total = requestBodyBytes.length;
122112

123113
httpResponse.addIntHeader("X-" + CONTENT_LENGTH, total);
124-
String md5 = TestUtils.md5(bytes, 0, total);
114+
String md5 = TestUtils.md5(requestBodyBytes, 0, total);
125115
httpResponse.addHeader(CONTENT_MD5.toString(), md5);
126116

127-
// if (!md5.equals(clientMd5)) {
128-
// int length = total;
129-
// int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;
130-
// StringBuilder buf = new StringBuilder("JETTY".length() + 1 + "JETTY".length() + 2 + 10 + 1 + 2 + rows * 80);
131-
//
132-
// buf.append("JETTY").append(' ').append("JETTY").append(": ").append(length).append('B').append(StringUtil.NEWLINE);
133-
// ByteBufUtil.appendPrettyHexDump(buf, Unpooled.wrappedBuffer(bytes));
134-
// LOGGER.error(buf.toString());
135-
// }
136-
137-
httpResponse.getOutputStream().write(bytes, 0, total);
117+
httpResponse.getOutputStream().write(requestBodyBytes, 0, total);
138118
} else {
139119
int size = 16384;
140120
if (httpRequest.getContentLength() > 0) {

0 commit comments

Comments
 (0)