1

我正在使用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
4

2 回答 2

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 = 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>
于 2013-10-23T11:25:38.317 回答
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>
于 2013-10-23T12:05:18.047 回答