How to access system property from WSO2 ESB and Registry

丶灬走出姿态 提交于 2019-12-01 13:24:36

问题


My WSO2 ESB proxy service references an endpoint which is located at different URLs in various environments - DEV, TEST, PROD. According to the WSO2 documentation, I need to store the endpoint definition in the Governance Registry and modify the URL in endpoint XML file in each environment. That might work fine for the organizations with 1 or 2 proxies, but becomes a significant overhead for a 10+ proxies.

Another scenario is when I need to read certain environment-specific properties in my ESB sequence.

Is there a way to define a bunch of properties in the external *.properties file and then read them within the ESB and Registry definitions?


回答1:


You can access system properties inside ESB sequences/proxy services using the script mediator as follows;

    <script language="js">mc.setProperty("file.separator",java.lang.System.getProperty("file.separator"));</script>
    <log level="custom">
       <property name="file.separator" expression="get-property('file.separator')"/>
    </log>

Here "file.separator" property is set as the property in the message context inside the script mediator and it can be used in subsequent mediators.

You also can access properties defined in a file in ESB registry. For example if you have a file in configuration registry (test.xml) with the following content,

<a>Helloo<b>World</b></a>

The text element "World" in <b> can be accessed using property mediator as follows,

<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM"/>
<log level="custom">
      <property name="test.b" expression="$ctx:test//b"/>
</log>



回答2:


here is a blog post on how to access registry resources from a classmeditor1. You can access any resources as mentioned in the post and do modifications.

Likewise you can keep the external properties file and read that from the classmeditor and set all properties in synapse message context using class meditaor.



来源:https://stackoverflow.com/questions/15210972/how-to-access-system-property-from-wso2-esb-and-registry

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