Reputation: 1225
Write now i have a situation. I am writing a custom mediator which implements mediate function that returns boolean. But instead i want to return other datatype as well. i am trying to achieve thsi by writing a custom code to add two numbers and return the result. but i am not able to figure out, how i can return integer instead of boolean. Please provide me an example related to this situation. I have written the code inside custom class mediator as:
public boolean mediate(MessageContext messageContext) {
System.out.println("Checkpoint1: OpenPublication.mediate()");
if (getChanneluri() != null && !getChanneluri().isEmpty()) {
messageContext.setProperty("SessionID", UUID.randomUUID().toString());
System.out.println("Checkpoint2: SessionID Property set");
synapseConfig = messageContext.getConfiguration();
System.out.println("Checkpoint3: messageContextSessionID = " + messageContext.getProperty("SessionID"));
System.out.println("Checkpoint3: messageID = " + messageContext.getMessageID());
}
return false;
}
Now i want to retreive this property value of "SessionID" in my sequence. How to do this. Thanks in advance.
Upvotes: 1
Views: 1180
Reputation: 344
AFAIK you cannot make a class mediator return anything other than a boolean value. A class mediator, when extending the AbstractMediator
class, has to implement the boolean mediate method; as you pointed out.
You may try setting properties to the Synapse message context to pass values between different mediators.
For example:
public class myMediator extends AbstractMediator {
private String property1 = "aProperty";
private String property2;
public boolean mediate(MessageContext messageContext) {
messageContext.setProperty("MyProperty", property1);
property2 = (String) messageContext.getProperty("MyProperty");
return true;
}
In the above example, the two String variables will end up having the same value "aProperty". In this manner, you can expose any type of object to the Synapse message context and retrieve it elsewhere.
Upvotes: 4