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

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

Introduction

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

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:com.capitalone.dashboard.collector.DefaultNexusIQClient.java

/**
 * Get report links for a given application.
 * @param application nexus application/*w w w .  jav  a2 s  .co m*/
 * @return a list of report links
 */
@Override
public List<LibraryPolicyReport> getApplicationReport(NexusIQApplication application) {
    List<LibraryPolicyReport> applicationReports = new ArrayList<>();

    String appReportLinkUrl = String.format(application.getInstanceUrl() + API_V2_REPORTS_LINKS,
            application.getApplicationId());

    try {
        JSONArray reports = parseAsArray(appReportLinkUrl);
        if ((reports == null) || (reports.isEmpty()))
            return null;
        for (Object element : reports) {
            LibraryPolicyReport appReport = new LibraryPolicyReport();
            String stage = str((JSONObject) element, "stage");
            appReport.setStage(stage);
            appReport.setEvaluationDate(timestamp((JSONObject) element, "evaluationDate"));
            appReport.setReportDataUrl(
                    application.getInstanceUrl() + "/" + str((JSONObject) element, "reportDataUrl"));
            appReport.setReportUIUrl(
                    application.getInstanceUrl() + "/" + str((JSONObject) element, "reportHtmlUrl"));
            applicationReports.add(appReport);
        }
    } catch (ParseException e) {
        LOG.error("Could not parse response from: " + appReportLinkUrl, e);
    } catch (RestClientException rce) {
        LOG.error("RestClientException: " + appReportLinkUrl + ". Error code=" + rce.getMessage());
    }
    return applicationReports;
}

From source file:com.capitalone.dashboard.collector.DefaultNexusIQClient.java

/**
 * Get the report details given a url for the report data.
 * @param url url of the report//from   w  w  w . j av  a2s. c o  m
 * @return LibraryPolicyResult
 */
@SuppressWarnings({ "PMD.AvoidDeeplyNestedIfStmts", "PMD.NPathComplexity" }) // agreed PMD, fixme

@Override
public LibraryPolicyResult getDetailedReport(String url) {
    LibraryPolicyResult policyResult = null;
    try {
        JSONObject obj = parseAsObject(url);
        JSONArray componentArray = (JSONArray) obj.get("components");
        if ((componentArray == null) || (componentArray.isEmpty()))
            return null;
        for (Object element : componentArray) {
            JSONObject component = (JSONObject) element;
            int licenseLevel = 0;
            JSONArray pathArray = (JSONArray) component.get("pathnames");

            String componentName = !CollectionUtils.isEmpty(pathArray) ? (String) pathArray.get(0)
                    : getComponentNameFromIdentifier((JSONObject) component.get("componentIdentifier"));

            JSONObject licenseData = (JSONObject) component.get("licenseData");

            if (licenseData != null) {
                //process license data
                JSONArray effectiveLicenseThreats = (JSONArray) licenseData.get("effectiveLicenseThreats");
                if (!CollectionUtils.isEmpty(effectiveLicenseThreats)) {
                    for (Object et : effectiveLicenseThreats) {
                        JSONObject etJO = (JSONObject) et;
                        Long longvalue = toLong(etJO, "licenseThreatGroupLevel");
                        if (longvalue != null) {
                            int newlevel = longvalue.intValue();
                            if (licenseLevel == 0) {
                                licenseLevel = newlevel;
                            } else {
                                licenseLevel = nexusIQSettings.isSelectStricterLicense()
                                        ? Math.max(licenseLevel, newlevel)
                                        : Math.min(licenseLevel, newlevel);
                            }
                        }
                    }

                }
            }

            if (policyResult == null) {
                policyResult = new LibraryPolicyResult();
            }

            if (licenseLevel > 0) {
                policyResult.addThreat(LibraryPolicyType.License,
                        LibraryPolicyThreatLevel.fromInt(licenseLevel), componentName);
            }

            JSONObject securityData = (JSONObject) component.get("securityData");
            if (securityData != null) {
                //process security data
                JSONArray securityIssues = (JSONArray) securityData.get("securityIssues");
                if (!CollectionUtils.isEmpty(securityIssues)) {
                    for (Object si : securityIssues) {
                        JSONObject siJO = (JSONObject) si;
                        BigDecimal bigDecimalValue = decimal(siJO, "severity");
                        double securityLevel = (bigDecimalValue == null)
                                ? getSeverityLevel(str(siJO, "threatCategory"))
                                : bigDecimalValue.doubleValue();
                        policyResult.addThreat(LibraryPolicyType.Security,
                                LibraryPolicyThreatLevel.fromDouble(securityLevel), componentName);
                    }
                }
            }
        }
    } catch (ParseException e) {
        LOG.error("Could not parse response from: " + url, e);
    } catch (RestClientException rce) {
        LOG.error("RestClientException from: " + url + ". Error code=" + rce.getMessage());
    }
    return policyResult;
}

From source file:com.ge.predix.uaa.token.lib.FastTokenServices.java

protected String getTokenKey(final String issuer) {
    // Check if the RestTemplate has been initialized already...
    if (null == this.restTemplate) {
        this.restTemplate = new RestTemplate();
        ((RestTemplate) this.restTemplate).setErrorHandler(new FastTokenServicesResponseErrorHandler());
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setConnectTimeout(this.tokenKeyRequestTimeoutSeconds * 1000);
        ((RestTemplate) this.restTemplate).setRequestFactory(requestFactory);
    }/*from  ww  w  . j  a va 2s  . co  m*/

    String tokenKeyUrl = getTokenKeyURL(issuer);
    ParameterizedTypeReference<Map<String, Object>> typeRef = new ParameterizedTypeReference<Map<String, Object>>() {
        //
    };
    Map<String, Object> responseMap = null;
    try {
        responseMap = this.restTemplate.exchange(tokenKeyUrl, HttpMethod.GET, null, typeRef).getBody();
    } catch (RestClientException e) {
        LOG.error("Unable to retrieve the token public key. " + e.getMessage());
        throw e;
    }

    String tokenKey = responseMap.get("value").toString();

    if (LOG.isDebugEnabled()) {
        LOG.debug("The downloaded token key from '" + tokenKeyUrl + "' is: '" + tokenKey + "'");
    }

    return tokenKey;

}

From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java

/**
 * Used to create a workpool. This call can create workpools of Full,
 * linked, Custom types.//  ww  w .  ja  va 2s  . c  o  m
 *
 * NOTE: The created workpool or the Id is not returned as its not needed
 * at this point in time. If needed @see VmImage.createVmImage()
 *
 * @param workpool
 * @return
 * @throws WpException, AfConflictException
 */
public Long createWorkpool(Workpool workpool) throws WpException, AfConflictException {
    try {
        // This method does not return the
        URI uri = _rest.postForLocation(baseUrl() + "/workpools", workpool);

        return Long.valueOf(AfUtil.extractLastURIToken(uri));
    } catch (HttpStatusCodeException ex) {
        if (ex.getStatusCode() == HttpStatus.CONFLICT) {
            throw new AfConflictException("CONFLICT_NAME: " + ex.getMessage());
        }
        throw new WpException("Workpool cannot be created: " + ex.getMessage());
    } catch (RestClientException e) {
        throw new WpException("Workpool cannot be created: " + e.getMessage());
    }
}

From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java

/**
 * Used to update a VM Image. Name field can be updated.
 *
 * @param workpool/*from w w  w .  ja  v  a  2  s.  c  om*/
 * @throws WpException
 */
public void updateWorkpool(Workpool workpool) throws WpException, AfNotFoundException, AfConflictException {
    Long id = workpool.getId();
    try {
        _rest.put(baseUrl() + "/workpools/{id}", workpool, id);
    } catch (HttpStatusCodeException ex) {
        if (ex.getStatusCode() == HttpStatus.NOT_FOUND) {
            throw new AfNotFoundException("NOT_FOUND: " + ex.getMessage());
        } else if (ex.getStatusCode() == HttpStatus.CONFLICT) {
            throw new AfConflictException("CONFLICT_NAME: " + ex.getMessage());
        }
        throw new WpException("Workpool cannot be updated: " + ex.getMessage());
    } catch (RestClientException e) {
        throw new WpException("Workpool cannot be updated: " + e.getMessage());
    }
}

From source file:fr.itldev.koya.services.impl.UserServiceImpl.java

@Override
public Boolean logout(User user) throws AlfrescoServiceException {
    try {//from   w  w  w .  j  a  v a  2s .  c o m
        user.getRestTemplate().delete(getAlfrescoServerUrl() + REST_DEL_LOGOUT, user.getTicketAlfresco());
    } catch (RestClientException rce) {
        throw new AlfrescoServiceException(rce.getMessage(), KoyaErrorCodes.CANNOT_LOGOUT_USER);
    }

    //TODO treat returns
    return null;

}

From source file:com.vmware.appfactory.workpool.WorkpoolClientService.java

/**
 * Deletes the workpool by id/*from ww  w  .  j a  v  a 2 s  .  c o  m*/
 *
 * @param workpoolId
 * @param deleteMethod
 */
public void deleteWorkpool(Long workpoolId, DeleteMethod deleteMethod) throws WpException {
    try {
        _rest.delete(baseUrl() + "/workpools/{workpoolId}?deleteMethod={deleteMethod}", workpoolId,
                deleteMethod);
    } catch (RestClientException e) {
        _log.error("Cannot delete workpool id: " + workpoolId + "due to: " + e.getMessage());
        throw new WpException(e);
    }
}

From source file:org.obiba.mica.micaConfig.rest.MicaConfigResource.java

private String getUserProfileTranslations(String locale) {
    try {//www.j  a v a  2 s . c o  m
        return userProfileService.getUserProfileTranslations(locale);
    } catch (RestClientException e) {
        logger.warn("Cannot get translations about userProfile (from agate): {}", e.getMessage());
        return "{}";
    }
}

From source file:org.alfresco.dropbox.service.DropboxServiceImpl.java

public Metadata delete(String path) {
    Metadata metadata;//from   w w w.  j a  v a2  s  . co  m
    Connection<Dropbox> connection = this.getConnection();

    try {
        metadata = connection.getApi().delete(path);

        logger.debug("Delete " + path + ". Deleted Metadata: " + this.metadataAsJSON(metadata));
    } catch (RestClientException rce) {
        if (rce.getMessage().equals(NOT_FOUND)) {
            throw new FileNotFoundException();
        } else {
            throw new DropboxClientException(rce.getMessage());
        }
    }

    return metadata;
}

From source file:org.alfresco.dropbox.service.DropboxServiceImpl.java

public Metadata delete(NodeRef nodeRef) {
    Metadata metadata;// w  w  w .j a v  a 2s  . c  o m
    Connection<Dropbox> connection = this.getConnection();

    String path = getDropboxPath(nodeRef) + "/" + nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);

    try {
        metadata = connection.getApi().delete(path);

        logger.debug("Delete " + path + ". Deleted Metadata: " + this.metadataAsJSON(metadata));
    } catch (RestClientException rce) {
        if (rce.getMessage().equals(NOT_FOUND)) {
            throw new FileNotFoundException(nodeRef);
        } else {
            throw new DropboxClientException(rce.getMessage());
        }
    }

    return metadata;
}