Example usage for org.springframework.web.client HttpClientErrorException HttpClientErrorException

List of usage examples for org.springframework.web.client HttpClientErrorException HttpClientErrorException

Introduction

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

Prototype

public HttpClientErrorException(HttpStatus statusCode, String statusText, @Nullable byte[] body,
        @Nullable Charset responseCharset) 

Source Link

Document

Constructor with a status code and status text, and content.

Usage

From source file:org.trustedanalytics.user.common.TestUtils.java

public static HttpClientErrorException createDummyHttpClientException(UUID userId) {
    String body = "{\"message\":\"Username already in use: test@example.com\",\"error\":\"scim_resource_already_exists\",\"verified\":false,\"active\":true,\"user_id\":\""
            + userId + "\"}";
    HttpClientErrorException exception = new HttpClientErrorException(HttpStatus.CONFLICT, "Conflict",
            body.getBytes(), Charset.defaultCharset());
    return exception;
}

From source file:nl.gridshore.nosapi.impl.NosApiResponseErrorHandler.java

@Override
public void handleError(ClientHttpResponse response) throws IOException {
    logger.debug("Handle error '{}' received from the NOS server.", response.getStatusCode().name());
    HttpStatus statusCode = response.getStatusCode();
    MediaType contentType = response.getHeaders().getContentType();
    Charset charset = contentType != null ? contentType.getCharSet() : null;
    byte[] body = FileCopyUtils.copyToByteArray(response.getBody());

    switch (statusCode) {
    case BAD_REQUEST:
    case UNAUTHORIZED:
    case FORBIDDEN:
        throwClientException(charset, body);
    default:/*from  www.jav  a2s. c  o  m*/
        // do nothing, let the series resolving do it' work
    }

    switch (statusCode.series()) {
    case CLIENT_ERROR:
        throw new HttpClientErrorException(statusCode, response.getStatusText(), body, charset);
    case SERVER_ERROR:
        throw new HttpServerErrorException(statusCode, response.getStatusText(), body, charset);
    default:
        throw new RestClientException("Unknown status code [" + statusCode + "]");
    }
}