为什么Synapse不在uri

编程入门 行业动态 更新时间:2024-10-27 07:19:58
为什么Synapse不在uri-template中扩展变量?(Why is Synapse not expanding a variable in a uri-template?)

我有一个WSO2 ESB 4.8.1序列,它将消息发送到定义为的HTTP端点

<http method="get" uri-template="http://host.example.com/v1/entity/{uri.var.id}/attributes/foo">
 

该属性以前由XPath设置:

<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.id" expression="//id" scope="default" type="STRING" />
 

有时它会调用正确的URL,有时它会直接调用http://host.example.com/v1/entity/{uri.var.id}/attributes/foo而不替换变量。 为什么?

I have a WSO2 ESB 4.8.1 sequence which sends a message to an HTTP endpoint defined as

<http method="get" uri-template="http://host.example.com/v1/entity/{uri.var.id}/attributes/foo">
 

The property is previously set by XPath:

<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.id" expression="//id" scope="default" type="STRING" />
 

Sometimes it invokes the correct URL, and sometimes it literally calls http://host.example.com/v1/entity/{uri.var.id}/attributes/foo without substituting the variable. Why?

最满意答案

可能有其他可能的原因,但似乎是我的问题的原因是逃避。 如果ID是纯字母数字字符串,那么它可以工作,但如果它包含空格字符,则它不会被替换。 记录错误消息并转到故障序列会更有帮助,但这是用WSO2引发的。

我发现的修复是通过编辑repository/conf/synapse.properties来启用XPath 2.0并取消注释synapse.xpath.dom.failover.enabled=true ; 然后使用XPath 2.0的转义功能:

<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.id" expression="encode-for-uri(//id)" scope="default" type="STRING"/>

There may be other possible reasons, but what seems to be the cause of my problems is escaping. If the ID is a pure alphanumeric string then it works, but if it includes a space character then it isn't substituted. It would be more helpful to log an error message and go to the fault sequence, but that's something to raise with WSO2.

The fix which I've found is to enable XPath 2.0 by editing repository/conf/synapse.properties and uncommenting synapse.xpath.dom.failover.enabled=true ; and then to use XPath 2.0's escaping functionality:

<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.id" expression="encode-for-uri(//id)" scope="default" type="STRING"/>

                    
                     
          

更多推荐

本文发布于:2023-08-04 15:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417839.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Synapse   uri

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!