ExchangeResult.java (spring-framework-5.3.23) | : | ExchangeResult.java (spring-framework-5.3.24) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright 2002-2021 the original author or authors. | * Copyright 2002-2022 the original author or authors. | |||
* | * | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | |||
* | * | |||
* https://www.apache.org/licenses/LICENSE-2.0 | * https://www.apache.org/licenses/LICENSE-2.0 | |||
* | * | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
skipping to change at line 53 | skipping to change at line 53 | |||
* Container for request and response details for exchanges performed through | * Container for request and response details for exchanges performed through | |||
* {@link WebTestClient}. | * {@link WebTestClient}. | |||
* | * | |||
* <p>Note that a decoded response body is not exposed at this level since the | * <p>Note that a decoded response body is not exposed at this level since the | |||
* body may not have been decoded and consumed yet. Subtypes | * body may not have been decoded and consumed yet. Subtypes | |||
* {@link EntityExchangeResult} and {@link FluxExchangeResult} provide access | * {@link EntityExchangeResult} and {@link FluxExchangeResult} provide access | |||
* to a decoded response entity and a decoded (but not consumed) response body | * to a decoded response entity and a decoded (but not consumed) response body | |||
* respectively. | * respectively. | |||
* | * | |||
* @author Rossen Stoyanchev | * @author Rossen Stoyanchev | |||
* @author Sam Brannen | ||||
* @since 5.0 | * @since 5.0 | |||
* @see EntityExchangeResult | * @see EntityExchangeResult | |||
* @see FluxExchangeResult | * @see FluxExchangeResult | |||
*/ | */ | |||
public class ExchangeResult { | public class ExchangeResult { | |||
private static final Log logger = LogFactory.getLog(ExchangeResult.class) ; | private static final Log logger = LogFactory.getLog(ExchangeResult.class) ; | |||
private static final List<MediaType> PRINTABLE_MEDIA_TYPES = Arrays.asLis t( | private static final List<MediaType> PRINTABLE_MEDIA_TYPES = Arrays.asLis t( | |||
MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, | MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, | |||
skipping to change at line 170 | skipping to change at line 171 | |||
* for any reason yet, use of this method will trigger consumption. | * for any reason yet, use of this method will trigger consumption. | |||
* @throws IllegalStateException if the request body has not been fully w ritten. | * @throws IllegalStateException if the request body has not been fully w ritten. | |||
*/ | */ | |||
@Nullable | @Nullable | |||
public byte[] getRequestBodyContent() { | public byte[] getRequestBodyContent() { | |||
return this.requestBody.block(this.timeout); | return this.requestBody.block(this.timeout); | |||
} | } | |||
/** | /** | |||
* Return the HTTP status code as an {@link HttpStatus} enum value. | * Return the HTTP status code as an {@link HttpStatus} enum value. | |||
* @throws IllegalArgumentException in case of an unknown HTTP status cod | ||||
e | ||||
* @see #getRawStatusCode() | ||||
*/ | */ | |||
public HttpStatus getStatus() { | public HttpStatus getStatus() { | |||
return this.response.getStatusCode(); | return this.response.getStatusCode(); | |||
} | } | |||
/** | /** | |||
* Return the HTTP status code (potentially non-standard and not resolvab le | * Return the HTTP status code (potentially non-standard and not resolvab le | |||
* through the {@link HttpStatus} enum) as an integer. | * through the {@link HttpStatus} enum) as an integer. | |||
* @since 5.1.10 | * @since 5.1.10 | |||
*/ | */ | |||
skipping to change at line 246 | skipping to change at line 249 | |||
} | } | |||
@Override | @Override | |||
public String toString() { | public String toString() { | |||
return "\n" + | return "\n" + | |||
"> " + getMethod() + " " + getUrl() + "\n" + | "> " + getMethod() + " " + getUrl() + "\n" + | |||
"> " + formatHeaders(getRequestHeaders(), "\n> ") + "\n" + | "> " + formatHeaders(getRequestHeaders(), "\n> ") + "\n" + | |||
"\n" + | "\n" + | |||
formatBody(getRequestHeaders().getContentType(), this.requestBody) + "\n" + | formatBody(getRequestHeaders().getContentType(), this.requestBody) + "\n" + | |||
"\n" + | "\n" + | |||
"< " + getStatus() + " " + getStatus().getReasonP hrase() + "\n" + | "< " + formatStatus() + "\n" + | |||
"< " + formatHeaders(getResponseHeaders(), "\n< " ) + "\n" + | "< " + formatHeaders(getResponseHeaders(), "\n< " ) + "\n" + | |||
"\n" + | "\n" + | |||
formatBody(getResponseHeaders().getContentType(), this.responseBody) +"\n" + | formatBody(getResponseHeaders().getContentType(), this.responseBody) +"\n" + | |||
formatMockServerResult(); | formatMockServerResult(); | |||
} | } | |||
private String formatStatus() { | ||||
try { | ||||
return getStatus() + " " + getStatus().getReasonPhrase(); | ||||
} | ||||
catch (Exception ex) { | ||||
return Integer.toString(getRawStatusCode()); | ||||
} | ||||
} | ||||
private String formatHeaders(HttpHeaders headers, String delimiter) { | private String formatHeaders(HttpHeaders headers, String delimiter) { | |||
return headers.entrySet().stream() | return headers.entrySet().stream() | |||
.map(entry -> entry.getKey() + ": " + entry.getVa lue()) | .map(entry -> entry.getKey() + ": " + entry.getVa lue()) | |||
.collect(Collectors.joining(delimiter)); | .collect(Collectors.joining(delimiter)); | |||
} | } | |||
@Nullable | @Nullable | |||
private String formatBody(@Nullable MediaType contentType, Mono<byte[]> b ody) { | private String formatBody(@Nullable MediaType contentType, Mono<byte[]> b ody) { | |||
return body | return body | |||
.map(bytes -> { | .map(bytes -> { | |||
End of changes. 5 change blocks. | ||||
2 lines changed or deleted | 15 lines changed or added |