Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit fa7e4b9

Browse files
committed
Properly catch errors thrown by request handlers
If the request handlers throw any exceptions, the call to JettyHttpClient would previously fail with an inline exception, rather than returning a failed future. This is fixed here.
1 parent 1fb8107 commit fa7e4b9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.proofpoint.http.client.jetty;
2+
3+
import com.google.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture;
4+
import com.proofpoint.http.client.HttpClient;
5+
6+
import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
7+
8+
public class FailedHttpResponseFuture<T>
9+
extends SimpleForwardingListenableFuture<T>
10+
implements HttpClient.HttpResponseFuture<T>
11+
{
12+
public FailedHttpResponseFuture(Throwable throwable)
13+
{
14+
super(immediateFailedFuture(throwable));
15+
}
16+
17+
@Override
18+
public String getState()
19+
{
20+
return "FAILED";
21+
}
22+
}

http-client/src/main/java/com/proofpoint/http/client/jetty/JettyHttpClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,12 @@ public <T, E extends Exception> HttpResponseFuture<T> executeAsync(Request reque
470470
requireNonNull(responseHandler, "responseHandler is null");
471471
AtomicLong bytesWritten = new AtomicLong(0);
472472

473-
request = applyRequestFilters(request);
473+
try {
474+
request = applyRequestFilters(request);
475+
}
476+
catch (RuntimeException e) {
477+
return new FailedHttpResponseFuture<>(e);
478+
}
474479

475480
HttpRequest jettyRequest = buildJettyRequest(request, bytesWritten);
476481

0 commit comments

Comments
 (0)