How to call Class mediator property value inside another mediator Class

扶醉桌前 提交于 2020-01-07 04:43:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!