如何在WSO2 ESB中运行自定义应用程序

时间:2015-08-05 11:30:51

标签: java wso2 wso2esb

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

有人可以建议如何运行一些简单的java应用程序 - 比如文件阅读器,并查看/监控ESB中的应用程序状态/日志吗?

感谢任何帮助。

谢谢和问候 Raaghu.K

2 个答案:

答案 0 :(得分:1)

您可以使用" class"在WSO2ESB中执行自定义Java代码。调解员并调用自定义类,请参阅https://docs.wso2.com/display/ESB481/Class+Mediatorhttps://docs.wso2.com/display/ESB481/Writing+a+WSO2+ESB+Mediator

答案 1 :(得分:0)

您可以编写自己的自定义中介并在自定义类上扩展 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>