当前位置: 首页>>代码示例>>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;未经允许,请勿转载。