@Test public void testValidator() throws IOException, InterruptedException { MockWebServer server = new MockWebServer(); String content = "Hello world"; server.enqueue(new MockResponse() .setResponseCode(200) .setHeader("Content-type", "text/plain") .setBody(content)); server.play(); HttpResourceGroup group = Ribbon.createHttpResourceGroup("myclient", ClientOptions.create() .withConfigurationBasedServerList("localhost:" + server.getPort())); HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("test", ByteBuf.class) .withUriTemplate("/") .withMethod("GET") .withResponseValidator(new ResponseValidator<HttpClientResponse<ByteBuf>>() { @Override public void validate(HttpClientResponse<ByteBuf> t1) throws UnsuccessfulResponseException { throw new UnsuccessfulResponseException("error", new IllegalArgumentException()); } }).build(); RibbonRequest<ByteBuf> request = template.requestBuilder().build(); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); request.toObservable().subscribe(new Action1<ByteBuf>() { @Override public void call(ByteBuf t1) { } }, new Action1<Throwable>(){ @Override public void call(Throwable t1) { error.set(t1); latch.countDown(); } }, new Action0() { @Override public void call() { } }); latch.await(); assertTrue(error.get() instanceof HystrixBadRequestException); assertTrue(error.get().getCause() instanceof UnsuccessfulResponseException); }
public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract);  }