繁体   English   中英

如何在 WSO2 EI 中读取 Class 调解器内的注册表项

[英]How to read registry items inside a Class Mediator in WSO2 EI

我们如何读取 Class 调解器中的注册表项? 我们有 100 多个使用 class 中介者的代理服务,并且要从注册表访问属性,我们必须在每个代理服务的 class 中介者之前添加一个属性中介者,如下所示:

<-- load the property via the Property Mediator -->
<property expression="get-property('registry','conf:someProp')" name="SOME_PROP" scope="default" type="STRING"/>

<-- then we access the "SOME_PROP" by using MessageContext#getProperty()
<class name="com.example.project.mediators.SomeMediator"/>

这将很难维持。 有没有更好的办法?

就是get-property function 执行此操作的方式,您可以在 class 中介体中复制此操作。

String[] regParam = key.split("@");
String regPath = null;
String propName = null;
if (regParam.length == 2) {
    regPath = regParam[0];
    propName = regParam[1];
} else if (regParam.length == 1) {
    regPath = regParam[0];
}

Entry propEntry = synCtx.getConfiguration().getEntryDefinition(regPath);
if (propEntry == null) {
    propEntry = new Entry();
    propEntry.setType(Entry.REMOTE_ENTRY);
    propEntry.setKey(key);
}
Registry registry = synCtx.getConfiguration().getRegistry();
if (registry != null) {
    registry.getResource(propEntry, new Properties());
    if (propName != null) {
        Properties reqProperties = propEntry.getEntryProperties();
        if (reqProperties != null) {
            if (reqProperties.get(propName) != null) {
                return reqProperties.getProperty(propName);
            }
        }
    } else if (propEntry.getValue() != null) {
        if (propEntry.getValue() instanceof OMText) {
            return ((OMText) propEntry.getValue()).getText();
        }
        return propEntry.getValue().toString();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM