List of usage examples for org.springframework.http HttpStatus is5xxServerError
public boolean is5xxServerError()
From source file:org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils.java
public static BaseClientDetails createOrUpdateClient(String adminToken, String url, String switchToZoneId, BaseClientDetails client) throws Exception { RestTemplate template = new RestTemplate(); template.setErrorHandler(new DefaultResponseErrorHandler() { @Override//from www . j a v a 2s .c om protected boolean hasError(HttpStatus statusCode) { return statusCode.is5xxServerError(); } }); MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); headers.add("Accept", APPLICATION_JSON_VALUE); headers.add("Authorization", "bearer " + adminToken); headers.add("Content-Type", APPLICATION_JSON_VALUE); if (StringUtils.hasText(switchToZoneId)) { headers.add(IdentityZoneSwitchingFilter.HEADER, switchToZoneId); } HttpEntity getHeaders = new HttpEntity(JsonUtils.writeValueAsBytes(client), headers); ResponseEntity<String> clientCreate = template.exchange(url + "/oauth/clients", HttpMethod.POST, getHeaders, String.class); if (clientCreate.getStatusCode() == HttpStatus.CREATED) { return JsonUtils.readValue(clientCreate.getBody(), BaseClientDetails.class); } else if (clientCreate.getStatusCode() == HttpStatus.CONFLICT) { HttpEntity putHeaders = new HttpEntity(JsonUtils.writeValueAsBytes(client), headers); ResponseEntity<String> clientUpdate = template.exchange(url + "/oauth/clients/" + client.getClientId(), HttpMethod.PUT, putHeaders, String.class); if (clientUpdate.getStatusCode() == HttpStatus.OK) { return JsonUtils.readValue(clientCreate.getBody(), BaseClientDetails.class); } else { throw new RuntimeException("Invalid update return code:" + clientUpdate.getStatusCode()); } } throw new RuntimeException("Invalid crete return code:" + clientCreate.getStatusCode()); }
From source file:org.springframework.web.server.handler.ResponseStatusExceptionHandler.java
@Override public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) { if (ex instanceof ResponseStatusException) { HttpStatus status = ((ResponseStatusException) ex).getStatus(); if (exchange.getResponse().setStatusCode(status)) { if (status.is5xxServerError()) { logger.error(buildMessage(exchange.getRequest(), ex)); } else if (status == HttpStatus.BAD_REQUEST) { logger.warn(buildMessage(exchange.getRequest(), ex)); } else { logger.trace(buildMessage(exchange.getRequest(), ex)); }/*from w w w.j a v a 2s.c o m*/ return exchange.getResponse().setComplete(); } } return Mono.error(ex); }