Java Code Examples for org.springframework.web.client.RestClientException#getMessage()

The following examples show how to use org.springframework.web.client.RestClientException#getMessage() . 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: InfluxDBService.java    From influx-proxy with Apache License 2.0 6 votes vote down vote up
@Transactional(rollbackFor = Exception.class)
public void addNewRetention(ManagementInfoWarpPo managementInfoWarpPo) {
    if (managementInfoWarpPo.getId() != null) {
        throw new IllegalArgumentException("创建时ID必须为空");
    }
    managementInfoService.addNewRetention(managementInfoWarpPo);
    //同步到influxdb
    try {
        String createDatabaseUrl = String.format(Constants.CREATE_DATABASE_URL, managementInfoWarpPo.getNodeUrl(), managementInfoWarpPo.getDatabaseName());
        restTemplate.postForObject(createDatabaseUrl, null, String.class);
        String isDefault = "";
        if (managementInfoWarpPo.isRetentionDefault()) {
            isDefault = "default";
        }
        String createRetentionUrl = String.format(Constants.BASE_URL, managementInfoWarpPo.getNodeUrl(), managementInfoWarpPo.getDatabaseName());
        String createRetentionData = String.format(Constants.CREATE_RETENTION_URL, managementInfoWarpPo.getRetentionName(), managementInfoWarpPo.getDatabaseName(), managementInfoWarpPo.getRetentionDuration(), isDefault);
        URI createUri = getUri(createRetentionUrl, createRetentionData);
        restTemplate.postForObject(createUri, null, String.class);
    } catch (RestClientException e) {
        throw new InfluxDBProxyException(e.getMessage());
    }
}
 
Example 2
Source File: InfluxDBService.java    From influx-proxy with Apache License 2.0 6 votes vote down vote up
@Transactional(rollbackFor = Exception.class)
public void updateRetention(ManagementInfoPo managementInfoPo) {
    //根据 节点更新本地信息
    ManagementInfoPo lastManagementInfo = managementInfoService.updateRetention(managementInfoPo);
    //再更新influxdb
    String isDefault = "";
    if (lastManagementInfo.isDefault()) {
        isDefault = "default";
    }
    String updateRetentionUrl = String.format(Constants.BASE_URL, lastManagementInfo.getNodeUrl(), lastManagementInfo.getDatabaseName());
    String updateRetentionData = String.format(Constants.UPDATE_RETENTION_URL, lastManagementInfo.getRetentionName(), lastManagementInfo.getDatabaseName(), lastManagementInfo.getRetentionDuration(), isDefault);
    try {
        URI uri = getUri(updateRetentionUrl, updateRetentionData);
        restTemplate.postForObject(uri, null, String.class);
    } catch (RestClientException e) {
        throw new InfluxDBProxyException(e.getMessage());
    }
}
 
Example 3
Source File: InfluxDBService.java    From influx-proxy with Apache License 2.0 6 votes vote down vote up
@Transactional(rollbackFor = Exception.class)
public void synLocalDataToInfluxDB(Long id) {
    ManagementInfoPo managementInfoPo = managementInfoService.selectRetentionById(id);
    //同步influxdb
    String isDefault = "";
    if (managementInfoPo.isDefault()) {
        isDefault = "default";
    }
    String updateRetentionUrl = String.format(Constants.BASE_URL, managementInfoPo.getNodeUrl(), managementInfoPo.getDatabaseName());
    String updateRetentionData = String.format(Constants.UPDATE_RETENTION_URL, managementInfoPo.getRetentionName(), managementInfoPo.getDatabaseName(), managementInfoPo.getRetentionDuration(), isDefault);

    try {
        URI uri = getUri(updateRetentionUrl, updateRetentionData);
        restTemplate.postForObject(uri, null, String.class);
    } catch (RestClientException e) {
        throw new InfluxDBProxyException(e.getMessage());
    }
}
 
