本文整理匯總了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());
}