本文整理汇总了Java中org.springframework.http.client.ClientHttpResponse.getStatusText方法的典型用法代码示例。如果您正苦于以下问题:Java ClientHttpResponse.getStatusText方法的具体用法?Java ClientHttpResponse.getStatusText怎么用?Java ClientHttpResponse.getStatusText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.client.ClientHttpResponse
的用法示例。
在下文中一共展示了ClientHttpResponse.getStatusText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
public void handleError(final ClientHttpResponse response) throws IOException {
HttpStatus statusCode = response.getStatusCode();
String statusText = response.getStatusText();
//
log.error("Handle error " + statusCode + " " + statusText);
switch (statusCode.series()) {
case CLIENT_ERROR:
throw new LoomClientException(statusText, statusCode.value());
case SERVER_ERROR:
String body = IOUtils.toString(response.getBody());
log.error("Server error " + statusCode + " body " + body);
throw new LoomClientException(statusText + " body: " + body, statusCode.value());
default:
throw new LoomClientException("Unknown status code [" + statusCode + "]", statusCode.value());
}
}
示例2: handleClientErrors
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
private static void handleClientErrors(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = response.getStatusCode();
Map<String, Object> errorMap = extractErrorDetailsFromResponse(response);
String errorText = "";
if (errorMap.containsKey("error")) {
errorText = (String) errorMap.get("error");
} else if (errorMap.containsKey("errors")) {
Object errors = errorMap.get("errors");
if (errors instanceof List) {
@SuppressWarnings("unchecked")
List<Map<String, String>> errorsList = (List<Map<String, String>>) errors;
errorText = errorsList.get(0).get("message");
} else if (errors instanceof String) {
errorText = (String) errors;
}
}
if (statusCode == HttpStatus.BAD_REQUEST) {
if (errorText.contains("Rate limit exceeded.")) {
throw new RateLimitExceededException(TWITTER);
}
} else if (statusCode == HttpStatus.UNAUTHORIZED) {
if (errorText == null) {
throw new NotAuthorizedException(TWITTER, response.getStatusText());
} else if ("Could not authenticate you.".equals(errorText)) {
throw new MissingAuthorizationException(TWITTER);
} else if ("Could not authenticate with OAuth.".equals(errorText)) { // revoked token
throw new RevokedAuthorizationException(TWITTER);
} else if ("Invalid / expired Token".equals(errorText)) {
// Note that Twitter doesn't actually expire tokens
throw new InvalidAuthorizationException(TWITTER, errorText);
} else {
throw new NotAuthorizedException(TWITTER, errorText);
}
} else if (statusCode == HttpStatus.FORBIDDEN) {
if (errorText.equals(DUPLICATE_STATUS_TEXT) || errorText.contains("You already said that")) {
throw new DuplicateStatusException(TWITTER, errorText);
} else if (errorText.equals(STATUS_TOO_LONG_TEXT) || errorText.contains(MESSAGE_TOO_LONG_TEXT)) {
throw new MessageTooLongException(errorText);
} else if (errorText.equals(INVALID_MESSAGE_RECIPIENT_TEXT)) {
throw new InvalidMessageRecipientException(errorText);
} else if (errorText.equals(DAILY_RATE_LIMIT_TEXT)) {
throw new RateLimitExceededException(TWITTER);
} else {
throw new OperationNotPermittedException(TWITTER, errorText);
}
} else if (statusCode == HttpStatus.NOT_FOUND) {
throw new ResourceNotFoundException(TWITTER, errorText);
} else if (statusCode == HttpStatus.valueOf(ENHANCE_YOUR_CALM) || statusCode == HttpStatus
.valueOf(TOO_MANY_REQUESTS)) {
throw new RateLimitExceededException(TWITTER);
}
}
示例3: getHttpStatusCode
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
private HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException {
HttpStatus statusCode;
try {
statusCode = response.getStatusCode();
}
catch (IllegalArgumentException ex) {
throw new UnknownHttpStatusCodeException(response.getRawStatusCode(),
response.getStatusText(), response.getHeaders(), getResponseBody(response), getCharset(response));
}
return statusCode;
}
示例4: handleError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
/**
* This default implementation throws a {@link HttpClientErrorException} if the response status code
* is {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}, a {@link HttpServerErrorException}
* if it is {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR},
* and a {@link RestClientException} in other cases.
*/
@Override
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = getHttpStatusCode(response);
switch (statusCode.series()) {
case CLIENT_ERROR:
throw new HttpClientErrorException(statusCode, response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
case SERVER_ERROR:
throw new HttpServerErrorException(statusCode, response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
default:
throw new RestClientException("Unknown status code [" + statusCode + "]");
}
}
示例5: handleError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = getHttpStatusCode(response);
// handle 3xx
switch (statusCode.series()) {
case REDIRECTION:
throw new HttpRedirectErrorException(statusCode, response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
}
// handler 4xx and 5xx
super.handleError(response);
}
示例6: getHttpStatusCode
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
protected HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException {
try {
return response.getStatusCode();
} catch (IllegalArgumentException ex) {
throw new UnknownHttpStatusCodeException(response.getRawStatusCode(), response.getStatusText(),
response.getHeaders(), getResponseBody(response), getCharset(response));
}
}