/** * Indicates whether the response has a message body. * <p>Implementation returns {@code false} for: * <ul> * <li>a response status of {@code 1XX}, {@code 204} or {@code 304}</li> * <li>a {@code Content-Length} header of {@code 0}</li> * </ul> * @return {@code true} if the response has a message body, {@code false} otherwise * @throws IOException in case of I/O errors */ public boolean hasMessageBody() throws IOException { HttpStatus status = HttpStatus.resolve(getRawStatusCode()); if (status != null && (status.is1xxInformational() || status == HttpStatus.NO_CONTENT || status == HttpStatus.NOT_MODIFIED)) { return false; } if (getHeaders().getContentLength() == 0) { return false; } return true; }
/** * Indicates whether the response has a message body. * <p>Implementation returns {@code false} for: * <ul> * <li>a response status of {@code 1XX}, {@code 204} or {@code 304}</li> * <li>a {@code Content-Length} header of {@code 0}</li> * </ul> * @return {@code true} if the response has a message body, {@code false} otherwise * @throws IOException in case of I/O errors */ public boolean hasMessageBody() throws IOException { HttpStatus status = HttpStatus.resolve(getRawStatusCode()); if (status != null && (status.is1xxInformational() || status == HttpStatus.NO_CONTENT || status == HttpStatus.NOT_MODIFIED)) { return false; } if (getHeaders().getContentLength() == 0) { return false; } return true; }
/** * Creates an {@code outcome} tag based on the response status of the given * {@code exchange}. * @param exchange the exchange * @return the outcome tag derived from the response status * @since 2.1.0 */ public static Tag outcome(ServerWebExchange exchange) { HttpStatus status = exchange.getResponse().getStatusCode(); if (status != null) { if (status.is1xxInformational()) { return OUTCOME_INFORMATIONAL; } if (status.is2xxSuccessful()) { return OUTCOME_SUCCESS; } if (status.is3xxRedirection()) { return OUTCOME_REDIRECTION; } if (status.is4xxClientError()) { return OUTCOME_CLIENT_ERROR; } return OUTCOME_SERVER_ERROR; } return OUTCOME_UNKNOWN; }
private static boolean isInfo(Integer statusCode) { return HttpStatus.valueOf(statusCode).is1xxInformational() || HttpStatus.valueOf(statusCode).is2xxSuccessful(); }
/** * Indicates whether the response has a message body. * <p>Implementation returns {@code false} for: * <ul> * <li>a response status of {@code 1XX}, {@code 204} or {@code 304}</li> * <li>a {@code Content-Length} header of {@code 0}</li> * </ul> * @return {@code true} if the response has a message body, {@code false} otherwise * @throws IOException in case of I/O errors */ public boolean hasMessageBody() throws IOException { HttpStatus status = HttpStatus.resolve(getRawStatusCode()); if (status != null && (status.is1xxInformational() || status == HttpStatus.NO_CONTENT || status == HttpStatus.NOT_MODIFIED)) { return false; } if (getHeaders().getContentLength() == 0) { return false; } return true; }
/** * Indicates whether the response has a message body. * <p>Implementation returns {@code false} for: * <ul> * <li>a response status of {@code 1XX}, {@code 204} or {@code 304}</li> * <li>a {@code Content-Length} header of {@code 0}</li> * </ul> * @return {@code true} if the response has a message body, {@code false} otherwise * @throws IOException in case of I/O errors */ public boolean hasMessageBody() throws IOException { HttpStatus status = HttpStatus.resolve(getRawStatusCode()); if (status != null && (status.is1xxInformational() || status == HttpStatus.NO_CONTENT || status == HttpStatus.NOT_MODIFIED)) { return false; } if (getHeaders().getContentLength() == 0) { return false; } return true; }
/** * @param status * @param translatableMessage */ public RestMessage(HttpStatus status, TranslatableMessage message) { super(); this.message = message.translate(Common.getTranslations()); if(status.is1xxInformational()||status.is2xxSuccessful()) this.level = RestMessageLevel.INFORMATION; else if(status.is3xxRedirection()) this.level = RestMessageLevel.WARNING; else if(status.is4xxClientError() || status.is5xxServerError()) this.level = RestMessageLevel.ERROR; this.status = status; }
public static Tag outcome(ClientHttpResponse response) { try { if (response != null) { HttpStatus statusCode = response.getStatusCode(); if (statusCode.is1xxInformational()) { return OUTCOME_INFORMATIONAL; } if (statusCode.is2xxSuccessful()) { return OUTCOME_SUCCESS; } if (statusCode.is3xxRedirection()) { return OUTCOME_REDIRECTION; } if (statusCode.is4xxClientError()) { return OUTCOME_CLIENT_ERROR; } if (statusCode.is5xxServerError()) { return OUTCOME_SERVER_ERROR; } } return OUTCOME_UNKNOWN; } catch (IOException | IllegalArgumentException e) { return OUTCOME_UNKNOWN; } } }