本文整理汇总了Java中org.springframework.web.client.HttpStatusCodeException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodeException.getMessage方法的具体用法?Java HttpStatusCodeException.getMessage怎么用?Java HttpStatusCodeException.getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.client.HttpStatusCodeException
的用法示例。
在下文中一共展示了HttpStatusCodeException.getMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例3: run
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
/**
* This delagates actual execution to {@link #runWithUrl(String)} and handles any
* Spring Rest exceptions, wrapping them as necessary. Default behavior is to throw
* a {@link RetryableApiCommandException} for 5xx errors and timeouts, and {@link
* NonRetryableApiCommandException} for all others. If you need different behavior
* your best bet is to write your own {@link RemoteServiceCallback} and/or use
* the various flavors of {@link org.springframework.web.client.RestTemplate} that
* take let you provide {@link ResponseErrorHandler}.
* @param url The URL of the remote service.
* @return Result of the remote call, or potentially throws an exception if an
* error occurs calling the remote service.
*/
@Override
public T run(String url)
{
T response = null;
try
{
LOG.debug("Running command {} with URL {}", getContext().getCommandName(), url);
response = runWithUrl(url);
}
catch (HttpStatusCodeException hsce)
{
if (hsce.getStatusCode() == HttpStatus.REQUEST_TIMEOUT ||
hsce.getStatusCode().value() >= 500)
{
throw new RetryableApiCommandException("Remote server error: " + hsce.getMessage(), hsce);
}
else
{
throw new NonRetryableApiCommandException("Local client error: " + hsce.getMessage(), hsce);
}
}
catch(HttpMessageConversionException e)
{
throw new NonRetryableApiCommandException("Invalid response from server: " + e.getMessage(), e);
}
LOG.debug("Returning response {}", response);
return response;
}
示例4: handleHttpStatusCodeException
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
@ExceptionHandler(HttpStatusCodeException.class)
public void handleHttpStatusCodeException(
HttpStatusCodeException e,
HttpServletResponse response) throws IOException {
String message = extractErrorFromJSON(e.getResponseBodyAsString());
message = StringUtils.isNotBlank(message) ? message : e.getMessage();
logAndSendErrorResponse(response, e.getStatusCode(), message, e);
}
示例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: handleConstraintViolation
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
@ExceptionHandler({ HttpServerErrorException.class, HttpClientErrorException.class})
public ResponseEntity<ApiError> handleConstraintViolation(WebRequest request, HttpStatusCodeException ex) {
ApiError apiError = new ApiError(ex.getStatusCode(), ex.getMessage());
return new ResponseEntity<>(apiError, ex.getStatusCode());
}