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

JERSEY-3258: Fixed error handling for async client #3545

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,10 @@ private void processResponse(final ClientResponse response, final ResponseCallba
final ClientResponse processedResponse;
try {
processedResponse = Stages.process(response, responseProcessingRoot);
callback.completed(processedResponse, requestScope);
} catch (final Throwable throwable) {
processFailure(throwable, callback);
return;
}
callback.completed(processedResponse, requestScope);
}

private void processFailure(final Throwable failure, final ResponseCallback callback) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.glassfish.jersey.tests.e2e.client;

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.rx.rxjava.RxObservableInvokerProvider;
import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.client.InvocationCallback;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class InvalidEntityTest extends JerseyTest {

@Override
protected Application configure() {
return new ResourceConfig()
.register(Resource.class)
.register(JacksonFeature.class);
}

@Override
protected void configureClient(ClientConfig config) {
config.connectorProvider(new GrizzlyConnectorProvider())
.register(RxObservableInvokerProvider.class)
.register(JacksonFeature.class);
}

@Test(expected = ExecutionException.class)
public void shouldReceiveErrorOnInvalidEntity() throws ExecutionException, InterruptedException, TimeoutException {
target("/test")
.path("/")
.request(MediaType.APPLICATION_JSON)
.async()
.get(new EmptyCallback())
.get(30, TimeUnit.SECONDS);
}

@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public static class Resource {

@GET
public String get() {
return "{\"id\":1,\"owner\":\"123\"}"; // intentionally invalid json
}
}

public static class Entity {
public long id;
public String name;
}

private static class EmptyCallback implements InvocationCallback<Entity> {

@Override
public void completed(Entity entity) {

}

@Override
public void failed(Throwable throwable) {

}
}

}