Java Code Examples for org.springframework.http.HttpStatus#Series

The following examples show how to use org.springframework.http.HttpStatus#Series . 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: StatusAssertions.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private WebTestClient.ResponseSpec assertSeriesAndReturn(HttpStatus.Series expected) {
	HttpStatus status = this.exchangeResult.getStatus();
	this.exchangeResult.assertWithDiagnostics(() -> {
		String message = "Range for response status value " + status;
		AssertionErrors.assertEquals(message, expected, status.series());
	});
	return this.responseSpec;
}
 
Example 2
Source File: StatusAssertions.java    From java-technology-stack with MIT License 5 votes vote down vote up
private WebTestClient.ResponseSpec assertSeriesAndReturn(HttpStatus.Series expected) {
	HttpStatus status = this.exchangeResult.getStatus();
	this.exchangeResult.assertWithDiagnostics(() -> {
		String message = "Range for response status value " + status;
		AssertionErrors.assertEquals(message, expected, status.series());
	});
	return this.responseSpec;
}
 
Example 3
Source File: HttpStatusHolder.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
public HttpStatus.Series getSeries() {
	if (httpStatus != null) {
		return httpStatus.series();
	}
	if (status != null) {
		return HttpStatus.Series.valueOf(status);
	}
	return null;
}
 
Example 4
Source File: StatusResultMatchers.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private HttpStatus.Series getHttpStatusSeries(MvcResult result) {
	int statusValue = result.getResponse().getStatus();
	HttpStatus status = HttpStatus.valueOf(statusValue);
	return status.series();
}
 
Example 5
Source File: StatusAssertions.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Assert the response status code is in the 5xx range.
 */
public WebTestClient.ResponseSpec is5xxServerError() {
	HttpStatus.Series expected = HttpStatus.Series.SERVER_ERROR;
	return assertSeriesAndReturn(expected);
}
 
Example 6
Source File: RestResponseErrorHandler.java    From mPaaS with Apache License 2.0 4 votes vote down vote up
protected boolean hasError(int unknownStatusCode) {
    HttpStatus.Series series = HttpStatus.Series.resolve(unknownStatusCode);
    return (series == HttpStatus.Series.CLIENT_ERROR || series == HttpStatus.Series.SERVER_ERROR);
}
 
Example 7
Source File: StatusResultMatchers.java    From java-technology-stack with MIT License 4 votes vote down vote up
private HttpStatus.Series getHttpStatusSeries(MvcResult result) {
	int statusValue = result.getResponse().getStatus();
	HttpStatus status = HttpStatus.valueOf(statusValue);
	return status.series();
}
 
Example 8
Source File: StatusAssertions.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Assert the response status code is in the 5xx range.
 */
public WebTestClient.ResponseSpec is5xxServerError() {
	HttpStatus.Series expected = HttpStatus.Series.SERVER_ERROR;
	return assertSeriesAndReturn(expected);
}
 
Example 9
Source File: StatusResultMatchers.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private HttpStatus.Series getHttpStatusSeries(MvcResult result) {
	int statusValue = result.getResponse().getStatus();
	HttpStatus status = HttpStatus.valueOf(statusValue);
	return status.series();
}
 
Example 10
Source File: Bindings.java    From riptide with MIT License 4 votes vote down vote up
public static PartialBinding<HttpStatus.Series> anySeries() {
    return any(HttpStatus.Series.class);
}
 
Example 11
Source File: ExtractingResponseErrorHandler.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set the mapping from HTTP status series to {@code RestClientException} subclass.
 * If this mapping has a match
 * for the {@linkplain ClientHttpResponse#getStatusCode() status code} of a given
 * {@code ClientHttpResponse}, {@link #hasError(ClientHttpResponse)} will return
 * {@code true} and {@link #handleError(ClientHttpResponse)} will attempt to use the
 * {@linkplain #setMessageConverters(List) configured message converters} to convert the
 * response into the mapped subclass of {@link RestClientException}.
 */
public void setSeriesMapping(Map<HttpStatus.Series, Class<? extends RestClientException>> seriesMapping) {
	if (!CollectionUtils.isEmpty(seriesMapping)) {
		this.seriesMapping.putAll(seriesMapping);
	}
}
 
Example 12
Source File: DefaultResponseErrorHandler.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Template method called from {@link #hasError(ClientHttpResponse)}.
 * <p>The default implementation checks if the given status code is
 * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR} or
 * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR SERVER_ERROR}.
 * Can be overridden in subclasses.
 * @param unknownStatusCode the HTTP status code as raw value
 * @return {@code true} if the response indicates an error; {@code false} otherwise
 * @since 4.3.21
 * @see org.springframework.http.HttpStatus.Series#CLIENT_ERROR
 * @see org.springframework.http.HttpStatus.Series#SERVER_ERROR
 */
protected boolean hasError(int unknownStatusCode) {
	HttpStatus.Series series = HttpStatus.Series.resolve(unknownStatusCode);
	return (series == HttpStatus.Series.CLIENT_ERROR || series == HttpStatus.Series.SERVER_ERROR);
}
 
Example 13
Source File: ExtractingResponseErrorHandler.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Set the mapping from HTTP status series to {@code RestClientException} subclass.
 * If this mapping has a match
 * for the {@linkplain ClientHttpResponse#getStatusCode() status code} of a given
 * {@code ClientHttpResponse}, {@link #hasError(ClientHttpResponse)} will return
 * {@code true} and {@link #handleError(ClientHttpResponse)} will attempt to use the
 * {@linkplain #setMessageConverters(List) configured message converters} to convert the
 * response into the mapped subclass of {@link RestClientException}.
 */
public void setSeriesMapping(Map<HttpStatus.Series, Class<? extends RestClientException>> seriesMapping) {
	if (!CollectionUtils.isEmpty(seriesMapping)) {
		this.seriesMapping.putAll(seriesMapping);
	}
}
 
Example 14
Source File: DefaultResponseErrorHandler.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Template method called from {@link #hasError(ClientHttpResponse)}.
 * <p>The default implementation checks if the given status code is
 * {@code HttpStatus.Series#CLIENT_ERROR CLIENT_ERROR} or
 * {@code HttpStatus.Series#SERVER_ERROR SERVER_ERROR}.
 * Can be overridden in subclasses.
 * @param unknownStatusCode the HTTP status code as raw value
 * @return {@code true} if the response indicates an error; {@code false} otherwise
 * @since 4.3.21
 * @see HttpStatus.Series#CLIENT_ERROR
 * @see HttpStatus.Series#SERVER_ERROR
 */
protected boolean hasError(int unknownStatusCode) {
	HttpStatus.Series series = HttpStatus.Series.resolve(unknownStatusCode);
	return (series == HttpStatus.Series.CLIENT_ERROR || series == HttpStatus.Series.SERVER_ERROR);
}