本文整理汇总了Java中org.springframework.http.client.ClientHttpResponse.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java ClientHttpResponse.getStatusCode方法的具体用法?Java ClientHttpResponse.getStatusCode怎么用?Java ClientHttpResponse.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.client.ClientHttpResponse
的用法示例。
在下文中一共展示了ClientHttpResponse.getStatusCode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = response.getStatusCode();
if (statusCode.series() == Series.SERVER_ERROR) {
handleServerErrors(statusCode);
} else if (statusCode.series() == Series.CLIENT_ERROR) {
handleClientErrors(response);
}
// if not otherwise handled, do default handling and wrap with UncategorizedApiException
try {
super.handleError(response);
} catch (Exception e) {
throw new UncategorizedApiException(TWITTER, "Error consuming Twitter REST API", e);
}
}
示例2: hasMessageBody
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
/**
* Indicates whether the given response has a message body. <p>Default implementation
* returns {@code false} for a response status of {@code 204} or {@code 304}, or a {@code
* Content-Length} of {@code 0}.
*
* @param response the response to check for a message body
* @return {@code true} if the response has a body, {@code false} otherwise
* @throws IOException in case of I/O errors
*/
protected boolean hasMessageBody(ClientHttpResponse response) throws IOException {
HttpStatus responseStatus = response.getStatusCode();
if (responseStatus == HttpStatus.NO_CONTENT ||
responseStatus == HttpStatus.NOT_MODIFIED) {
return false;
}
long contentLength = response.getHeaders().getContentLength();
return contentLength != 0;
}
示例3: 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());
}
}
示例4: 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);
}
}
示例5: handleError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = response.getStatusCode();
switch (statusCode.series()) {
case CLIENT_ERROR:
case SERVER_ERROR:
throw getException(response);
default:
throw new RestClientException("Unknown status code [" + statusCode + "]");
}
}
示例6: getAuthorizationResponseExtractor
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() {
return new ResponseExtractor<ResponseEntity<Void>>() {
public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
return new ResponseEntity(response.getHeaders(), response.getStatusCode());
}
};
}
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:8,代码来源:MyAuthorizationCodeAccessTokenProvider.java
示例7: handleError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
public void handleError(ClientHttpResponse clienthttpresponse) throws IOException {
if (clienthttpresponse.getStatusCode() == HttpStatus.FORBIDDEN) {
Logger.debug(this, HttpStatus.FORBIDDEN + " response. Throwing authentication exception");
// throw new AuthenticationException();
}
}
示例8: hasError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
public boolean hasError(ClientHttpResponse clienthttpresponse) throws IOException {
if (clienthttpresponse.getStatusCode() != HttpStatus.OK) {
String content = IOUtils.toString(clienthttpresponse.getBody(), "UTF-8");
// The server has successfully fulfilled the request and that there is no additional content to send in the response payload body.
if(clienthttpresponse.getStatusCode() == HttpStatus.NO_CONTENT) {
return false;
}
// JSON String to RestError
try {
// REST Error
ObjectMapper mapper = new ObjectMapper();
RestError restError = mapper.readValue(content, RestError.class);
// Add HTTP Status Code to Error
if (restError.getStatus() == null) {
restError.setStatus(clienthttpresponse.getStatusCode().ordinal());
}
throw new RestException(restError);
} catch (RestException restException) {
// Rethrow
throw restException;
} catch (Exception ex) {
// No REST Error
Logger.trace(this, "Status code: " + clienthttpresponse.getStatusCode());
Logger.trace(this, "Response" + clienthttpresponse.getStatusText());
Logger.trace(this, "Content: " + content);
if (clienthttpresponse.getStatusCode() == HttpStatus.FORBIDDEN) {
if (content.contains("used Cloudflare to restrict access")) {
Logger.warn(this, "Your current ip is banned by cloudflare, so you can't reach the target.");
} else {
Logger.debug(this, "Call returned a error 403 forbidden resposne ");
}
return true;
}
}
}
return false;
}
示例9: extractData
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
public ResponseEntity<T> extractData(ClientHttpResponse response) throws IOException {
if (this.delegate != null) {
T body = this.delegate.extractData(response);
return new ResponseEntity<T>(body, response.getHeaders(), response.getStatusCode());
}
else {
return new ResponseEntity<T>(response.getHeaders(), response.getStatusCode());
}
}
示例10: 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;
}
示例11: pingAndUpdateJvmState
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Override
@Transactional
public JvmHttpRequestResult pingAndUpdateJvmState(final Jvm jvm) {
ClientHttpResponse response = null;
JvmState jvmState = jvm.getState();
String responseDetails = StringUtils.EMPTY;
try {
response = clientFactoryHelper.requestGet(jvm.getStatusUri());
LOGGER.info(">>> Response = {} from jvm {}", response.getStatusCode(), jvm.getId().getId());
jvmState = JvmState.JVM_STARTED;
if (response.getStatusCode() == HttpStatus.OK) {
jvmStateService.updateState(jvm, jvmState, StringUtils.EMPTY);
} else {
// As long as we get a response even if it's not a 200 it means that the JVM is alive
jvmStateService.updateState(jvm, jvmState, StringUtils.EMPTY);
responseDetails = MessageFormat.format("Request {0} sent expecting a response code of {1} but got {2} instead",
jvm.getStatusUri(), HttpStatus.OK.value(), response.getRawStatusCode());
}
} catch (final IOException ioe) {
LOGGER.info(ioe.getMessage(), ioe);
jvmStateService.updateState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY);
responseDetails = MessageFormat.format("Request {0} sent and got: {1}", jvm.getStatusUri(), ioe.getMessage());
jvmState = JvmState.JVM_STOPPED;
} catch (RuntimeException rte) {
LOGGER.error(rte.getMessage(), rte);
} finally {
if (response != null) {
response.close();
}
}
return new JvmHttpRequestResult(jvmState, responseDetails);
}
示例12: 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));
}
}
示例13: doExecute
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@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,
new ResponseExtractor<T>() {
@SuppressWarnings("rawtypes")
public T extractData(ClientHttpResponse response) throws IOException {
httpStatus[0] = response.getStatusCode();
headers[0] = response.getHeaders();
T data = null;
if (responseExtractor != null && (data = responseExtractor.extractData(response)) != null) {
if (data instanceof String) {
message[0] = ((String) data).length() + " 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;
}
示例14: hasError
import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
/**
* Decide whether we have an error or not.
* @param response The response to check
* @return <code>true</code> if response is an error
* @throws IOException Error reading status code
*/
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return response.getStatusCode() != HttpStatus.OK;
}