Raaghu
Raaghu

Reputation: 473

How to run Custom application in WSO2 ESB

I have wso2 ESB as one of the ESB option to develop/deploy application, but I don't see any documentation which explains how to deploy a normal (not web, not ws...) main class in wso2 ESB and see the status of the same.

Can anyone suggest how to run some simple java application -- like a file reader and see/monitor the application status/log in ESB ?

Appreciate any help.

Thanks and Regards Raaghu.K

Upvotes: 0

Views: 520

Answers (2)

vibol rim
vibol rim

Reputation: 11

You can write your own custom mediation and extends AbstractMediator class on your custom class

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

}

when you call java on your xml flow:

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

Upvotes: 0

Jean-Michel
Jean-Michel

Reputation: 5946

You can execute your custom java code in WSO2ESB using "class" mediator and calling your custom class, see https://docs.wso2.com/display/ESB481/Class+Mediator and https://docs.wso2.com/display/ESB481/Writing+a+WSO2+ESB+Mediator

Upvotes: 1

Related Questions