How can we read registry items inside a Class Mediator? We have 100+ proxy services that use a class mediator, and to access a property from a registry, we have to add a property mediator before our class mediator to each proxy service, like this:
<-- 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"/>
This would be difficult to maintain. Is there a better way?
This is how the get-property
function does this, you can replicate this in the class mediator.
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.