【问题标题】:How to run Custom application in WSO2 ESB如何在 WSO2 ESB 中运行自定义应用程序
【发布时间】:2015-08-05 11:30:50
【问题描述】:

我将 wso2 ESB 作为开发/部署应用程序的 ESB 选项之一,但我没有看到任何说明如何在 wso2 ESB 中部署普通(不是 Web,不是 ws...)主类的文档和查看相同的状态。

谁能建议如何运行一些简单的 java 应用程序——比如文件阅读器并在 ESB 中查看/监控应用程序状态/日志?

感谢任何帮助。

感谢和问候 拉古.K

【问题讨论】:

    标签: java wso2 wso2esb


    【解决方案1】:

    您可以在 WSO2ESB 中使用“类”中介并调用您的自定义类来执行您的自定义 java 代码,请参阅 https://docs.wso2.com/display/ESB481/Class+Mediatorhttps://docs.wso2.com/display/ESB481/Writing+a+WSO2+ESB+Mediator

    【讨论】:

    • 感谢您的回复。查看链接,我想它会回答我的问题
    【解决方案2】:

    您可以编写自己的自定义中介并在自定义类上扩展 AbstractMediator 类

    public class DiscountQuoteMediator extends AbstractMediator {
    
    private static final Log log = LogFactory.getLog(DiscountQuoteMediator.class);
    private String discountFactor = "10";
    private String bonusFor = "10";
    private int bonusCount = 0;
    public DiscountQuoteMediator() {}
    public boolean mediate(MessageContext mc) {
    
        String price = mc.getEnvelope().getBody().getFirstElement().getFirstElement().
                getFirstChildWithName(new QName("http://services.samples/xsd", "last")).getText();
    
        //converting String properties into integers
        int discount = Integer.parseInt(discountFactor);
        int bonusNo = Integer.parseInt(bonusFor);
        double currentPrice = Double.parseDouble(price);
    
        //discounting factor is deducted from current price form every response
        Double lastPrice = new Double(currentPrice - currentPrice * discount / 100);
    
        //Special discount of 5% offers for the first responses as set in the bonusFor property
        if (bonusCount <= bonusNo) {
            lastPrice = new Double(lastPrice.doubleValue() - lastPrice.doubleValue() * 0.05);
            bonusCount++;
        }
    
        String discountedPrice = lastPrice.toString();
    
        mc.getEnvelope().getBody().getFirstElement().getFirstElement().getFirstChildWithName
                (new QName("http://services.samples/xsd", "last")).setText(discountedPrice);
    
        System.out.println("Quote value discounted.");
        System.out.println("Original price: " + price);
        System.out.println("Discounted price: " + discountedPrice);
    
        return true;
    }
    
    public String getType() {
        return null;
    }
    
    public void setTraceState(int traceState) {
        traceState = 0;
    }
    
    public int getTraceState() {
        return 0;
    }
    
    public void setDiscountFactor(String discount) {
        discountFactor = discount;
    }
    
    public String getDiscountFactor() {
        return discountFactor;
    }
    
    public void setBonusFor(String bonus) {
        bonusFor = bonus;
    }
    
    public String getBonusFor() {
        return bonusFor;
    }
    

    }

    当您在 xml 流上调用 java 时:

     <class name="yourclass_package.DiscountQuoteMediator">
                <property name="discountFactor" value="10"/>
                <property name="bonusFor" value="5"/>
            </class>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-20
      • 2012-09-09
      相关资源
      最近更新 更多