本文整理匯總了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);
}