Java Code Examples for org.springframework.http.HttpStatus#is2xxSuccessful()
The following examples show how to use
org.springframework.http.HttpStatus#is2xxSuccessful() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusUpdater.java From spring-boot-admin with Apache License 2.0 | 8 votes |
@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); }
Example 2
Source File: PreviewDeployerImpl.java From studio with GNU General Public License v3.0 | 6 votes |
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(); } }
Example 3
Source File: StatusUpdater.java From Moss with Apache License 2.0 | 5 votes |
@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); }
Example 4
Source File: DemoApplication.java From football-events with MIT License | 5 votes |
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); }
Example 5
Source File: UserService.java From SpringAll with MIT License | 5 votes |
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 "新增用户失败"; } }
Example 6
Source File: TestController.java From SpringAll with MIT License | 5 votes |
@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 "新增用户失败"; } }
Example 7
Source File: UserService.java From SpringAll with MIT License | 5 votes |
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 "新增用户失败"; } }
Example 8
Source File: UserService.java From SpringAll with MIT License | 5 votes |
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 "新增用户失败"; } }
Example 9
Source File: HttpSupplier.java From spring-cloud-function with Apache License 2.0 | 5 votes |
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)); }
Example 10
Source File: CloudEurekaClient.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
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; }
Example 11
Source File: AuditLoggingFilter.java From cerberus with Apache License 2.0 | 4 votes |
private boolean isResponseSuccessful(int statusCode) { HttpStatus status = HttpStatus.valueOf(statusCode); return status.is2xxSuccessful(); }
Example 12
Source File: EurekaConfigServerBootstrapConfiguration.java From spring-cloud-netflix with Apache License 2.0 | 4 votes |
private boolean isSuccessful(EurekaHttpResponse<Applications> response) { HttpStatus httpStatus = HttpStatus.resolve(response.getStatusCode()); return httpStatus != null && httpStatus.is2xxSuccessful(); }