Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb037426

Browse files
committed
Have BodyDeferringAsyncHandler unwrap ExecutionException
1 parentfea92a5 commitb037426

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

‎client/src/main/java/org/asynchttpclient/handler/BodyDeferringAsyncHandler.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ public void close() throws IOException {
248248
// "join" async request
249249
try {
250250
getLastResponse();
251-
}catch (Exceptione) {
251+
}catch (ExecutionExceptione) {
252+
IOExceptionioe =newIOException(e.getMessage());
253+
ioe.initCause(e.getCause());
254+
throwioe;
255+
}catch (InterruptedExceptione) {
252256
IOExceptionioe =newIOException(e.getMessage());
253257
ioe.initCause(e);
254258
throwioe;

‎client/src/test/java/org/asynchttpclient/handler/BodyDeferringAsyncHandlerTest.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
packageorg.asynchttpclient.handler;
1414

1515
importstaticio.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
16+
importstaticio.netty.handler.codec.http.HttpHeaderValues.APPLICATION_OCTET_STREAM;
1617
importstaticorg.apache.commons.io.IOUtils.copy;
1718
importstaticorg.asynchttpclient.Dsl.*;
1819
importstaticorg.asynchttpclient.test.TestUtils.findFreePort;
@@ -51,7 +52,7 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
5152

5253
httpResponse.setStatus(200);
5354
httpResponse.setContentLength(CONTENT_LENGTH_VALUE);
54-
httpResponse.setContentType("application/octet-stream");
55+
httpResponse.setContentType(APPLICATION_OCTET_STREAM.toString());
5556

5657
httpResponse.flushBuffer();
5758

@@ -121,7 +122,7 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce
121122
Responseresp =bdah.getResponse();
122123
assertNotNull(resp);
123124
assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
124-
assertEquals(resp.getHeader("content-length"),String.valueOf(CONTENT_LENGTH_VALUE));
125+
assertEquals(resp.getHeader(CONTENT_LENGTH),String.valueOf(CONTENT_LENGTH_VALUE));
125126
// we got headers only, it's probably not all yet here (we have BIG file
126127
// downloading)
127128
assertTrue(cos.getByteCount() <=CONTENT_LENGTH_VALUE);
@@ -179,7 +180,7 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
179180
Responseresp =is.getAsapResponse();
180181
assertNotNull(resp);
181182
assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
182-
assertEquals(resp.getHeader("content-length"),String.valueOf(CONTENT_LENGTH_VALUE));
183+
assertEquals(resp.getHeader(CONTENT_LENGTH),String.valueOf(CONTENT_LENGTH_VALUE));
183184
// "consume" the body, but our code needs input stream
184185
CountingOutputStreamcos =newCountingOutputStream();
185186
try {
@@ -196,8 +197,8 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
196197
}
197198
}
198199

199-
@Test(groups ="standalone")
200-
publicvoiddeferredInputStreamTrickWithFailure()throwsIOException,ExecutionException,TimeoutException,InterruptedException {
200+
@Test(groups ="standalone",expectedExceptions =RemotelyClosedException.class)
201+
publicvoiddeferredInputStreamTrickWithFailure()throwsThrowable {
201202
try (AsyncHttpClientclient =asyncHttpClient(getAsyncHttpClientConfig())) {
202203
BoundRequestBuilderr =client.prepareGet("http://localhost:" +port1 +"/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER",Boolean.TRUE.toString());
203204
PipedOutputStreampos =newPipedOutputStream();
@@ -211,7 +212,7 @@ public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionE
211212
Responseresp =is.getAsapResponse();
212213
assertNotNull(resp);
213214
assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
214-
assertEquals(resp.getHeader("content-length"),String.valueOf(CONTENT_LENGTH_VALUE));
215+
assertEquals(resp.getHeader(CONTENT_LENGTH),String.valueOf(CONTENT_LENGTH_VALUE));
215216
// "consume" the body, but our code needs input stream
216217
CountingOutputStreamcos =newCountingOutputStream();
217218
try {
@@ -221,9 +222,8 @@ public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionE
221222
is.close();
222223
cos.close();
223224
}
224-
fail("InputStream consumption should fail with IOException!");
225225
}catch (IOExceptione) {
226-
// good!
226+
throwe.getCause();
227227
}
228228
}
229229
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp