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.oneops.amq.plugins.CMSClient.java

/**
 * Gets the cloud ci.//from   w w  w.j  a va  2s  .  c o  m
 *
 * @param ns the ns
 * @param ciName the ci name
 * @return the cloud ci
 */
public CmsCISimple getCloudCi(String ns, String ciName) {

    try {
        CmsCISimple[] mgmtClouds = restTemplate.getForObject(
                serviceUrl + "cm/simple/cis?nsPath={nsPath}&ciClassName={mgmtCloud}&ciName={ciName}",
                new CmsCISimple[0].getClass(), ns, mgmtCloud, ciName);
        if (mgmtClouds.length > 0) {
            return mgmtClouds[0];
        }
        CmsCISimple[] acctClouds = restTemplate.getForObject(
                serviceUrl + "cm/simple/cis?nsPath={nsPath}&ciClassName={acctCloud}&ciName={ciName}",
                new CmsCISimple[0].getClass(), ns, acctCloud, ciName);
        if (acctClouds.length > 0) {
            return acctClouds[0];
        }

        return null;
    } catch (RestClientException ce) {
        logger.error("Broker can not connect to cms api to authenticate the user:" + ce.getMessage());
        throw ce;
    }
}

From source file:com.appglu.impl.StorageTemplate.java

protected boolean streamStorageFile(StorageFile file, final InputStreamCallback inputStreamCallback,
        RequestCallback requestCallback) throws AppGluRestClientException {
    URI uri = this.getStorageFileURI(file);

    try {/*ww  w  .  j a v  a 2  s . c  om*/
        ResponseExtractor<Boolean> responseExtractor = new ResponseExtractor<Boolean>() {
            public Boolean extractData(ClientHttpResponse response) throws IOException {
                if (response.getStatusCode() == HttpStatus.NOT_MODIFIED) {
                    return false;
                }

                Md5DigestCalculatingInputStream inputStream = new Md5DigestCalculatingInputStream(
                        response.getBody());
                inputStreamCallback.doWithInputStream(inputStream);

                String eTagHeader = response.getHeaders().getETag();

                if (StringUtils.isNotEmpty(eTagHeader)) {
                    String eTag = StringUtils.removeDoubleQuotes(eTagHeader);

                    byte[] contentMd5 = inputStream.getMd5Digest();
                    if (!HashUtils.md5MatchesWithETag(contentMd5, eTag)) {
                        throw new AppGluRestClientException("Unable to verify integrity of downloaded file. "
                                + "Client calculated content hash didn't match hash calculated by server");
                    }
                }

                return true;
            }
        };

        return this.downloadRestOperations.execute(uri, HttpMethod.GET, requestCallback, responseExtractor);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.appglu.impl.UserTemplate.java

private AuthenticationResult authenticate(String url, UserBody user) {
    try {/* w  w w .  jav  a2 s . com*/
        ResponseEntity<UserBody> response = this.restOperations.exchange(url, HttpMethod.POST,
                new HttpEntity<UserBody>(user), UserBody.class);
        this.saveSessionId(response);
        this.saveAuthenticatedUser(response);
        return new AuthenticationResult(true);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.appglu.impl.CrudTemplate.java

/**
 * {@inheritDoc}/*from   w w w . j  ava 2s .c om*/
 */
public Object create(String tableName, Row row) throws AppGluRestClientException {
    try {
        RowBody primaryKey = this.restOperations.postForObject(CRUD_TABLE_URL, new RowBody(row), RowBody.class,
                tableName);
        return this.extractPrimaryKeyValue(primaryKey.getRow());
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.appglu.impl.CrudTemplate.java

/**
 * {@inheritDoc}//from  w w w.  j  a v a 2  s.  co m
 */
public Rows readAll(String tableName, boolean expandRelationships, ReadAllFilterArguments arguments)
        throws AppGluRestClientException {
    try {
        String readAllUrl = this.buildReadAllUrl(expandRelationships, arguments);
        return this.restOperations.getForObject(readAllUrl, Rows.class, tableName);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.qdeve.oilprice.reader.ContentReader.java

private String getContentViaHttpClient() {
    String body = null;// w w w .  j  av  a2s. c om
    try {
        body = restTemplate.getForObject(properties.getContentPath(), String.class);
    } catch (RestClientException e) {
        throw new ProcessingException("Failed to retrieve content from " + properties.getContentPath()
                + ", reason: " + e.getMessage(), e);
    }

    return body;
}

From source file:com.appglu.impl.SyncTemplate.java

/**
 * {@inheritDoc}/*w w w  .  j a v a  2 s .  c  o m*/
 */
public TableChanges changesForTable(String tableName, long version) throws AppGluRestClientException {
    try {
        return this.restOperations.getForObject(CHANGES_FOR_TABLE_URL, TableChanges.class, tableName, version);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.appglu.impl.SyncTemplate.java

/**
 * {@inheritDoc}/*from w w  w  .j a v  a 2 s .c o m*/
 */
public List<TableChanges> changesForTables(List<TableVersion> tables) throws AppGluRestClientException {
    try {
        TableVersionBody body = new TableVersionBody(tables);
        TableChangesBody response = this.restOperations.postForObject(CHANGES_FOR_TABLES_URL, body,
                TableChangesBody.class);
        return response.getTables();
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.appglu.impl.SyncTemplate.java

/**
 * {@inheritDoc}//  w  w  w . j  ava  2 s  .  c o m
 */
public List<TableVersion> versionsForTables(List<String> tables) throws AppGluRestClientException {
    try {
        String tablesParameter = StringUtils.collectionToCommaDelimitedString(tables);
        TableVersionBody response = this.restOperations.getForObject(VERSIONS_FOR_TABLES_URL,
                TableVersionBody.class, tablesParameter);
        return response.getTables();
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.arvato.thoroughly.util.RestTemplateUtil.java

/**
 * @param url//  w  w w .ja  va 2s .  c  o  m
 * @param content
 *           It must be json format data
 * @return Results <br>
 *         code : http status <br>
 *         responseBody : http response body
 */
public JsonObject post(String url, String content) throws TmallAppException {
    LOGGER.trace("Post url:" + url);
    HttpEntity<String> request = new HttpEntity<String>(content, createHeaders());
    ResponseEntity<String> entity = null;
    try {
        entity = restTemplate.postForEntity(url, request, String.class);
    } catch (RestClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new TmallAppException(ResponseCode.CONNECTION_REFUSED.getCode(),
                "Connection refused:unknown URL content:" + url);
    }

    LOGGER.trace("Post data :" + content);
    LOGGER.trace("Response status:" + entity.getStatusCode().value());
    LOGGER.trace("Response body:" + entity.getBody());

    JsonObject responseObject = new JsonObject();
    if (entity.getStatusCode().value() == 200) {
        String responseBody = entity.getBody();
        JsonParser parser = new JsonParser();
        responseObject = parser.parse(responseBody).getAsJsonObject();
    } else {
        responseObject.addProperty("code", entity.getStatusCode().toString());
        responseObject.addProperty("msg", entity.getBody());
    }
    return responseObject;
}