ResponseEntityResponseExtractor tolerates unknown HTTP status codes

Issue: SPR-16371
This commit is contained in:
Juergen Hoeller
2018-01-19 19:13:16 +01:00
parent f68fdd4454
commit c1bc74c83f
3 changed files with 68 additions and 83 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,9 +57,9 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse {
*/
public boolean hasMessageBody() throws IOException {
try {
HttpStatus responseStatus = getStatusCode();
if (responseStatus.is1xxInformational() || responseStatus == HttpStatus.NO_CONTENT ||
responseStatus == HttpStatus.NOT_MODIFIED) {
HttpStatus status = getStatusCode();
if (status != null && status.is1xxInformational() || status == HttpStatus.NO_CONTENT ||
status == HttpStatus.NOT_MODIFIED) {
return false;
}
}

View File

@@ -20,7 +20,6 @@ import java.io.IOException;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -931,10 +930,10 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
public ResponseEntity<T> extractData(ClientHttpResponse response) throws IOException {
if (this.delegate != null) {
T body = this.delegate.extractData(response);
return new ResponseEntity<T>(body, response.getHeaders(), response.getStatusCode());
return ResponseEntity.status(response.getRawStatusCode()).headers(response.getHeaders()).body(body);
}
else {
return new ResponseEntity<T>(response.getHeaders(), response.getStatusCode());
return ResponseEntity.status(response.getRawStatusCode()).headers(response.getHeaders()).build();
}
}
}