WSO2迭代介体为WSO2 EI中的每个迭代迭代相同的元素

时间:2020-04-29 15:01:05

标签: iterator wso2 aggregate wso2esb wso2ei

我正在使用WSO2迭代中介器将多个记录一对一地添加到Salesforce ,并且所有来自Salesforce的响应都使用汇总来汇总。到此为止一切正常。 聚合响应包含多个json对象(每个元素都是不同的元素),我需要获取每个json对象元素,并将主要详细信息(例如Email,MobilePhone,LeadId,SF ErrorCode等)跟踪到数据库表中。 为此,我再次使用Iterator来拆分聚合响应。 对于每次迭代,它都会打印相同的json元素 。在这种情况下有人可以帮助我吗?

汇总响应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject xmlns
="http://ws.apache.org/ns/synapse"><jsonValue xmlns="">"{\"transactionId\":null,\"timestamp\":\"2020-04-28 14:21:01\",\"OpportunityId\":\"0065500000Fz6EdAAJ\",\"message\":\"Insert/
Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvaJ8EAJ\"},\"Company\":\"N/A\",\"Email\":\"dunleavy2010@hotmail
.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Brendan\",\"LastName\":\"Dunleavy\",\"Id\":\"00Q5500000AvaJ8EAJ\",\"MobilePhone\":
\"+61 449 819 834\"},\"errorCode\":\"200\",\"appraisalId\":null}"</jsonValue><jsonValue xmlns="">"{\"transactionId\":null,\"timestamp\":\"2020-04-28 14:21:01\",\"OpportunityId\":\"
0065500000Fz6EiAAJ\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvaJ3EAJ\"},\"Company\
":\"N/A\",\"Email\":\"steveross01@bigpond.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV Facebook - Book a Test Drive\",\"FirstName\":\"Stephen\",\"LastName\":\"Ross\",\"
Id\":\"00Q5500000AvaJ3EAJ\",\"MobilePhone\":\"+61 414 404 774\"},\"errorCode\":\"200\",\"appraisalId\":null}"</jsonValue><jsonValue xmlns="">"{\"transactionId\":null,\"timestamp\":
\"2020-04-28 14:21:04\",\"OpportunityId\":\"0065500000Fz6EnAAJ\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/so
bjects/Lead/00Q5500000AvaJDEAZ\"},\"Company\":\"N/A\",\"Email\":\"jaxonstevens18@gmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\
":\"Jaxon\",\"LastName\":\"Stevens\",\"Id\":\"00Q5500000AvaJDEAZ\",\"MobilePhone\":\"+61 423 927 100\"},\"errorCode\":\"200\",\"appraisalId\":null}"</jsonValue></jsonObject></soape
nv:Body></soapenv:Envelope>

代理代码:

<proxy name="VBReadFromEmailBody" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
    <inSequence>
                <iterate expression="//jsonArray/jsonElement" id="LDVid" sequential="true">
                    <target>
                        <sequence>
                            <!-- Each jsonElement is pushed to SalesForce  -->
                            <sequence description="VBEmail_LDVNonQualifiedLead_Sequence" key="VBEmail_LDVNonQualifiedLead_Sequence"/>
                        </sequence>
                    </target>
                </iterate>
                <property name="Aggregated_Responses" scope="default">
                    <jsonObject/>
                </property>
                <aggregate id="LDVid">
                    <completeCondition>
                        <messageCount max="-1" min="-1"/>
                    </completeCondition>
                    <onComplete enclosingElementProperty="Aggregated_Responses" expression="$body/*[1]" xmlns:ns="http://org.apache.synapse/xsd">
                        <loopback/>
                    </onComplete>
                </aggregate>
     </inSequence>
    <outSequence>
        <log level="custom">
            <property name="======OUTSEQUENCE=======" value="CALLED"/>
        </log>
        <!-- Log to check aggregatedresponse  -->
        <log level="full"/>
                <property name="messageType" scope="axis2" type="STRING" value="application/json"/>
                <iterate continueParent="true" expression="//jsonValue" sequential="true">
                    <target>
                        <sequence>
                            <property expression="json-eval($)" name="jsonString" scope="default" type="STRING"/>
                            <script language="js"><![CDATA[var log = mc.getServiceLog();        
var payload = mc.getProperty('jsonString').toString();log.info("script payload::::" + payload); payloadRemoveSlash = payload.replace('\\', '').replace('"{','{').replace('}"','}'); mc.setProperty('payloadRemoveSlash',payloadRemoveSlash);]]></script>
                        <log level="custom">
                          <property name=":: Body Inside payloadRemoveSlash::" expression="$ctx:payloadRemoveSlash"/>
                        </log>

                        </sequence>
                    </target>
                </iterate>
 </outSequence>
    <faultSequence>
        <log level="custom">
            <property description="ERROR_CODE" name="ERROR_CODE" scope="default" type="STRING" expression="get-property('ERROR_CODE')"/>
            <property description="ERROR_MESSAGE" name="ERROR_MESSAGE" scope="default" type="STRING" expression="get-property('ERROR_MESSAGE')/>
        </log>

     </faultSequence>
