INT-4503: Fix assertion in HttpMessageHandlerSpec
JIRA: https://jira.spring.io/browse/INT-4503 Custom `ErrorHandler` can't be used if an external `RestTemplate` is provided * Replace `isClientSet()`` with ``!isClientSet()`` for `isTrue` assertion in `errorHandler` method * Replace assertion of `restTemplate` `isNull` with assertion `!isClientSet()` `isTrue` in the `requestFactory()` method * Add test coverage for the `errorHandler` into the `HttpDslTests` **Cherry-pick to 5.0.x**
This commit is contained in:
committed by
Artem Bilan
parent
1a4de86b30
commit
865e2162e5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2016-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.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Shiliang Li
|
||||
* @author Oleksii Komlyk
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
@@ -63,8 +64,7 @@ public class HttpMessageHandlerSpec
|
||||
* @return the spec
|
||||
*/
|
||||
public HttpMessageHandlerSpec requestFactory(ClientHttpRequestFactory requestFactory) {
|
||||
Assert.isNull(this.restTemplate,
|
||||
"the 'requestFactory' must be specified on the provided 'restTemplate': " + this.restTemplate);
|
||||
Assert.isTrue(!isClientSet(), "the 'requestFactory' must be specified on the provided 'restTemplate'");
|
||||
this.target.setRequestFactory(requestFactory);
|
||||
return this;
|
||||
}
|
||||
@@ -75,8 +75,7 @@ public class HttpMessageHandlerSpec
|
||||
* @return the spec
|
||||
*/
|
||||
public HttpMessageHandlerSpec errorHandler(ResponseErrorHandler errorHandler) {
|
||||
Assert.isTrue(this.isClientSet(),
|
||||
"the 'errorHandler' must be specified on the provided 'restTemplate'");
|
||||
Assert.isTrue(!isClientSet(), "the 'errorHandler' must be specified on the provided 'restTemplate'");
|
||||
this.target.setErrorHandler(errorHandler);
|
||||
return _this();
|
||||
}
|
||||
@@ -88,7 +87,7 @@ public class HttpMessageHandlerSpec
|
||||
* @return the spec
|
||||
*/
|
||||
public HttpMessageHandlerSpec messageConverters(HttpMessageConverter<?>... messageConverters) {
|
||||
Assert.isTrue(!isClientSet(), "the 'messageConverters' must be specified on the provided restTemplate");
|
||||
Assert.isTrue(!isClientSet(), "the 'messageConverters' must be specified on the provided 'restTemplate'");
|
||||
this.target.setMessageConverters(Arrays.asList(messageConverters));
|
||||
return _this();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user