當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientHttpResponse.getStatusText方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:19,代碼來源:RestClient.java

示例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);
    }

}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:56,代碼來源:TwitterErrorHandler.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:DefaultResponseErrorHandler.java

示例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 + "]");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:DefaultResponseErrorHandler.java

示例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);
}
 
開發者ID:vianneyfaivre,項目名稱:Persephone,代碼行數:15,代碼來源:RestErrorHandler.java

示例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));
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:9,代碼來源:WxResponseErrorHandler.java


注:本文中的org.springframework.http.client.ClientHttpResponse.getStatusText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。