Skip to content

Commit 6530497

Browse files
author
Stephane Landelle
committed
Introduce a constant exception for Remotely Closed
1 parent 3286d44 commit 6530497

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

api/src/main/java/org/asynchttpclient/AsyncHttpClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import org.asynchttpclient.filter.FilterException;
2121
import org.asynchttpclient.filter.RequestFilter;
2222
import org.asynchttpclient.resumable.ResumableAsyncHandler;
23+
2324
import java.io.Closeable;
25+
2426
import org.slf4j.Logger;
2527
import org.slf4j.LoggerFactory;
2628

api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.io.ByteArrayInputStream;
1616
import java.io.FileNotFoundException;
17+
import java.io.IOException;
1718
import java.io.InputStream;
1819
import java.io.SequenceInputStream;
1920
import java.io.UnsupportedEncodingException;
@@ -52,7 +53,13 @@
5253
* The cookies's handling code is from the Netty framework.
5354
*/
5455
public class AsyncHttpProviderUtils {
55-
56+
57+
public static final IOException REMOTELY_CLOSED_EXCEPTION = new IOException("Remotely Closed");
58+
59+
static {
60+
REMOTELY_CLOSED_EXCEPTION.setStackTrace(new StackTraceElement[] {});
61+
}
62+
5663
private final static byte[] NO_BYTES = new byte[0];
5764

5865
public final static String DEFAULT_CHARSET = "ISO-8859-1";

api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.asynchttpclient.AsyncHttpClientConfig;
2929
import org.asynchttpclient.Realm;
3030
import org.asynchttpclient.Response;
31+
import org.asynchttpclient.util.AsyncHttpProviderUtils;
3132
import org.eclipse.jetty.server.Request;
3233
import org.eclipse.jetty.server.Server;
3334
import org.eclipse.jetty.server.handler.AbstractHandler;
@@ -195,7 +196,7 @@ public void digestFuturePreemptiveAuthTimeoutTest() throws Exception {
195196
protected void inspectException(Throwable t) {
196197
assertNotNull(t.getCause());
197198
assertEquals(t.getCause().getClass(), IOException.class);
198-
if (!t.getCause().getMessage().startsWith("Remotely Closed")) {
199+
if (t.getCause() != AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION) {
199200
fail();
200201
}
201202
}

providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.asynchttpclient.Request;
1818
import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandler;
1919
import org.asynchttpclient.providers.grizzly.statushandler.StatusHandler;
20+
import org.asynchttpclient.util.AsyncHttpProviderUtils;
2021
import org.asynchttpclient.websocket.WebSocket;
2122
import org.glassfish.grizzly.CloseListener;
2223
import org.glassfish.grizzly.CloseType;
@@ -67,7 +68,7 @@ public final class HttpTxContext {
6768
public void onClosed(Closeable closeable, CloseType type)
6869
throws IOException {
6970
if (CloseType.REMOTELY.equals(type)) {
70-
abort(new IOException("Remotely Closed"));
71+
abort(AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION);
7172
}
7273
}
7374
};

providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.asynchttpclient.providers.netty.future.NettyResponseFuture;
3636
import org.asynchttpclient.providers.netty.future.NettyResponseFutures;
3737
import org.asynchttpclient.providers.netty.request.NettyRequestSender;
38+
import org.asynchttpclient.util.AsyncHttpProviderUtils;
3839
import org.slf4j.Logger;
3940
import org.slf4j.LoggerFactory;
4041

@@ -119,7 +120,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
119120

120121
if (future != null && !future.isDone() && !future.isCancelled()) {
121122
if (!requestSender.retry(ctx.channel(), future)) {
122-
channels.abort(future, new IOException("Remotely Closed"));
123+
channels.abort(future, AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION);
123124
}
124125
} else {
125126
channels.closeChannel(ctx);

0 commit comments

Comments
 (0)