Java Code Examples for org.springframework.web.client.HttpServerErrorException#getResponseBodyAsString()

The following examples show how to use org.springframework.web.client.HttpServerErrorException#getResponseBodyAsString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloController.java    From Mastering-Distributed-Tracing with MIT License 5 votes vote down vote up
private String formatGreeting(String name) {
    URI uri = UriComponentsBuilder //
            .fromHttpUrl(formatterUrl) //
            .queryParam("name", name) //
            .build(Collections.emptyMap());
    logger.info("Calling {}", uri);
    try {
        ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
        return response.getBody();
    } catch (HttpServerErrorException e) {
        String responseBody = e.getResponseBodyAsString();
        throw new RuntimeException("Formatter error: " + responseBody);
    }
}
 
Example 2
Source File: ClientfacingErrorITest.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@RequestMapping("/throw5xxServerHttpStatusCodeException")
public void throw5xxServerHttpStatusCodeException() {
    HttpServerErrorException serverResponseEx = new HttpServerErrorException(HttpStatus.NOT_IMPLEMENTED);
    throw new ServerHttpStatusCodeException(new Exception("Intentional test exception"), "FOO", serverResponseEx, serverResponseEx.getStatusCode().value(), serverResponseEx.getResponseHeaders(), serverResponseEx.getResponseBodyAsString());
}
 
Example 3
Source File: ClientfacingErrorITest.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@RequestMapping("/throwTooManyRequestsException")
public void throwTooManyRequestsException() {
    HttpServerErrorException serverResponseEx = new HttpServerErrorException(HttpStatus.TOO_MANY_REQUESTS);
    throw new ServerHttpStatusCodeException(new Exception("Intentional test exception"), "FOO", serverResponseEx, serverResponseEx.getStatusCode().value(), serverResponseEx.getResponseHeaders(), serverResponseEx.getResponseBodyAsString());
}