Example usage for org.springframework.web.client RestClientException getCause

List of usage examples for org.springframework.web.client RestClientException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.ge.predix.test.utils.ACSTestUtil.java

public static boolean isServerListening(final URI url) {
    RestTemplate restTemplate = new RestTemplate();
    try {//  w  w  w.j av a 2s  .  c o m
        restTemplate.getForObject(url, String.class);
    } catch (RestClientException e) {
        if (e.getCause() instanceof ConnectException) {
            return false;
        }
    }
    return true;
}

From source file:com.ns.retailmgr.connector.gmaps.GMapConnectorImpl.java

@Override
public Map<String, String> getLngLatByAddress(String address) throws RuntimeException {
    LOGGER.debug("Started method {} - params {}", "getLngLatByAddress", address);
    final String url = geoLatngUrl + address;
    try {/*  w  w w  . ja v  a  2  s  .  c  o  m*/
        final GeoCodeLocInfo geocodingResult = restTemplate.getForObject(url, GeoCodeLocInfo.class);
        final Map<String, String> returnMap = new HashMap<>();
        LngLatInfo[] results = geocodingResult.getResults();
        for (LngLatInfo res : results) {
            returnMap.put(ShopConstant.LATITUDE_KEY, Double.toString(res.getGeometry().getLocation().getLat()));
            returnMap.put(ShopConstant.LONGITUDE_KEY,
                    Double.toString(res.getGeometry().getLocation().getLng()));
        }
        return returnMap;
    } catch (RestClientException e) {
        LOGGER.error("Failed to find location lng lat. Exception {}", e);
        throw new RuntimeException("Failed to find latitude/longitude of address", e.getCause());
    }
}

From source file:com.ns.retailmgr.connector.gmaps.GMapConnectorImpl.java

@Override
public GeoCodeLocInfo getNearestShopDetails(String latlngParam) throws RuntimeException {
    LOGGER.info("Started method {} - params {}", "getNearestShopDetails", latlngParam);
    final String url = geoLocationUrl + latlngParam;
    try {/*from  w w  w  .j ava 2  s  .c  o m*/
        return restTemplate.getForObject(url, GeoCodeLocInfo.class);
    } catch (RestClientException e) {
        LOGGER.error("Failed to find location lng lat. Exception {}", e);
        throw new RuntimeException("Failed to find nearest locations of latitude/longitude", e.getCause());
    }
}

From source file:com.thinkbiganalytics.servicemonitor.check.AmbariServicesStatusCheck.java

/**
 * https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/host-component-resources.md
 *
 * State    Description                                                                          <br>
 * INIT    The initial clean state after the component is first created.                        <br>
 * INSTALLING    In the process of installing the component.                                  <br>
 * INSTALL_FAILED    The component install failed.                                                <br>
 * INSTALLED    The component has been installed successfully but is not currently running.  <br>
 * STARTING    In the process of starting the component.                                    <br>
 * STARTED    The component has been installed and started.                                        <br>
 * STOPPING    In the process of stopping the component.                                    <br>
 * UNINSTALLING    In the process of uninstalling the component.                                <br>
 * UNINSTALLED    The component has been successfully uninstalled.                             <br>
 * WIPING_OUT    In the process of wiping out the installed component.                        <br>
 * UPGRADING    In the process of upgrading the component.                                   <br>
 * MAINTENANCE    The component has been marked for maintenance.                               <br>
 * UNKNOWN    The component state can not be determined.                                           <br>
 */// w w  w  . java2 s .  c  o  m
