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

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

Introduction

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

Prototype

public void setErrorHandler(ResponseErrorHandler errorHandler) 

Source Link

Document

Set the error handler.

Usage

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.AppConfig.java

/**
 * Creates and configures the instance of {@link RestTemplate} to be used by the API client.
 * //from  w  w w.ja  va  2s  . c o m
 * @return The instance of {@link RestTemplate} to be used by the API client.
 */
@Bean
public RestTemplate apiClientRestTemplate() {
    // Use custom list of HttpMessageConverter rather than the default to allow the marshalling config to be customised
    RestTemplate restTemplate = new RestTemplate(this.httpMessageConverters());
    restTemplate.setRequestFactory(this.clientHttpRequestFactory());
    restTemplate.setErrorHandler(this.responseErrorHandler());
    return restTemplate;
}

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

public ActionsTest() {
    final RestTemplate template = new RestTemplate();
    template.setMessageConverters(singletonList(
            new MappingJackson2HttpMessageConverter(new ObjectMapper().findAndRegisterModules())));
    template.setErrorHandler(new PassThroughResponseErrorHandler());
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Rest.create(template);
}

From source file:org.springframework.social.facebook.api.impl.FacebookTemplate.java

@Override
protected void configureRestTemplate(RestTemplate restTemplate) {
    restTemplate.setErrorHandler(new FacebookErrorHandler());
}

From source file:org.opencredo.couchdb.CouchDbIntegrationTest.java

@Before
public void setUpTestDatabase() throws Exception {
    assumeDatabaseIsUpAndRunning();//from   w  ww .ja v  a  2  s  .  c  o  m
    RestTemplate template;
    if (credentials.length > 0)
        template = new BasicAuthRestTemplate(credentials[0], credentials[1], databaseUrl());
    else
        template = new BasicAuthRestTemplate();
    template.setErrorHandler(new DefaultResponseErrorHandler() {
        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
            // do nothing, error status will be handled in the switch statement
        }
    });
    ResponseEntity<String> response = template.getForEntity(databaseUrl(), String.class);
    HttpStatus statusCode = response.getStatusCode();
    switch (statusCode) {
    case NOT_FOUND:
        createNewTestDatabase();
        break;
    case OK:
        deleteExisitingTestDatabase();
        createNewTestDatabase();
        break;
    default:
        throw new IllegalStateException("Unsupported http status [" + statusCode + "]");
    }
}

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

public CaptureTest() {
    final RestTemplate template = new RestTemplate();
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(new ObjectMapper().findAndRegisterModules());
    template.setMessageConverters(singletonList(converter));
    template.setErrorHandler(new PassThroughResponseErrorHandler());
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Rest.create(template);
}

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

public CallTest() {
    final RestTemplate template = new RestTemplate();
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(new ObjectMapper().findAndRegisterModules());
    template.setMessageConverters(singletonList(converter));
    template.setErrorHandler(new PassThroughResponseErrorHandler());
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Rest.create(template);
}

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

public NestedDispatchTest() {
    final RestTemplate template = new RestTemplate();
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(new ObjectMapper().findAndRegisterModules());
    template.setMessageConverters(singletonList(converter));
    template.setErrorHandler(new PassThroughResponseErrorHandler());
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Rest.create(template);
}

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

public ContentTypeDispatchTest() {
    final RestTemplate template = new RestTemplate();
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(new ObjectMapper().findAndRegisterModules());
    template.setMessageConverters(singletonList(converter));
    template.setErrorHandler(new PassThroughResponseErrorHandler());
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Rest.create(template);
}

From source file:org.cloudfoundry.identity.uaa.ServerRunning.java

public RestTemplate createRestTemplate() {
    RestTemplate client = new RestTemplate();
    client.setRequestFactory(new StatelessRequestFactory());
    client.setErrorHandler(new ResponseErrorHandler() {
        // Pass errors through in response entity for status code analysis
        @Override/*w  w w . j  ava2  s . c om*/
        public boolean hasError(ClientHttpResponse response) throws IOException {
            return false;
        }

        @Override
        public void handleError(ClientHttpResponse response) throws IOException {
        }
    });
    return client;
}

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

public FailedDispatchTest() {
    final RestTemplate template = new RestTemplate();
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(new ObjectMapper().findAndRegisterModules());
    template.setMessageConverters(singletonList(converter));
    template.setErrorHandler(new PassThroughResponseErrorHandler());
    this.server = MockRestServiceServer.createServer(template);
    this.unit = Rest.create(template);
}