Ensure withBasicAuth keeps error handler
Fix `TestRestTemplate` so that any custom `ErrorHandler` isn't lost when calling `withBasicAuth`. Fixes gh-7441
This commit is contained in:
@@ -916,14 +916,16 @@ public class TestRestTemplate {
|
||||
*/
|
||||
public TestRestTemplate withBasicAuth(String username, String password) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.setErrorHandler(getRestTemplate().getErrorHandler());
|
||||
restTemplate.setMessageConverters(getRestTemplate().getMessageConverters());
|
||||
restTemplate.setInterceptors(
|
||||
removeBasicAuthInterceptorIfPresent(getRestTemplate().getInterceptors()));
|
||||
restTemplate.setRequestFactory(getRestTemplate().getRequestFactory());
|
||||
restTemplate.setUriTemplateHandler(getRestTemplate().getUriTemplateHandler());
|
||||
return new TestRestTemplate(restTemplate, username, password,
|
||||
this.httpClientOptions);
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplate, username,
|
||||
password, this.httpClientOptions);
|
||||
testRestTemplate.getRestTemplate()
|
||||
.setErrorHandler(getRestTemplate().getErrorHandler());
|
||||
return testRestTemplate;
|
||||
}
|
||||
|
||||
private List<ClientHttpRequestInterceptor> removeBasicAuthInterceptorIfPresent(
|
||||
|
||||
Reference in New Issue
Block a user