Java Code Examples for org.springframework.web.client.HttpStatusCodeException#getStatusText()

The following examples show how to use org.springframework.web.client.HttpStatusCodeException#getStatusText() . 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: HealthApi.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
private static void getResource(final String url, final Optional<String> mediaType) {
    final HttpHeaders headers = new HttpHeaders();
    if (mediaType.isPresent()) {
        headers.setAccept(asList(parseMediaType(mediaType.get())));
    }
    try {
        final ResponseEntity<String> responseEntity = restTemplate.exchange(
                url,
                GET,
                new HttpEntity<>("parameters", headers), String.class
        );
        content = responseEntity.getBody();
        statusCode = responseEntity.getStatusCode();
    } catch (HttpStatusCodeException e) {
        content = e.getStatusText();
        statusCode = e.getStatusCode();
    }
}
 
Example 2
Source File: DockerServiceImpl.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
private String formatHttpException(HttpStatusCodeException e) {
    try {
        return MessageFormat.format("Response from server: {0} {1}\n {2}",
          e.getStatusCode().value(),
          e.getStatusText(),// getResponseBodyAsString - below
          org.springframework.util.StringUtils.trimWhitespace(e.getResponseBodyAsString()));
    } catch (Exception ex) {
        log.error("Can not format exception {}", e, ex);
    }
    return e.getStatusText();
}
 
Example 3
Source File: AbstractV2RegistryService.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
protected void processStatusCodeException(HttpStatusCodeException e) {
    String message;
    try {
        message = MessageFormat.format("Response from server: {0} {1}",
                e.getStatusCode().value(),
                e.getStatusText());
        //we do not read error body, because it contains html code in some cases
    } catch (Exception ex) {
        message = e.getStatusText();
    }
    log.error("Error from server: {}", message, e);

}
 
Example 4
Source File: CustomControllerClientErrorHandler.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
private CloudOperationException asCloudOperationException(HttpStatusCodeException exception) {
    String description = getDescriptionFromResponseBody(exception.getResponseBodyAsString());
    return new CloudOperationException(exception.getStatusCode(), exception.getStatusText(), description);
}
 
Example 5
Source File: CredHubException.java    From spring-credhub with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new exception with the provided root cause.
 * @param e an {@link HttpStatusCodeException} caught while attempting to communicate
 * with CredHub
 */
public CredHubException(HttpStatusCodeException e) {
	super(e.getStatusCode(), e.getStatusText(), e.getResponseHeaders(), e.getResponseBodyAsByteArray(), null);
}