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

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

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.recursivechaos.clearent.service.ClearentService.java

public Transaction postTransaction(Transaction transaction) {
    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<Response> responseEntity;
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
    headers.set("api-key", gatewayProperties.getKey());
    HttpEntity<String> request = new HttpEntity<>(transaction.toString(), headers);
    try {/*from w  ww  . java  2 s . com*/
        responseEntity = restTemplate.postForEntity(gatewayProperties.getUrl() + "/transactions", request,
                Response.class);
    } catch (HttpClientErrorException he) {
        logger.error("Gateway Request Failed: {}", he.getLocalizedMessage());
        logger.error(he.getResponseBodyAsString());
        throw new GatewayException(he.getLocalizedMessage());
    }
    assert responseEntity != null;
    return responseEntity.getBody().getPayload().getTransaction();
}

From source file:org.urlshortener.core.dao.rest.UrlShortenerWsDAOImpl.java

/**
 * {@inheritDoc}//  w  w  w .  j  a  va2  s. com
 */
public String expandUrl(String encodeShortUrl, String server) {
    String longUrl = "";
    final String restServer = getRestServer(server, EXPAND_URL_REST_OP);

    try {
        longUrl = restTemplate.getForObject(restServer, String.class, encodeShortUrl);

    } catch (org.springframework.web.client.HttpClientErrorException e) {
        longUrl = "ERROR: " + e.getLocalizedMessage();
    }

    longUrl = prepareUrl(longUrl);

    return longUrl;
}

From source file:org.urlshortener.core.dao.rest.UrlShortenerWsDAOImpl.java

/**
 * {@inheritDoc}/*from  ww w  .  j  a  v  a2  s .c o m*/
 */
public String shortenUrl(String encodeLongUrl, String server) {
    String shortUrl = "";

    final String restServer = getRestServer(server, SHORTEN_URL_REST_OP);
    try {
        shortUrl = restTemplate.getForObject(restServer, String.class, encodeLongUrl);

    } catch (org.springframework.web.client.HttpClientErrorException e) {
        shortUrl = "ERROR: " + e.getLocalizedMessage();
    } catch (org.springframework.web.client.ResourceAccessException e) {
        shortUrl = "ERROR: " + e.getLocalizedMessage();
    }

    shortUrl = prepareUrl(shortUrl);

    return shortUrl;
}

From source file:com.wavemaker.tools.deployment.cloudfoundry.CloudFoundryDeploymentTarget.java

private Boolean appNameInUse(CloudFoundryClient client, String appName) {
    try {/*  ww w .j av a  2 s.  com*/
        if (client.getApplication(appName) != null) {
            log.info("ApplicationName: " + appName + " is already in use");
            return true;
        } else {
            log.info("ApplicatonName with name: " + appName + "was NOT found");
            return false;
        }
    } catch (HttpClientErrorException e) {
        log.info("Failed to find aplicatonName with name: " + appName + ". Response was: "
                + e.getLocalizedMessage());
        if (e.getStatusCode() != HttpStatus.NOT_FOUND) {
            return true;
        } else {
            return false;
        }
    }
}