@Override
public List<ServiceStatusResponse> healthCheck() {

    List<ServiceStatusResponse> serviceStatusResponseList = new ArrayList<>();

    //Get the Map of Services and optional Components we are tracking
    Map<String, List<String>> definedServiceComponentMap = ServiceMonitorCheckUtil
            .getMapOfServiceAndComponents(services);

    if (definedServiceComponentMap != null && !definedServiceComponentMap.isEmpty()) {

        try {
            AmbariClient client = ambariClient;
            //get the Clusers from ambari
            List<String> clusterNames = client.getAmbariClusterNames();
            //get the Service Status from Ambari
            ServiceComponentInfoSummary response = client.getServiceComponentInfo(clusterNames, services);
            //get alert info for these services as well
            AlertSummary alertSummary = client.getAlerts(clusterNames, services);
            //Convert the Ambari Alerts to the Pipeline Controller Alert
            List<ServiceAlert> serviceAlerts = transformAmbariAlert(alertSummary);
            //Convert the Ambari ServiceComponentInfo objects to Pipeline Controller ServiceComponents
            serviceStatusResponseList = transformAmbariServiceComponents(response, serviceAlerts,
                    definedServiceComponentMap);
        } catch (RestClientException e) {
            Throwable cause;
            if (e.getCause() != null) {
                cause = e.getCause();
            } else {
                cause = e;
            }
            ServiceComponent ambariServiceComponent = new DefaultServiceComponent.Builder("Unknown", "Ambari",
                    "Ambari REST_CLIENT", ServiceComponent.STATE.DOWN).exception(cause).build();
            List<ServiceComponent> ambariComponents = new ArrayList<>();
            ambariComponents.add(ambariServiceComponent);
            ServiceStatusResponse serviceStatusResponse = new DefaultServiceStatusResponse(
                    ambariServiceComponent.getServiceName(), ambariComponents);
            serviceStatusResponseList.add(serviceStatusResponse);
            //add the other services as being Warnings
            addAmbariServiceErrors(cause.getMessage(), serviceStatusResponseList, definedServiceComponentMap);

        }
    }
    return serviceStatusResponseList;
}

From source file:io.seldon.client.services.ApiServiceImpl.java

private ResourceBean getResource(final String url, Class<?> c) {
    logger.info("* GET Endpoint: " + url);
    ResourceBean bean;/*from   w  w  w  .jav  a  2s . c o m*/
    if (token == null) {
        ResourceBean r = getToken();
        if (r instanceof ErrorBean)
            return r;
    }

    String urlWithToken = url + "&oauth_token=" + token;
    logger.debug("** Token: " + token);
    logger.debug("** Class: " + c.getName());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> entity = new HttpEntity<String>(headers);
    RestTemplate restTemplate = createRestTemplate();
    try {
        //logger.info("Calling end point: " + urlWithToken + " for class: " + c.getName());
        @SuppressWarnings("unchecked")
        HttpEntity<ResourceBean> res = (HttpEntity<ResourceBean>) restTemplate.exchange(urlWithToken,
                HttpMethod.GET, entity, c);
        logger.debug("Result: " + res.toString() + " : " + res.getBody());
        bean = res.getBody();
        logger.debug("*** OK (" + urlWithToken + ")");
    } catch (Exception e) {
        if (e.getCause() instanceof SocketTimeoutException) {
            return createTimeoutBean();
        }
        logger.error("Exception class: " + e.getClass());
        //logger.error("Failed Api Call for url: " + urlWithToken + " : " + e.toString());
        logger.error("*** NOK (" + urlWithToken + "): " + e.getMessage());
        HttpEntity<ErrorBean> res = null;
        try {
            res = restTemplate.exchange(urlWithToken, HttpMethod.GET, entity, ErrorBean.class);
        } catch (RestClientException e1) {
            if (e1.getCause() instanceof SocketTimeoutException) {
                return createTimeoutBean();
            }
        }
        bean = res.getBody();
    }
    if (bean instanceof ErrorBean) {
        if (((ErrorBean) bean).getError_id() != Constants.TOKEN_EXPIRED) {
            return bean;
        } else {
            logger.info("Token expired; fetching a new one.");
            ResourceBean r = getToken();
            if (r instanceof ErrorBean) {
                return r;
            } else {
                return getResource(url, c);
            }
        }
    } else {
        return bean;
    }
}