You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSO2 ESB使用Iterator Mediator计算总和遇Axis服务查找错误

问题分析与修复方案

1. 端点路径错误导致服务找不到

错误信息ERROR {PassThroughNHttpGetProcessor} - Unable to find axis service for service name : studenttest/getsomme,是因为你把REST资源路径放到了WSO2的SOAP服务专用路径(/services/)下。WSO2 ESB中/services/后缀仅用于SOAP服务,REST服务应直接使用根路径访问。

修复端点配置

将call mediator中的端点URI修改为:

<http method="get" uri-template="http://ITMTNF3RRJSJ:8290/studenttest/getsomme?nom={uri.var.nom}">

2. Iterator未配置聚合导致请求挂起

你启用了sequential="TRUE"的Iterator,但未添加Aggregate Mediator聚合迭代后的上下文。ESB会一直等待聚合完成,导致Postman请求长时间无响应;同时提前调用的respond mediator也无法返回正确结果。

修复迭代与聚合逻辑

需在Iterator后添加Aggregate Mediator,并将respond移到聚合完成的序列中,确保流程结束后返回计算结果。

3. 数值计算逻辑错误

  • it_count和note均为STRING类型,直接相加会执行字符串拼接而非数值求和
  • Script中直接引用it_count会报错,需通过mc.getProperty获取属性值并转换为数值类型

修复计算逻辑

  1. 修改it_count的类型为INTEGER:
<property name="it_count" scope="operation" type="INTEGER" value="0"/>
  1. 修正Script Mediator的代码:
var note = parseInt(mc.getProperty('note'));
var currentTotal = parseInt(mc.getProperty('it_count'));
var totalnote = currentTotal + note;
mc.setProperty('it_count', totalnote.toString());

完整修复后的配置代码

<resource methods="GET" uri-template="/gettotal">
    <inSequence>
        <property expression="$url:nom" name="uri.var.nom" scope="default" type="STRING"/>
        <call>
            <endpoint>
                <http method="get" uri-template="http://ITMTNF3RRJSJ:8290/studenttest/getsomme?nom={uri.var.nom}">
                    <suspendOnFailure>
                        <initialDuration>-1</initialDuration>
                        <progressionFactor>-1</progressionFactor>
                        <maximumDuration>0</maximumDuration>
                    </suspendOnFailure>
                    <markForSuspension>
                        <retriesBeforeSuspension>0</retriesBeforeSuspension>
                    </markForSuspension>
                </http>
            </endpoint>
        </call>
        <!-- 初始化总和为整数类型 -->
        <property name="it_count" scope="operation" type="INTEGER" value="0"/>
        <iterate expression="//symbols/symbol" sequential="TRUE" id="sumIteration">
            <target>
                <sequence>
                    <property expression="json-eval($.note)" name="note" scope="default" type="STRING"/>
                    <script language="js"><![CDATA[
                        var note = parseInt(mc.getProperty('note'));
                        var currentTotal = parseInt(mc.getProperty('it_count'));
                        var totalnote = currentTotal + note;
                        mc.setProperty('it_count', totalnote.toString());
                    ]]></script>
                </sequence>
            </target>
        </iterate>
        <!-- 聚合迭代结果,完成后返回总和 -->
        <aggregate id="sumIteration">
            <completeCondition>
                <messageCount max="-1" min="-1"/>
            </completeCondition>
            <onComplete>
                <payloadFactory media-type="json">
                    <format>{"total_note": "$1"}</format>
                    <args>
                        <arg evaluator="xml" expression="$ctx:it_count"/>
                    </args>
                </payloadFactory>
                <respond/>
            </onComplete>
        </aggregate>
    </inSequence>
    <outSequence/>
    <faultSequence>
        <log level="full"/>
        <respond/>
    </faultSequence>
</resource>
</api>

额外注意事项

  • 确认后端studenttest/getsomme服务返回的响应结构与//symbols/symbol表达式匹配,否则Iterator不会执行任何迭代
  • 配置FaultSequence并记录日志,便于排查后续请求错误

内容的提问来源于stack exchange,提问作者rania ben salem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 04:35:30