[英]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.我将 wso2 ESB 作为开发/部署应用程序的 ESB 选项之一,但我没有看到任何说明如何在 wso2 ESB 中部署普通(不是 web,不是 ws...)主类并查看状态的文档一样的。
Can anyone suggest how to run some simple java application -- like a file reader and see/monitor the application status/log in ESB ?任何人都可以建议如何运行一些简单的 Java 应用程序——比如文件阅读器,并在 ESB 中查看/监控应用程序状态/日志?
Appreciate any help.感谢任何帮助。
Thanks and Regards Raaghu.K感谢和问候 Raaghu.K
您可以使用“类”中介并调用您的自定义类在 WSO2ESB 中执行您的自定义 Java 代码,请参阅https://docs.wso2.com/display/ESB481/Class+Mediator和https://docs.wso2.com/display /ESB481/写+a+WSO2+ESB+中介
You can write your own custom mediation and extends AbstractMediator class on your custom class您可以编写自己的自定义中介并在自定义类上扩展 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;
}
} }
when you call java on your xml flow:当您在 xml 流上调用 java 时:
<class name="yourclass_package.DiscountQuoteMediator">
<property name="discountFactor" value="10"/>
<property name="bonusFor" value="5"/>
</class>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.