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:
Artem Bilan
2017-03-28 11:33:00 -04:00
parent 85aead337f
commit 75fe5d0f72
2 changed files with 15 additions and 14 deletions

View File

@@ -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);
}

View File

@@ -183,11 +183,8 @@ public class HttpDslTests {
return IntegrationFlows
.from(Http.inboundGateway("/service")
.requestMapping(r -> r.params("name")))
.handle(Http.<MultiValueMap<String, String>>outboundGateway(m ->
UriComponentsBuilder.fromPath("/service/internal")
.queryParams(m.getPayload())
.build()
.toUri())
.handle(Http.<MultiValueMap<String, String>>outboundGateway("/service/internal?{params}")
.uriVariable("params", "payload")
.expectedResponseType(String.class),
e -> e.id("serviceInternalGateway"))
.get();