How to retrieve the properties in Synapse
How to use get-property( ) to access the property saved in registry.
To retrieve the
get -property( 'registry', String registryPath@propertyName)
How to access the property saved in registry using class mediator.
Step 1
package Mypackage;
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
import org.apache.synapse.registry.Registry;
import org.apache.synapse.config.Entry;
import java.util.Properties;
public class Sample extends AbstractMediator {
public boolean mediate(MessageContext synCtx) {
// TODO Implement your mediation logic here
String[] regParam = "gov:/tasks/EventAlertScheduledTask@lastAccessTime".split("@");
String regPath = regParam[0];
String propName = regParam[1];
Entry propEntry = synCtx.getConfiguration().getEntryDefinition(regPath);
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) {
System.out.println("Property value is : "+reqProperties.getProperty(propName));
}
}
}
}
return true;
}
}
Step 2
The following proxy service can be used to invoke the above class mediator.
<? xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="property_value"
expression="get-property('registry','gov:/tasks/EventAlertScheduledTask@lastAccessTime')"/>
<log>
<property name="Access using property mediator :"
expression="get-property('property_value')"/>
</log>
<class name="Mypackage.Sample"/>
<drop/>
</inSequence>
</target>
<description/>
</proxy>
No comments:
Post a Comment