[英]How to run Custom application in WSO2 ESB
我將 wso2 ESB 作為開發/部署應用程序的 ESB 選項之一,但我沒有看到任何說明如何在 wso2 ESB 中部署普通(不是 web,不是 ws...)主類並查看狀態的文檔一樣的。
任何人都可以建議如何運行一些簡單的 Java 應用程序——比如文件閱讀器,並在 ESB 中查看/監控應用程序狀態/日志?
感謝任何幫助。
感謝和問候 Raaghu.K
您可以使用“類”中介並調用您的自定義類在 WSO2ESB 中執行您的自定義 Java 代碼,請參閱https://docs.wso2.com/display/ESB481/Class+Mediator和https://docs.wso2.com/display /ESB481/寫+a+WSO2+ESB+中介
您可以編寫自己的自定義中介並在自定義類上擴展 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.