Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit dc607ba

Browse files
Marek PotociarGerrit Code Review
authored andcommitted
Merge "JERSEY-2746: RuntimeExceptions thrown by request filters do not propagate when using submit() with Futures"
2 parents 0d49f45 + 49d1a54 commit dc607ba

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

core-client/src/main/java/org/glassfish/jersey/client/ClientRuntime.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ public void submit(final ClientRequest request, final ResponseCallback callback)
151151

152152
@Override
153153
public void run() {
154-
ClientRequest processedRequest;
155154
try {
156-
processedRequest = Stages.process(request, requestProcessingRoot);
157-
processedRequest = addUserAgent(processedRequest, connector.getName());
158-
} catch (final AbortException aborted) {
159-
processResponse(aborted.getAbortResponse(), callback);
160-
return;
161-
}
155+
ClientRequest processedRequest;
156+
try {
157+
processedRequest = Stages.process(request, requestProcessingRoot);
158+
processedRequest = addUserAgent(processedRequest, connector.getName());
159+
} catch (final AbortException aborted) {
160+
processResponse(aborted.getAbortResponse(), callback);
161+
return;
162+
}
162163

163-
try {
164164
final SettableFuture<ClientResponse> responseFuture = SettableFuture.create();
165165
final AsyncConnectorCallback connectorCallback = new AsyncConnectorCallback() {
166166

core-client/src/test/java/org/glassfish/jersey/client/JerseyInvocationTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.concurrent.atomic.AtomicReference;
5252

5353
import javax.ws.rs.ProcessingException;
54+
import javax.ws.rs.client.AsyncInvoker;
5455
import javax.ws.rs.client.Client;
5556
import javax.ws.rs.client.ClientBuilder;
5657
import javax.ws.rs.client.ClientRequestContext;
@@ -398,4 +399,26 @@ public void filter(final ClientRequestContext requestContext) throws IOException
398399
requestContext.abortWith(Response.ok("ENTITY").build());
399400
}
400401
}
402+
403+
@Test
404+
public void runtimeExceptionInAsyncInvocation() throws ExecutionException, InterruptedException {
405+
final AsyncInvoker ai = ClientBuilder.newClient().register(new ExceptionInvokerFilter())
406+
.target("http://localhost:888/").request().async();
407+
408+
try {
409+
ai.get().get();
410+
fail("ExecutionException should be thrown");
411+
} catch (ExecutionException ee) {
412+
assertEquals(ProcessingException.class, ee.getCause().getClass());
413+
assertEquals(RuntimeException.class, ee.getCause().getCause().getClass());
414+
}
415+
}
416+
417+
public static class ExceptionInvokerFilter implements ClientRequestFilter {
418+
419+
@Override
420+
public void filter(final ClientRequestContext requestContext) throws IOException {
421+
throw new RuntimeException("ExceptionInvokerFilter RuntimeException");
422+
}
423+
}
401424
}

0 commit comments

Comments
 (0)