【问题标题】:How to read a property injected from file.properties in WSO2 - micro integrator?如何读取从 WSO2 中的 file.properties 注入的属性 - 微积分器?
【发布时间】:2021-02-16 18:36:17
【问题描述】:

有没有办法使用 property mediator 从 wso2 中的文件中读取属性?

我从 file.properties 注入地址 uri,并将文件路径作为 -Dproperties.file.path 参数传递给启动脚本,它只能使用地址端点的 uri 属性解析变量语法 $FILE:variableName 如下:

                <call>
                    <endpoint>
                        <address uri="$FILE:uploadPath">
                            <suspendOnFailure>
                                <initialDuration>-1</initialDuration>
                                <progressionFactor>1</progressionFactor>
                            </suspendOnFailure>
                            <markForSuspension>
                                <retriesBeforeSuspension>0</retriesBeforeSuspension>
                            </markForSuspension>
                        </address>
                    </endpoint>
                </call>

           

但我也需要使用相同的属性,做一个小的转换并将它传递给一个类中介,

我已经尝试了以下方法,但它们都不起作用。

<log level="custom">
  <property expression="$FILE:uploadPath" name="file-path-1"/>
  <property expression="$ctx:uploadPath" name="file-path-2"/>
  <property expression="$axis2:uploadPath" name="file-path-3"/>
  <property expression="$trp:uploadPath" name="file-path-4"/>
  <property expression="$axis2:POST_TO_URI" name="POST_TO_URI"/>
</log>

以下是我正在使用的操作系统和工具的版本。 操作系统:Mac os catalina, WSO2:微积分器 1.2.0,Integration sutdio - 7.1.0

【问题讨论】:

    标签: wso2


    【解决方案1】:

    前段时间,我正在努力解决类似的问题,尝试在 dockered microintegrator 中使用 $FILE:。检查源代码后,我意识到在属性调解器中没有实现读取,并且仅在端点中有效……我相信这是出于安全原因?

    但是,有一些解决方法,我不是很喜欢。您可以使用 Property 和 ScriptMediator:

    <property xmlns:ns="http://org.apache.synapse/xsd" name="propPath" expression="get-property('system','properties.file.path')" scope="default" type="STRING"/>
    <script language="js"><![CDATA[
       var path = java.nio.file.Paths.get(mc.getProperty('propPath'));
       var fromFile = java.nio.file.Files.readAllLines(path, java.nio.charset.StandardCharsets.UTF_8);
    
       mc.setProperty('line1',fromFile.get(0).toString());
       mc.setProperty('line2',fromFile.get(1).toString());
    ]]></script>
    

    当然你得到了完整的线路,但是如果你调整这个 ScriptMediator,你可以在单独的属性中拥有你想要的东西。

    【讨论】:

      猜你喜欢
      • 2022-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多