org.springframework.http.HttpStatus#is2xxSuccessful ( )源码实例Demo

下面列出了org.springframework.http.HttpStatus#is2xxSuccessful ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spring-boot-admin   文件: StatusUpdater.java
@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);
}
 
源代码2 项目: studio   文件: PreviewDeployerImpl.java
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();
    }
}
 
源代码3 项目: Moss   文件: StatusUpdater.java
@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);
}
 
源代码4 项目: football-events   文件: DemoApplication.java
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);
}
 
源代码5 项目: SpringAll   文件: UserService.java
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 "新增用户失败";
    }
}
 
源代码6 项目: SpringAll   文件: TestController.java
@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 "新增用户失败";
    }
}
 
源代码7 项目: SpringAll   文件: UserService.java
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 "新增用户失败";
    }
}
 
源代码8 项目: SpringAll   文件: UserService.java
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 "新增用户失败";
    }
}
 
源代码9 项目: spring-cloud-function   文件: HttpSupplier.java
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));
}
 
源代码10 项目: spring-cloud-netflix   文件: CloudEurekaClient.java
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;
}
 
源代码11 项目: cerberus   文件: AuditLoggingFilter.java
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();
}