Spring Integration 6.x http 出站网关 http uri 变量表达式不评估应用程序属性

问题描述 投票:0回答:1

我们在 Spring 集成应用程序中使用基于 xml 的配置。代码正在从 Spring Integration v5.x 升级到 v6.x。由此我们可以看到,在使用 http 出站网关时 -> http uri 变量并未通过之前有效的表达式评估应用程序属性。这会导致错误 - URI 不是绝对的。

以下是应用程序配置示例:

<int-http:outbound-gateway id="sampleGateway"
    request-channel="jsonInputChannel"
    url="{url}/call-some-api"
    http-method="POST"
    expected-response-type="java.lang.String"
    charset="UTF-8"
    reply-timeout="30000"
    reply-channel="nullChannel">
    <int-http:uri-variable name="url" expression="${sample.api.url}"/>
</int-http:outbound-gateway>

这里的sample.api.url是在application.properties中定义的,用于环境特定的基本url。

${sample.api.url} 应从应用程序属性解析,并且 url="{url}/call-some-api" 应为网关构造正确的 url。这适用于 v5.x,也应该适用于 6.x。没有关于此能力被删除的文档。

我们使用日志记录适配器来确保表达式评估应用程序属性并具有适当的值。

spring spring-integration spring-integration-http
1个回答
0
投票

感谢您提供示例项目。

调试后我发现属性占位符已正确解析。 但到了

RestTemplate.execute()
,就有这样的逻辑:

URI url = getUriTemplateHandler().expand(uriTemplate, uriVariables);

结果是这样的:

https%3A%2F%2Fgoogle.com%2Fsearch/call-some-api

因此,所有这些非标准符号(

:
/
)都被编码了。

您可以将

encoding-mode="NONE"
添加到
<int-http:outbound-gateway>
或考虑使用
url-expression
代替
url

在文档中查看更多信息:https://docs.spring.io/spring-integration/reference/http/namespace.html#http-uri-encoding

© www.soinside.com 2019 - 2024. All rights reserved.