Is there any replace function in wso2esb?

耗尽温柔 提交于 2019-12-25 07:31:53

问题


i have string like htt://api.orgsync.com/orgs/{orgId}/events?key={orgSyncKey}&startdate={startDate}&enddate={endDate}

i need to replace {orgId} with 1234, {orgSyncKey} with 2345 , {startDate} with 12/01/2004 and {endDate} with 15/02/2005.

is there any replace kind of function in wso2esb?


回答1:


replace is a function that comes with XPath 2.0. To enable XPath 2.0 functions uncomment the following entry in the synapse.properties file which is located at $ESB_HOME/repository/conf directory.

synapse.xpath.dom.failover.enabled=true

then you have to specify the mediator as follows,

<property
expression="fn:replace('your_original_string', 'pattern_to_replace', 'your_new_string')"
name="NEWSTRING" scope="default" type="STRING"
xmlns:fn="http://www.w3.org/2005/xpath-functions" />



回答2:


See the example mentioned at https://docs.wso2.com/display/ESB480/HTTP+Endpoint#HTTPEndpoint-XMLConfigurationXMLConfiguration

You can create property mediators with keys and values which you want to replace in the url. Then you can call send mediator which has an endpoint url with those placeholders.




回答3:


You can use xpath replace function which is available from XPath 2.0. First you need to enable xpath 2.0 on esb. For that set the following property

synapse.xpath.dom.failover.enabled=true

at [ESB_HOME]/repository/conf/synapse.properties file.

Assuming the original string is set to a property as below.

<property name="OriginalString"
value="htt://api.orgsync.com/orgs/{orgId}/events?key={orgSyncKey}&startdate={startDate}&enddate={endDate}"
scope="default" type="STRING"/>

You can include the following to replace the required parts of the string using property mediator.

<property name="ReplacedString" expression="fn:replace(fn:replace(fn:replace((fn:replace($ctx:OriginalString , '\{orgId\}', '1234')), '\{orgSyncKey\}', '2345'), '\{startDate\}' ,'12/01/2004'), '\{endDate\}' , '15/02/2005')" scope="default" type="STRING" xmlns:fn="http://www.w3.org/2005/xpath-functions" />



回答4:


If you are not in to using XPATH 2.0, you can use the script mediator and write a javascript script for the string replace.



来源:https://stackoverflow.com/questions/40148230/is-there-any-replace-function-in-wso2esb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!