Example 4
Source File: InfluxDBService.java    From influx-proxy with Apache License 2.0 5 votes vote down vote up
@Transactional(rollbackFor = Exception.class)
public void deleteRetention(Long id) {
    //根据ID软删除本地信息
    ManagementInfoPo managementInfoPo = managementInfoService.deleteRetentionById(id);
    //再删除influxdb
    String deleteRetentionUrl = String.format(Constants.BASE_URL, managementInfoPo.getNodeUrl(), managementInfoPo.getDatabaseName());
    String deleteRetentionData = String.format(Constants.DELETE_RETENTION_URL, managementInfoPo.getRetentionName(), managementInfoPo.getDatabaseName());

    try {
        URI uri = getUri(deleteRetentionUrl, deleteRetentionData);
        restTemplate.postForObject(uri, null, String.class);
    } catch (RestClientException e) {
        throw new InfluxDBProxyException(e.getMessage());
    }
}
 
Example 5
Source File: EchoResponseErrorHandler.java    From Milkomeda with MIT License 5 votes vote down vote up
@Override
public void handleError(ClientHttpResponse response) throws IOException {
    try {
        errorHandler.handleError(response);
    } catch (RestClientException e) {
        if (e instanceof HttpStatusCodeException) {
            HttpStatusCodeException ce = (HttpStatusCodeException) e;
            log.error("Echo request with error code: {}, msg:{}, body:{}", ce.getStatusCode().value(), ce.getMessage(), ce.getResponseBodyAsString());
            throw new EchoException(ce.getStatusCode().value(), ce.getMessage(), ce.getResponseBodyAsString());
        }
        throw new EchoException(ErrorCode.VENDOR_REQUEST_ERROR, e.getMessage());
    }
}
 
Example 6
Source File: DefaultJwtBearerTokenResponseClient.java    From oauth2-protocol-patterns with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2AccessTokenResponse getTokenResponse(JwtBearerGrantRequest jwtBearerGrantRequest) {
	Assert.notNull(jwtBearerGrantRequest, "jwtBearerGrantRequest cannot be null");

	RequestEntity<?> request = this.requestEntityConverter.convert(jwtBearerGrantRequest);

	ResponseEntity<OAuth2AccessTokenResponse> response;
	try {
		response = this.restOperations.exchange(request, OAuth2AccessTokenResponse.class);
	} catch (RestClientException ex) {
		OAuth2Error oauth2Error = new OAuth2Error(INVALID_TOKEN_RESPONSE_ERROR_CODE,
				"An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: " + ex.getMessage(), null);
		throw new OAuth2AuthorizationException(oauth2Error, ex);
	}

	OAuth2AccessTokenResponse tokenResponse = response.getBody();

	if (CollectionUtils.isEmpty(tokenResponse.getAccessToken().getScopes())) {
		// As per spec, in Section 5.1 Successful Access Token Response
		// https://tools.ietf.org/html/rfc6749#section-5.1
		// If AccessTokenResponse.scope is empty, then default to the scope
		// originally requested by the client in the Token Request
		tokenResponse = OAuth2AccessTokenResponse.withResponse(tokenResponse)
				.scopes(jwtBearerGrantRequest.getClientRegistration().getScopes())
				.build();
	}

	return tokenResponse;
}
 
Example 7
Source File: LoggingRestTemplate.java    From cf-java-client-sap with Apache License 2.0 4 votes vote down vote up
@Override
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, final ResponseExtractor<T> responseExtractor)
    throws RestClientException {
    final String[] status = new String[1];
    final HttpStatus[] httpStatus = new HttpStatus[1];
    final Object[] headers = new Object[1];
    final String[] message = new String[1];
    T results = null;
    RestClientException exception = null;
    try {
        results = super.doExecute(url, method, requestCallback, response -> {
            httpStatus[0] = response.getStatusCode();
            headers[0] = response.getHeaders();
            T data;
            if (responseExtractor != null && (data = responseExtractor.extractData(response)) != null) {
                if (data instanceof String) {
                    message[0] = ((String) data).length() * 2 + " bytes";
                } else if (data instanceof Map) {
                    message[0] = ((Map) data).keySet()
                                             .toString();
                } else {
                    message[0] = data.getClass()
                                     .getName();
                }
                return data;
            } else {
                message[0] = "<no data>";
                return null;
            }
        });
        status[0] = "OK";
    } catch (RestClientException e) {
        status[0] = "ERROR";
        message[0] = e.getMessage();
        exception = e;
        if (e instanceof HttpStatusCodeException) {
            httpStatus[0] = ((HttpStatusCodeException) e).getStatusCode();
        }
    }
    addLogMessage(method, url, status[0], httpStatus[0], message[0]);
    if (exception != null) {
        throw exception;
    }
    return results;
}