Ensure WebClient exceptions are serializable
Not all HttpHeaders implementations are serializable. This commit ensures that WebClientRequestException and WebClientResponseException are serializable, by copying any non-serializable HttpHeaders into a new, serializable, instance. Closes gh-28321
This commit is contained in:
parent
97ea8a6789
commit
b8b54ee524
|
|
@ -17,6 +17,8 @@
|
||||||
package org.springframework.web.reactive.function.client;
|
package org.springframework.web.reactive.function.client;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
|
@ -56,7 +58,11 @@ public class WebClientRequestException extends WebClientException {
|
||||||
*/
|
*/
|
||||||
private static HttpHeaders copy(HttpHeaders headers) {
|
private static HttpHeaders copy(HttpHeaders headers) {
|
||||||
HttpHeaders result = new HttpHeaders();
|
HttpHeaders result = new HttpHeaders();
|
||||||
result.putAll(headers);
|
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||||
|
for (String value : entry.getValue()) {
|
||||||
|
result.add(entry.getKey(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ package org.springframework.web.reactive.function.client;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpRequest;
|
import org.springframework.http.HttpRequest;
|
||||||
|
|
@ -47,7 +49,7 @@ public class WebClientResponseException extends WebClientException {
|
||||||
private final Charset responseCharset;
|
private final Charset responseCharset;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final HttpRequest request;
|
private transient final HttpRequest request;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,7 +114,11 @@ public class WebClientResponseException extends WebClientException {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
HttpHeaders result = new HttpHeaders();
|
HttpHeaders result = new HttpHeaders();
|
||||||
result.putAll(headers);
|
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||||
|
for (String value : entry.getValue()) {
|
||||||
|
result.add(entry.getKey(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue