本文整理汇总了Java中org.springframework.web.client.HttpStatusCodeException.getStatusText方法的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodeException.getStatusText方法的具体用法?Java HttpStatusCodeException.getStatusText怎么用?Java HttpStatusCodeException.getStatusText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.client.HttpStatusCodeException
的用法示例。
在下文中一共展示了HttpStatusCodeException.getStatusText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getResource
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private static void getResource(final String url, final Optional<String> mediaType) {
final HttpHeaders headers = new HttpHeaders();
if (mediaType.isPresent()) {
headers.setAccept(asList(parseMediaType(mediaType.get())));
}
try {
final ResponseEntity<String> responseEntity = restTemplate.exchange(
url,
GET,
new HttpEntity<>("parameters", headers), String.class
);
content = responseEntity.getBody();
statusCode = responseEntity.getStatusCode();
} catch (HttpStatusCodeException e) {
content = e.getStatusText();
statusCode = e.getStatusCode();
}
}
示例3: formatHttpException
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private String formatHttpException(HttpStatusCodeException e) {
try {
return MessageFormat.format("Response from server: {0} {1}\n {2}",
e.getStatusCode().value(),
e.getStatusText(),// getResponseBodyAsString - below
org.springframework.util.StringUtils.trimWhitespace(e.getResponseBodyAsString()));
} catch (Exception ex) {
log.error("Can not format exception {}", e, ex);
}
return e.getStatusText();
}
示例4: processStatusCodeException
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
protected void processStatusCodeException(HttpStatusCodeException e) {
String message;
try {
message = MessageFormat.format("Response from server: {0} {1}",
e.getStatusCode().value(),
e.getStatusText());
//we do not read error body, because it contains html code in some cases
} catch (Exception ex) {
message = e.getStatusText();
}
log.error("Error from server: {}", message, e);
}
示例5: executeHttpCmd
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private ResponseEntity<String> executeHttpCmd(
HttpCommand cmd,
BulbCmdTranslator_HTTP cmdTranslator)throws BulbBridgeHwException{
if(log.isDebugEnabled()){
log.debug("|- Invocing HTTP Cmd: " + cmd);
}
try{
ResponseEntity<String> resp = restClient.exchange(
cmd.getUrl(),
cmd.getHttpMethod(),
cmd.getEntity(), String.class, cmd.getUrlVariables());
if(HttpStatus.OK != resp.getStatusCode()){
throw new BulbBridgeHwException(
resp.getStatusCode().value(),
resp.getStatusCode().getReasonPhrase(),
resp.getBody());
}
InvocationResponse invocationResp;
if( (invocationResp = cmdTranslator.checkResponseForError(resp.getBody())) != null){
throw new BulbBridgeHwException(invocationResp.getMessage(), null);
}
return resp;
}catch(HttpStatusCodeException bbex){
throw new BulbBridgeHwException(
bbex.getStatusCode().value(), bbex.getStatusText(), bbex.getResponseBodyAsString());
}catch(RestClientException rcex){
throw new BulbBridgeHwException(rcex.getMessage(), rcex);
}
}
示例6: asCloudFoundryException
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private CloudFoundryException asCloudFoundryException(HttpStatusCodeException exception) {
String description = getDescriptionFromResponseBody(exception.getResponseBodyAsString());
return new CloudFoundryException(exception.getStatusCode(), exception.getStatusText(), description);
}
示例7: createExternalHttpRequestException
import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
protected ExternalHttpRequestException createExternalHttpRequestException(HttpMethod method, URI url, HttpStatusCodeException ex) {
return new ExternalHttpRequestException(method, url.toString(), ex.getStatusCode(), ex.getStatusText(), ex.getResponseHeaders(), ex.getResponseBodyAsByteArray(), getCharset(ex), jsonMapper, xmlMapper);
}