我正在使用 wso2esb4.7.0 我希望使用wso2esb添加2个数字,因为我已经编写了我的代理但它不起作用 我的代理是这样的
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Addition"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="Value1"
expression="//Value1/text()"
scope="default"
type="STRING"/>
<property name="Value2"
expression="//Value2/text()"
scope="default"
type="STRING"/>
<property name="Result"
expression="fn:sum(get-property('Value1'),get-property('Value2'))"
scope="default"
type="STRING"/>
<log>
<property name="RESULT" expression="get-property('Result')"/>
</log>
</inSequence>
<outSequence/>
</target>
<description/>
</proxy>
我记录了结果是错误的:
ERROR - SynapseXPath Evaluation of the XPath expression fn:sum(get-property('Value1'),get-property('Value2')) resulted in an error
org.jaxen.FunctionCallException: sum() requires one argument.
at org.jaxen.function.SumFunction.call(SumFunction.java:99)
at org.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java:177)
at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)
at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:674)
at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:213)
at org.jaxen.BaseXPath.evaluate(BaseXPath.java:172)
我也试过这个
<property name="Result"
expression="fn:sum(//Value1/text(),//Value2/text()))"
scope="default"
type="STRING"/>
Even this is also giving errors how would i reach to addition goal and my curl command like this
curl -v -H "Accept: application/json" -H "Content-Type:application/json" -H "ModifiedOn:0" -H "userid:-1899999899" -H "username:vikash|214057357158656" -H "password:gbadmin" -d '{"Value1":"2","Value2":"45"}' http://youtility2-desktop:8282/services/Addition
答案 0 :(得分:1)
您可以使用script mediator来实现此目的。首先,您可以像上面那样设置两个值。然后在脚本调解器中,您可以添加它们并设置为所需的属性。
使用此方法完成代理;
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Addition"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="Value1"
expression="//Value1/text()"
scope="default"
type="INTEGER"/>
<property name="Value2"
expression="//Value2/text()"
scope="default"
type="INTEGER"/>
<script language="js">
var value1 = mc.getProperty("Value1");
var value2 = mc.getProperty("Value2");
var result = value1 + value2;
mc.setProperty("Result", result);
</script>
<log>
<property name="RESULT" expression="get-property('Result')"/>
</log>
</inSequence>
<outSequence/>
</target>
<description/>
</proxy>
答案 1 :(得分:1)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Addition"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="Value1"
expression="//Value1/text()"
scope="default"
type="INTEGER"/>
<property name="Value2"
expression="//Value2/text()"
scope="default"
type="INTEGER"/>
<script language="js">
var value1 = parseInt(mc.getProperty("Value1"));
var value2 = parseInt(mc.getProperty("Value2"));
var result = value1 + value2;
mc.setProperty("Result", result);
</script>
<log>
<property name="RESULT" expression="get-property('Result')"/>
</log>
</inSequence>
<outSequence/>
</target>
<description/>
</proxy>