下面列出了org.springframework.http.HttpStatus#is2xxSuccessful ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("unchecked")
protected StatusInfo getStatusInfoFromStatus(HttpStatus httpStatus, Map<String, ?> body) {
if (httpStatus.is2xxSuccessful()) {
return StatusInfo.ofUp();
}
Map<String, Object> details = new LinkedHashMap<>();
details.put("status", httpStatus.value());
details.put("error", httpStatus.getReasonPhrase());
if (body.get("details") instanceof Map) {
details.putAll((Map<? extends String, ?>) body.get("details"));
}
else {
details.putAll(body);
}
return StatusInfo.ofDown(details);
}
protected void doDeployment(String site, String environment, boolean waitTillDone) {
String requestUrl = getDeployTargetUrl(site, environment);
HttpPost postRequest = new HttpPost(requestUrl);
if (waitTillDone) {
String requestBody = getDeployTargetRequestBody(true);
HttpEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
postRequest.setEntity(requestEntity);
}
// TODO: DB: add all required params to post method
try {
CloseableHttpResponse response = httpClient.execute(postRequest);
HttpStatus httpStatus = HttpStatus.valueOf(response.getStatusLine().getStatusCode());
if (!httpStatus.is2xxSuccessful()) {
logger.error("Preview sync request for site " + site + " returned status " + httpStatus + " (" +
httpStatus.getReasonPhrase() + ")");
}
} catch (IOException e) {
logger.error("Error while sending preview sync request for site " + site, e);
} finally {
postRequest.releaseConnection();
}
}
@SuppressWarnings("unchecked")
protected StatusInfo getStatusInfoFromStatus(HttpStatus httpStatus, Map<String, ?> body) {
if (httpStatus.is2xxSuccessful()) {
return StatusInfo.ofUp();
}
Map<String, Object> details = new LinkedHashMap<>();
details.put("status", httpStatus.value());
details.put("error", httpStatus.getReasonPhrase());
if (body.get("details") instanceof Map) {
details.putAll((Map<? extends String, ?>) body.get("details"));
} else {
details.putAll(body);
}
return StatusInfo.ofDown(details);
}
private void rest(String[] line) {
String httpMethod = line[1];
String url = line[2];
String body = line[3];
body = applyParams(line, 4, body, isoFormat);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpStatus statusCode = null;
for (int i = 0; i < 3; i++) {
try {
statusCode = fbApp.command(url, HttpMethod.valueOf(httpMethod), body);
if (statusCode.is2xxSuccessful()) {
logger.debug("{} {} {} {}", statusCode, httpMethod, url, body);
return;
}
if (statusCode == HttpStatus.NOT_FOUND || statusCode == HttpStatus.UNPROCESSABLE_ENTITY) {
logger.warn("retry {} {} {} {}", statusCode, httpMethod, url, body);
sleep(2000);
continue;
}
throw new RuntimeException(statusCode + " " + httpMethod + " " + url + " " + body);
} catch (RestClientException e) {
throw new RuntimeException(httpMethod + " " + url + " " + body, e);
}
}
throw new RuntimeException("Response status is still " + statusCode + " " + httpMethod + " " + url
+ " " + body);
}
public String addUser() {
User user = new User(1L, "mrbird", "123456");
HttpStatus status = this.restTemplate.postForEntity("http://Server-Provider/user", user, null).getStatusCode();
if (status.is2xxSuccessful()) {
return "新增用户成功";
} else {
return "新增用户失败";
}
}
@GetMapping("user/add")
public String addUser() {
User user = new User(1L, "mrbird", "123456");
HttpStatus status = this.restTemplate.postForEntity("http://Server-Provider/user", user, null).getStatusCode();
if (status.is2xxSuccessful()) {
return "新增用户成功";
} else {
return "新增用户失败";
}
}
public String addUser() {
User user = new User(1L, "mrbird", "123456");
HttpStatus status = this.restTemplate.postForEntity("http://Server-Provider/user", user, null).getStatusCode();
if (status.is2xxSuccessful()) {
return "新增用户成功";
} else {
return "新增用户失败";
}
}
public String addUser() {
User user = new User(1L, "mrbird", "123456");
HttpStatus status = this.restTemplate.postForEntity("http://Server-Provider/user", user, null).getStatusCode();
if (status.is2xxSuccessful()) {
return "新增用户成功";
} else {
return "新增用户失败";
}
}
private Mono<?> transform(ClientResponse response) {
HttpStatus status = response.statusCode();
if (!status.is2xxSuccessful()) {
if (this.props.isDebug()) {
logger.info("Delaying supplier based on status=" + response.statusCode());
}
return Mono.delay(Duration.ofSeconds(1));
}
return response.bodyToMono(this.props.getSource().getType())
.map(value -> message(response, value));
}
public InstanceInfo getInstanceInfo(String appname, String instanceId) {
EurekaHttpResponse<InstanceInfo> response = getEurekaHttpClient()
.getInstance(appname, instanceId);
HttpStatus httpStatus = HttpStatus.valueOf(response.getStatusCode());
if (httpStatus.is2xxSuccessful() && response.getEntity() != null) {
return response.getEntity();
}
return null;
}
private boolean isResponseSuccessful(int statusCode) {
HttpStatus status = HttpStatus.valueOf(statusCode);
return status.is2xxSuccessful();
}
private boolean isSuccessful(EurekaHttpResponse<Applications> response) {
HttpStatus httpStatus = HttpStatus.resolve(response.getStatusCode());
return httpStatus != null && httpStatus.is2xxSuccessful();
}