apache-synapseuritemplatewso2-esb

Why is Synapse not expanding a variable in a uri-template?


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?


Solution

  • 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"/>