</target>

日志详细信息:

[2020-04-28 22:21:53,160] []  INFO - CommonScriptMessageContext script payload::::"{\"transactionId\":null,\"timestamp\":\"2020-04-29 02:51:50\",\"OpportunityId\":\"0065500000FzDxE
AAV\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AveQuEAJ\"},\"Company\":\"N/A\",\"Ema
il\":\"dunleavy2010@hotmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Brendan\",\"LastName\":\"Dunleavy\",\"Id\":\"00Q5500000
AveQuEAJ\",\"MobilePhone\":\"+61 449 819 834\"},\"errorCode\":\"200\",\"appraisalId\":null}"
[2020-04-28 22:21:53,161] []  INFO - LogMediator :: Body Inside payloadRemoveSlash:: = {"transactionId":null,"timestamp":"2020-04-29 02:51:50","OpportunityId":"0065500000FzDxEAAV",
"message":"Insert/Update success","Lead":{"attributes":{"type":"Lead","url":"/services/data/v48.0/sobjects/Lead/00Q5500000AveQuEAJ"},"Company":"N/A","Email":"dunleavy2010@hotmail.c
om","Lead_Type__c":"Internet","LeadSource":"LDV i-Motor - Get a Quote","FirstName":"Brendan","LastName":"Dunleavy","Id":"00Q5500000AveQuEAJ","MobilePhone":"+61 449 819 834"},"error
Code":"200","appraisalId":null}
[2020-04-28 22:21:53,160] []  INFO - CommonScriptMessageContext script payload::::"{\"transactionId\":null,\"timestamp\":\"2020-04-29 02:51:50\",\"OpportunityId\":\"0065500000FzDxE
AAV\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AveQuEAJ\"},\"Company\":\"N/A\",\"Ema
il\":\"dunleavy2010@hotmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Brendan\",\"LastName\":\"Dunleavy\",\"Id\":\"00Q5500000
AveQuEAJ\",\"MobilePhone\":\"+61 449 819 834\"},\"errorCode\":\"200\",\"appraisalId\":null}"
[2020-04-28 22:21:53,171] []  INFO - LogMediator :: Body Inside payloadRemoveSlash:: = {"transactionId":null,"timestamp":"2020-04-29 02:51:50","OpportunityId":"0065500000FzDxEAAV",
"message":"Insert/Update success","Lead":{"attributes":{"type":"Lead","url":"/services/data/v48.0/sobjects/Lead/00Q5500000AveQuEAJ"},"Company":"N/A","Email":"dunleavy2010@hotmail.c
om","Lead_Type__c":"Internet","LeadSource":"LDV i-Motor - Get a Quote","FirstName":"Brendan","LastName":"Dunleavy","Id":"00Q5500000AveQuEAJ","MobilePhone":"+61 449 819 834"},"error
Code":"200","appraisalId":null}
[2020-04-28 22:21:53,176] []  INFO - CommonScriptMessageContext script payload::::"{\"transactionId\":null,\"timestamp\":\"2020-04-29 02:51:50\",\"OpportunityId\":\"0065500000FzDxE
AAV\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AveQuEAJ\"},\"Company\":\"N/A\",\"Ema
il\":\"dunleavy2010@hotmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Brendan\",\"LastName\":\"Dunleavy\",\"Id\":\"00Q5500000
AveQuEAJ\",\"MobilePhone\":\"+61 449 819 834\"},\"errorCode\":\"200\",\"appraisalId\":null}"
[2020-04-28 22:21:53,179] []  INFO - LogMediator :: Body Inside payloadRemoveSlash:: = {"transactionId":null,"timestamp":"2020-04-29 02:51:50","OpportunityId":"0065500000FzDxEAAV",
"message":"Insert/Update success","Lead":{"attributes":{"type":"Lead","url":"/services/data/v48.0/sobjects/Lead/00Q5500000AveQuEAJ"},"Company":"N/A","Email":"dunleavy2010@hotmail.c
om","Lead_Type__c":"Internet","LeadSource":"LDV i-Motor - Get a Quote","FirstName":"Brendan","LastName":"Dunleavy","Id":"00Q5500000AveQuEAJ","MobilePhone":"+61 449 819 834"},"error
Code":"200","appraisalId":null}

注意:

  1. 汇总响应包含3个不同的json对象(请参阅:汇总响应
  2. 但是迭代器中的脚本会打印相同的json元素(即dunleavy2010@hotmail.com)3次(请参阅:日志详细信息

请看看并给我解决方案吗?

0 个答案:

没有答案