Example usage for org.springframework.web.client AsyncRestTemplate setErrorHandler

List of usage examples for org.springframework.web.client AsyncRestTemplate setErrorHandler

Introduction

In this page you can find the example usage for org.springframework.web.client AsyncRestTemplate setErrorHandler.

Prototype

public void setErrorHandler(ResponseErrorHandler errorHandler) 

Source Link

Document

Set the error handler.

Usage

From source file:org.zalando.riptide.OAuth2CompatibilityTest.java

@Test
public void dispatchesConsumedAsyncResponseAgain() throws IOException {
    final AsyncRestTemplate template = new AsyncRestTemplate();
    final MockRestServiceServer server = MockRestServiceServer.createServer(template);

    server.expect(requestTo(url)).andRespond(withUnauthorizedRequest().body(new byte[] { 0x13, 0x37 }));

    template.setErrorHandler(new OAuth2ErrorHandler(new OAuth2CompatibilityResponseErrorHandler(), null));
    final AsyncRest rest = AsyncRest.create(template);

    final AtomicReference<ClientHttpResponse> reference = new AtomicReference<>();

    rest.execute(GET, url).dispatch(status(), on(UNAUTHORIZED).call(reference::set));

    assertThat(reference.get().getBody().available(), is(2));
}