如何 运行 WSO2 ESB 中的自定义应用程序
How to run Custom application in WSO2 ESB
我将 wso2 ESB 作为 develop/deploy 应用程序的 ESB 选项之一,但我没有看到任何说明如何部署普通(不是网络,不是 ws...)main class 在 wso2 ESB 中查看相同的状态。
任何人都可以建议如何 运行 一些简单的 java 应用程序——例如文件 reader 和 see/monitor ESB 中的应用程序 status/log 吗?
感谢任何帮助。
感谢和问候
Raaghu.K
您可以使用 "class" 调解器在 WSO2ESB 中执行您的自定义 java 代码并调用您的自定义 class,请参阅 https://docs.wso2.com/display/ESB481/Class+Mediator and https://docs.wso2.com/display/ESB481/Writing+a+WSO2+ESB+Mediator
您可以编写自己的自定义中介并在您的自定义 class
上扩展 AbstractMediator 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;
}
}
当您在 xml 流程上调用 java 时:
<class name="yourclass_package.DiscountQuoteMediator">
<property name="discountFactor" value="10"/>
<property name="bonusFor" value="5"/>
</class>
我将 wso2 ESB 作为 develop/deploy 应用程序的 ESB 选项之一,但我没有看到任何说明如何部署普通(不是网络,不是 ws...)main class 在 wso2 ESB 中查看相同的状态。
任何人都可以建议如何 运行 一些简单的 java 应用程序——例如文件 reader 和 see/monitor ESB 中的应用程序 status/log 吗?
感谢任何帮助。
感谢和问候 Raaghu.K
您可以使用 "class" 调解器在 WSO2ESB 中执行您的自定义 java 代码并调用您的自定义 class,请参阅 https://docs.wso2.com/display/ESB481/Class+Mediator and https://docs.wso2.com/display/ESB481/Writing+a+WSO2+ESB+Mediator
您可以编写自己的自定义中介并在您的自定义 class
上扩展 AbstractMediator classpublic 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>