本文整理汇总了Java中org.springframework.web.client.HttpStatusCodeException.getResponseBodyAsString方法的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodeException.getResponseBodyAsString方法的具体用法?Java HttpStatusCodeException.getResponseBodyAsString怎么用?Java HttpStatusCodeException.getResponseBodyAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.client.HttpStatusCodeException
的用法示例。
在下文中一共展示了HttpStatusCodeException.getResponseBodyAsString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHttpErrorMessage
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
/**
*
* @param error
* @return Error message containing description of the error. If no
* description is found, it will return the exception error or HTTP status
* text message, if present. May return null if no message can be resolved.
*/
protected static String getHttpErrorMessage(HttpStatusCodeException error) {
String message = null;
if (error instanceof CloudFoundryException) {
message = ((CloudFoundryException) error).getDescription();
}
if (message == null) {
message = error.getMessage();
if (message == null) {
message = error.getStatusText();
if (message == null) {
message = error.getResponseBodyAsString();
}
}
}
return message;
}
示例2: callDownstream
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private String callDownstream(String uri) {
try {
ResponseEntity<String> responseEntity = this.oAuth2RestTemplate.getForEntity(uri, String.class);
return responseEntity.getBody();
} catch(HttpStatusCodeException statusCodeException) {
return statusCodeException.getResponseBodyAsString();
}
}
示例3: request
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private String request(RestTemplate template) {
// Uninitialized and sealed can cause status 500
try {
ResponseEntity<String> responseEntity = template.exchange(url, HttpMethod.GET,
null, String.class);
return responseEntity.getBody();
}
catch (HttpStatusCodeException e) {
return e.getResponseBodyAsString();
}
}
开发者ID:spring-projects,项目名称:spring-vault,代码行数:13,代码来源:ClientHttpRequestFactoryFactoryIntegrationTests.java
示例4: retrieveErrorMessage
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
protected String retrieveErrorMessage(Throwable e) {
if (e instanceof HttpStatusCodeException) {
HttpStatusCodeException ex = (HttpStatusCodeException) e;
return ex.getMessage() + ": " + ex.getResponseBodyAsString();
}
return e.getMessage();
}
示例5: getMessage
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private String getMessage(String task, String url, HttpStatusCodeException e) {
String message = e.getMessage();
String jsonResponse = e.getResponseBodyAsString();
if (StringUtils.hasText(jsonResponse)) {
JsonNode json = POMUtils.parseJSONtoNode(jsonResponse);
JsonNode firstError = json.path("error").path("errors").path(0);
message += "; " + firstError.path("message").asText();
}
return "JDS error during " + task + " at \"" + url + "\": " + message;
}
示例6: handleHttpStatusCodeError
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
/**
* @param uriVariables
* @param tryNumber
* @param error
* @throws RestApiException if tryNumber >= API_RETRY.
*/
protected void handleHttpStatusCodeError(Map<String, String> uriVariables, int tryNumber, HttpStatusCodeException error) {
if (error.getStatusCode() == HttpStatus.UNAUTHORIZED) {
resetBhRestToken(uriVariables);
}
log.error(
"HttpStatusCodeError making api call. Try number:" + tryNumber + " out of " + API_RETRY + ". Http status code: "
+ error.getStatusCode() + ". Response body: " + error.getResponseBodyAsString(), error);
if (tryNumber >= API_RETRY) {
throw new RestApiException("HttpStatusCodeError making api call with url variables " + uriVariables.toString()
+ ". Http status code: " + error.getStatusCode().toString() + ". Response body: " + error == null ? ""
: error.getResponseBodyAsString());
}
}
示例7: makeRequest
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
/** Makes a generic request to the server with the specified attributes
*
* Automatically adds and requests the authentication to each request. Will automatically retry the request if the
* Authentication token has expired
*
* @param url The URL to make the request on
* @param method The HTTP method of the request
* @param requestEntity The request Entity representing the request body and headers
* @param responseType The expected response type of the request
* @param urlVariables Any url parameters
* @return The results from the request, or null if there were any errors
* @throws RequestException If an error occurred while making the request
*/
protected AFTResponse<T> makeRequest(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... urlVariables) throws RequestException {
HttpEntity<?> entity = addAuthenticationHeaders(requestEntity);
try {
ResponseEntity<T> results = restTemplate.exchange(url, method, entity, responseType, urlVariables);
return processSucessfulRequestResponse(results, url, method, requestEntity, responseType, urlVariables);
}
catch (HttpStatusCodeException e) {
String responseBody = e.getResponseBodyAsString();
HttpStatus status = e.getStatusCode();
return processErrorRequestResponse(responseBody, status, url, method, requestEntity, responseType, urlVariables);
}
}
示例8: executeHttpCmd
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private ResponseEntity<String> executeHttpCmd(
HttpCommand cmd,
BulbCmdTranslator_HTTP cmdTranslator)throws BulbBridgeHwException{
if(log.isDebugEnabled()){
log.debug("|- Invocing HTTP Cmd: " + cmd);
}
try{
ResponseEntity<String> resp = restClient.exchange(
cmd.getUrl(),
cmd.getHttpMethod(),
cmd.getEntity(), String.class, cmd.getUrlVariables());
if(HttpStatus.OK != resp.getStatusCode()){
throw new BulbBridgeHwException(
resp.getStatusCode().value(),
resp.getStatusCode().getReasonPhrase(),
resp.getBody());
}
InvocationResponse invocationResp;
if( (invocationResp = cmdTranslator.checkResponseForError(resp.getBody())) != null){
throw new BulbBridgeHwException(invocationResp.getMessage(), null);
}
return resp;
}catch(HttpStatusCodeException bbex){
throw new BulbBridgeHwException(
bbex.getStatusCode().value(), bbex.getStatusText(), bbex.getResponseBodyAsString());
}catch(RestClientException rcex){
throw new BulbBridgeHwException(rcex.getMessage(), rcex);
}
}
示例9: buildDataRetrievalException
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
protected DataRetrievalException buildDataRetrievalException(
HttpStatusCodeException ex) {
return new DataRetrievalException(
getResultClass().getSimpleName(), ex.getStatusCode(), ex.getResponseBodyAsString()
);
}
示例10: CredHubException
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
/**
* Create a new exception with the provided root cause.
*
* @param e an {@link HttpStatusCodeException} caught while attempting to communicate
* with CredHub
*/
public CredHubException(HttpStatusCodeException e) {
super("Error calling CredHub: " + e.getStatusCode() + ": "
+ e.getResponseBodyAsString());
}