如何在另一个mediator类中调用Class mediator属性值

时间:2017-07-11 13:22:51

标签: wso2 wso2esb

我需要在另一个介体类

中调用一些Class mediator属性值

这是我的SurepayMediator课程

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;
   }
}

我需要在AddSubscription类和CancelSubscription类中调用firstValue

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 个答案:

答案 0 :(得分:1)

似乎只有" SurepayMediator"应该是一个班级调解员(你需要从调解中调用的唯一一个)。

更改类AddSubscription和CancelSubscription,以便它们不会扩展AbstractMediator。

最终,重命名'调解'方法并使用MessageContext参数从SurepayMediator调用它:您将获得" firstValue" property调用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;
  }
}