Fix HTTP out DSL for uri variables propagation
Since `AbstractHttpRequestExecutingMessageHandler` does a copy of the provided `uriVariableExpressions`, we lose a coupling propagating from the ctor. * Move `uriVariableExpressions` propagation from the ctor to the `getComponentsToRegister()`
This commit is contained in:
@@ -45,8 +45,10 @@ import org.springframework.web.client.RestTemplate;
|
||||
*
|
||||
* @param <S> the target {@link BaseHttpMessageHandlerSpec} implementation type.
|
||||
* @param <E> the target {@link AbstractHttpRequestExecutingMessageHandler} implementation type.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Shiliang Li
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public abstract class BaseHttpMessageHandlerSpec<S extends BaseHttpMessageHandlerSpec<S, E>, E extends AbstractHttpRequestExecutingMessageHandler>
|
||||
@@ -61,7 +63,6 @@ public abstract class BaseHttpMessageHandlerSpec<S extends BaseHttpMessageHandle
|
||||
|
||||
public BaseHttpMessageHandlerSpec(E handler) {
|
||||
this.target = handler;
|
||||
this.target.setUriVariableExpressions(this.uriVariableExpressions);
|
||||
this.target.setHeaderMapper(this.headerMapper);
|
||||
}
|
||||
|
||||
@@ -233,26 +234,28 @@ public abstract class BaseHttpMessageHandlerSpec<S extends BaseHttpMessageHandle
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a SpEL expression to evaluate a value for the uri template variable.
|
||||
* Specify an {@link Expression} to evaluate a value for the uri template variable.
|
||||
* @param variable the uri template variable.
|
||||
* @param value the expression to evaluate value for te uri template variable.
|
||||
* @param expression the expression to evaluate value for te uri template variable.
|
||||
* @return the current Spec.
|
||||
* @see AbstractHttpRequestExecutingMessageHandler#setUriVariableExpressions(Map)
|
||||
* @see ValueExpression
|
||||
* @see org.springframework.expression.common.LiteralExpression
|
||||
*/
|
||||
public S uriVariable(String variable, Expression value) {
|
||||
this.uriVariableExpressions.put(variable, value);
|
||||
public S uriVariable(String variable, Expression expression) {
|
||||
this.uriVariableExpressions.put(variable, expression);
|
||||
return _this();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a value for the uri template variable.
|
||||
* Specify a value SpEL expression for the uri template variable.
|
||||
* @param variable the uri template variable.
|
||||
* @param value the expression to evaluate value for te uri template variable.
|
||||
* @param expression the expression to evaluate value for te uri template variable.
|
||||
* @return the current Spec.
|
||||
* @see AbstractHttpRequestExecutingMessageHandler#setUriVariableExpressions(Map)
|
||||
*/
|
||||
public S uriVariable(String variable, String value) {
|
||||
return uriVariable(variable, PARSER.parseExpression(value));
|
||||
public S uriVariable(String variable, String expression) {
|
||||
return uriVariable(variable, PARSER.parseExpression(expression));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,6 +315,7 @@ public abstract class BaseHttpMessageHandlerSpec<S extends BaseHttpMessageHandle
|
||||
|
||||
@Override
|
||||
public Collection<Object> getComponentsToRegister() {
|
||||
this.target.setUriVariableExpressions(this.uriVariableExpressions);
|
||||
return Collections.singletonList(this.headerMapper);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user