问题
I need to call some Class mediator property value inside another mediator Class
This is my SurepayMediator class
package esb.cellcard.billing;
public class SurepayMediator extends AbstractMediator{
public boolean mediate(MessageContext context) {
context.setProperty("firstValue", "Run Fast");
if(something){
//Here I need to execute AddSubscription class
}
else {
//Here I need to execute CancleSubscription class
}
return true;
}
}
I need to call this firstValue inside the AddSubscription class and CancelSubscription class
AddSubscription
package esb.cellcard.billing;
public class AddSubscription extends AbstractMediator{
SurepayMediator sm = new SurepayMediator();
public boolean mediate(MessageContext context) {
//I need to call that firstValue in here
return true;
}
}
CancelSubscription
package esb.cellcard.billing;
public class CancelSubscription extends AbstractMediator{
SurepayMediator sm = new SurepayMediator();
public boolean mediate(MessageContext context) {
//I need to call that firstValue in here
return true;
}
}
回答1:
It seems that only "SurepayMediator" should be a class mediator (the only one you need to call from your mediation).
Change classes AddSubscription and CancelSubscription so that they do not extends AbstractMediator.
Eventually, rename 'mediate' method and call it from SurepayMediator with the MessageContext parameter : you will get "firstValue" property's value calling context.getProperty("firstValue");
if(something){
addSubscription.add(context);
}
.
public class AddSubscription{
public boolean add(MessageContext context) {
//I need to call that firstValue in here
String value = context.getProperty("firstValue");
...
return true;
}
}
来源:https://stackoverflow.com/questions/45035829/how-to-call-class-mediator-property-value-inside-another-mediator-class