在 WSO2 EI/ESB 中处理脚本中介内的有效负载

To process payload inside script mediator in WSO2 EI/ESB

我有如下有效负载。 我需要在脚本中介器中获取整个有效负载并对该有效负载执行斜杠删除操作。我无法获得完整的有效负载,只能在脚本中介程序中获得一个 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 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>
                        <enrich>
            <source clone="true" type="inline">
                <test xmlns="">abc</test>
            </source>
            <target type="body"/>
        </enrich>
        <payloadFactory description="Form Salesforce Request" media-type="json">
            <format></format>
            <args>
                <arg evaluator="xml" expression="get-property('payloadRemoveSlash')"/>
            </args>
        </payloadFactory>
                    <log level="custom">
                          <property name="After Enrich" expression="json-eval($.)"/>
                        </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>

线路日志 - 1:

[2020-04-28 14:48:25,594] []  INFO - LogMediator LogText = Salesforce Request Uniqueidentifier:17132e6366d3d561,**, ======SF RequestPayload====== = {"getLead":{"Company":"N/A","Ema
    il":"dunleavy2010@hotmail.com","Lead_Type__c":"Internet","LeadSource":"LDV i-Motor - Get a Quote","FirstName":"Brendan","LastName":"Dunleavy","MobilePhone":"+61 449 819 834"},"getT
    rade":[]}
    [2020-04-28 14:48:25,596] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "POST /services/apexrest/LeadIntegrationAPIHandler HTTP/1.1[\r][\n]"
    [2020-04-28 14:48:25,596] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Authorization: Bearer  00D550000000fgk!AR0AQALfr1npMosFbJQ.zn17zoWY2WnRXuFTNtBCPnkmo_WaCG9uvQJ68D.l.5NPI
    dIg0AUsv0yHmucn8ikq6inf74ePBFu3[\r][\n]"
    [2020-04-28 14:48:25,596] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "X-Frame-Options: SAMEORIGIN[\r][\n]"
    [2020-04-28 14:48:25,597] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Alt-Svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q04
    8=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,h3-T050=":443"; ma=2592000[\r][\n]"
    [2020-04-28 14:48:25,599] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Cache-Control: private, max-age=0, must-revalidate, no-transform[\r][\n]"
    [2020-04-28 14:48:25,600] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "ETag: "hicYA7eHlMWnqap7I2cx6HOrcNI/vfNEq8c2pcFW4FNGRTeNcH6yFic"[\r][\n]"
    [2020-04-28 14:48:25,600] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "X-Content-Type-Options: nosniff[\r][\n]"
    [2020-04-28 14:48:25,600] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Content-Security-Policy: frame-ancestors 'self'[\r][\n]"
    [2020-04-28 14:48:25,601] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Vary: Origin[\r][\n]"
    [2020-04-28 14:48:25,601] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Vary: X-Origin[\r][\n]"
    [2020-04-28 14:48:25,602] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Expires: Tue, 28 Apr 2020 09:18:05 GMT[\r][\n]"
    [2020-04-28 14:48:25,602] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "X-XSS-Protection: 1; mode=block[\r][\n]"
    [2020-04-28 14:48:25,602] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Content-Type: application/json[\r][\n]"
    [2020-04-28 14:48:25,603] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Transfer-Encoding: chunked[\r][\n]"
    [2020-04-28 14:48:25,603] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Host: vonbibra--vbdevmerge.my.salesforce.com[\r][\n]"
    [2020-04-28 14:48:25,603] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Connection: Keep-Alive[\r][\n]"
    [2020-04-28 14:48:25,604] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
    [2020-04-28 14:48:25,604] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "[\r][\n]"
    [2020-04-28 14:48:25,604] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "dd[\r][\n]"
    [2020-04-28 14:48:25,605] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "{"getLead":{"Company":"N/A","Email":"dunleavy2010@hotmail.com","Lead_Type__c":"Internet","LeadSource":"L
    DV i-Motor - Get a Quote","FirstName":"Brendan","LastName":"Dunleavy","MobilePhone":"+61 449 819 834"},"getTrade":[]}[\r][\n]"
    [2020-04-28 14:48:25,605] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "0[\r][\n]"
    [2020-04-28 14:48:25,605] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "[\r][\n]"
    [2020-04-28 14:48:28,341] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "HTTP/1.1 200 OK[\r][\n]"
    [2020-04-28 14:48:28,341] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Date: Tue, 28 Apr 2020 09:18:20 GMT[\r][\n]"
    [2020-04-28 14:48:28,341] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Strict-Transport-Security: max-age=31536002; includeSubDomains[\r][\n]"
    [2020-04-28 14:48:28,342] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Public-Key-Pins-Report-Only: pin-sha256="9n0izTnSRF+W4W4JTq51avSXkWhQB8duS2bxVLfzXsY="; pin-sha256="5kJv
    NEMw0KjrCAu7eXY5HZdvyCS13BbA0VJG1RSP91w="; pin-sha256="njN4rRG+22dNXAi+yb8e3UMypgzPUPHlv4+foULwl1g="; max-age=86400; includeSubDomains; report-uri="https://a.forcesslreports.com/hp
    kp-report/00D550000000fgkm";[\r][\n]"
    [2020-04-28 14:48:28,342] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Expect-CT: max-age=86400, report-uri="https://a.forcesslreports.com/Expect-CT-report/00D550000000fgkm"[\
    r][\n]"
    [2020-04-28 14:48:28,342] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "X-Content-Type-Options: nosniff[\r][\n]"
    [2020-04-28 14:48:28,343] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "X-XSS-Protection: 1; mode=block[\r][\n]"
    [2020-04-28 14:48:28,343] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "X-Robots-Tag: none[\r][\n]"
    [2020-04-28 14:48:28,343] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private[\r][\n]"
    [2020-04-28 14:48:28,344] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Set-Cookie: BrowserId=M-JoJIkxEeqAhF-kj0dI8Q; domain=.salesforce.com; path=/; expires=Wed, 28-Apr-2021 0
    9:18:20 GMT; Max-Age=31536000[\r][\n]"
    [2020-04-28 14:48:28,344] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
    [2020-04-28 14:48:28,344] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Vary: Accept-Encoding[\r][\n]"
    [2020-04-28 14:48:28,345] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "Transfer-Encoding: chunked[\r][\n]"
    [2020-04-28 14:48:28,345] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "[\r][\n]"
    [2020-04-28 14:48:28,345] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "223[\r][\n]"
    [2020-04-28 14:48:28,346] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> ""{\"transactionId\":null,\"timestamp\":\"2020-04-28 19:18:24\",\"OpportunityId\":\"0065500000Fz9foAAB\",
    \"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtgEAB\"},\"Company\":\"N/A\",\"Email\":\
    "jaxonstevens18@gmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Jaxon\",\"LastName\":\"Stevens\",\"Id\":\"00Q5500000AvbtgEAB\
    ",\"MobilePhone\":\"+61 423 927 100\"},\"errorCode\":\"200\",\"appraisalId\":null}""
    [2020-04-28 14:48:29,084] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "[\r][\n]"
    [2020-04-28 14:48:29,084] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "0[\r][\n]"
    [2020-04-28 14:48:29,084] [] DEBUG - wire HTTPS-Sender I/O dispatcher-3 >> "[\r][\n]"
    [2020-04-28 14:48:29,631] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "HTTP/1.1 200 OK[\r][\n]"
    [2020-04-28 14:48:29,632] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Date: Tue, 28 Apr 2020 09:18:26 GMT[\r][\n]"
    [2020-04-28 14:48:29,632] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Strict-Transport-Security: max-age=31536002; includeSubDomains[\r][\n]"
    [2020-04-28 14:48:29,632] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Public-Key-Pins-Report-Only: pin-sha256="9n0izTnSRF+W4W4JTq51avSXkWhQB8duS2bxVLfzXsY="; pin-sha256="5kJv
    NEMw0KjrCAu7eXY5HZdvyCS13BbA0VJG1RSP91w="; pin-sha256="njN4rRG+22dNXAi+yb8e3UMypgzPUPHlv4+foULwl1g="; max-age=86400; includeSubDomains; report-uri="https://a.forcesslreports.com/hp
    kp-report/00D550000000fgkm";[\r][\n]"
    [2020-04-28 14:48:29,633] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Expect-CT: max-age=86400, report-uri="https://a.forcesslreports.com/Expect-CT-report/00D550000000fgkm"[\
    r][\n]"
    [2020-04-28 14:48:29,634] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-Content-Type-Options: nosniff[\r][\n]"
    [2020-04-28 14:48:29,634] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-XSS-Protection: 1; mode=block[\r][\n]"
    [2020-04-28 14:48:29,634] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-Robots-Tag: none[\r][\n]"
    [2020-04-28 14:48:29,634] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private[\r][\n]"
    [2020-04-28 14:48:29,635] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Set-Cookie: BrowserId=N0LRQokxEeqAhF-kj0dI8Q; domain=.salesforce.com; path=/; expires=Wed, 28-Apr-2021 0
    9:18:26 GMT; Max-Age=31536000[\r][\n]"
    [2020-04-28 14:48:29,635] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
    [2020-04-28 14:48:29,635] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Vary: Accept-Encoding[\r][\n]"
    [2020-04-28 14:48:29,636] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Transfer-Encoding: chunked[\r][\n]"
    [2020-04-28 14:48:29,636] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "[\r][\n]"
    [2020-04-28 14:48:29,636] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "226[\r][\n]"
    [2020-04-28 14:48:29,637] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> ""{\"transactionId\":null,\"timestamp\":\"2020-04-28 19:18:29\",\"OpportunityId\":\"0065500000Fz9fyAAB\",
    \"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtlEAB\"},\"Company\":\"N/A\",\"Email\":\
    "dunleavy2010@hotmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Brendan\",\"LastName\":\"Dunleavy\",\"Id\":\"00Q5500000AvbtlE
    AB\",\"MobilePhone\":\"+61 449 819 834\"},\"errorCode\":\"200\",\"appraisalId\":null}"[\r][\n]"
    [2020-04-28 14:48:29,637] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "0[\r][\n]"
    [2020-04-28 14:48:29,638] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "[\r][\n]"
    [2020-04-28 14:48:29,651] []  INFO - LogMediator ======OUTSEQUENCE======= = CALLED

线路日志 - 2:脚本相关的线路日志

[2020-04-28 14:48:29,653] []  INFO - LogMediator To: , WSAction: , SOAPAction: , MessageID: urn:uuid:14c06142-fccf-4a80-ba38-b8f040c992de, Direction: response, Envelope: <?xml vers
        ion='1.0' encoding='utf-8'?><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 19:18:24\",\"OpportunityId\":\"0065500000Fz9ftAAB\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"
        type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtbEAB\"},\"Company\":\"N/A\",\"Email\":\"steveross01@bigpond.com\",\"Lead_Type__c\":\"Internet\",\"LeadSou
        rce\":\"LDV Facebook - Book a Test Drive\",\"FirstName\":\"Stephen\",\"LastName\":\"Ross\",\"Id\":\"00Q5500000AvbtbEAB\",\"MobilePhone\":\"+61 414 404 774\"},\"errorCode\":\"200\",
        \"appraisalId\":null}"</jsonValue><jsonValue xmlns="">"{\"transactionId\":null,\"timestamp\":\"2020-04-28 19:18:24\",\"OpportunityId\":\"0065500000Fz9foAAB\",\"message\":\"Insert/U
        pdate success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtgEAB\"},\"Company\":\"N/A\",\"Email\":\"jaxonstevens18@gmail.
        com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Jaxon\",\"LastName\":\"Stevens\",\"Id\":\"00Q5500000AvbtgEAB\",\"MobilePhone\":\"+6
        1 423 927 100\"},\"errorCode\":\"200\",\"appraisalId\":null}"</jsonValue><jsonValue xmlns="">"{\"transactionId\":null,\"timestamp\":\"2020-04-28 19:18:29\",\"OpportunityId\":\"0065
        500000Fz9fyAAB\",\"message\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtlEAB\"},\"Company\":\"
        N/A\",\"Email\":\"dunleavy2010@hotmail.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV i-Motor - Get a Quote\",\"FirstName\":\"Brendan\",\"LastName\":\"Dunleavy\",\"Id\":\
        "00Q5500000AvbtlEAB\",\"MobilePhone\":\"+61 449 819 834\"},\"errorCode\":\"200\",\"appraisalId\":null}"</jsonValue></jsonObject></soapenv:Body></soapenv:Envelope>
        [2020-04-28 14:48:29,658] []  INFO - LogMediator ====each payload==== = "{\"transactionId\":null,\"timestamp\":\"2020-04-28 19:18:24\",\"OpportunityId\":\"0065500000Fz9ftAAB\",\"me
        ssage\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtbEAB\"},\"Company\":\"N/A\",\"Email\":\"ste
        veross01@bigpond.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV Facebook - Book a Test Drive\",\"FirstName\":\"Stephen\",\"LastName\":\"Ross\",\"Id\":\"00Q5500000AvbtbEAB
        \",\"MobilePhone\":\"+61 414 404 774\"},\"errorCode\":\"200\",\"appraisalId\":null}"
        [2020-04-28 14:48:29,665] []  INFO - CommonScriptMessageContext script payload::::{"transactionId":null,"timestamp":"2020-04-28 19:18:24","OpportunityId":"0065500000Fz9ftAAB","mess
        age":"Insert/Update success","Lead":{"attributes":{"type":"Lead","url":"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtbEAB"},"Company":"N/A","Email":"steveross01@bigpond.com","L
        ead_Type__c":"Internet","LeadSource":"LDV Facebook - Book a Test Drive","FirstName":"Stephen","LastName":"Ross","Id":"00Q5500000AvbtbEAB","MobilePhone":"+61 414 404 774"},"errorCod
        e":"200","appraisalId":null}
        [2020-04-28 14:48:29,666] []  INFO - LogMediator ====each payload==== = "{\"transactionId\":null,\"timestamp\":\"2020-04-28 19:18:24\",\"OpportunityId\":\"0065500000Fz9ftAAB\",\"me
        ssage\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtbEAB\"},\"Company\":\"N/A\",\"Email\":\"ste
        veross01@bigpond.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV Facebook - Book a Test Drive\",\"FirstName\":\"Stephen\",\"LastName\":\"Ross\",\"Id\":\"00Q5500000AvbtbEAB
        \",\"MobilePhone\":\"+61 414 404 774\"},\"errorCode\":\"200\",\"appraisalId\":null}"
        [2020-04-28 14:48:29,671] []  INFO - CommonScriptMessageContext script payload::::{"transactionId":null,"timestamp":"2020-04-28 19:18:24","OpportunityId":"0065500000Fz9ftAAB","mess
        age":"Insert/Update success","Lead":{"attributes":{"type":"Lead","url":"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtbEAB"},"Company":"N/A","Email":"steveross01@bigpond.com","L
        ead_Type__c":"Internet","LeadSource":"LDV Facebook - Book a Test Drive","FirstName":"Stephen","LastName":"Ross","Id":"00Q5500000AvbtbEAB","MobilePhone":"+61 414 404 774"},"errorCod
        e":"200","appraisalId":null}
        [2020-04-28 14:48:29,672] []  INFO - LogMediator ====each payload==== = "{\"transactionId\":null,\"timestamp\":\"2020-04-28 19:18:24\",\"OpportunityId\":\"0065500000Fz9ftAAB\",\"me
        ssage\":\"Insert/Update success\",\"Lead\":{\"attributes\":{\"type\":\"Lead\",\"url\":\"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtbEAB\"},\"Company\":\"N/A\",\"Email\":\"ste
        veross01@bigpond.com\",\"Lead_Type__c\":\"Internet\",\"LeadSource\":\"LDV Facebook - Book a Test Drive\",\"FirstName\":\"Stephen\",\"LastName\":\"Ross\",\"Id\":\"00Q5500000AvbtbEAB
        \",\"MobilePhone\":\"+61 414 404 774\"},\"errorCode\":\"200\",\"appraisalId\":null}"
        [2020-04-28 14:48:29,678] []  INFO - CommonScriptMessageContext script payload::::{"transactionId":null,"timestamp":"2020-04-28 19:18:24","OpportunityId":"0065500000Fz9ftAAB","mess
        age":"Insert/Update success","Lead":{"attributes":{"type":"Lead","url":"/services/data/v48.0/sobjects/Lead/00Q5500000AvbtbEAB"},"Company":"N/A","Email":"steveross01@bigpond.com","L
        ead_Type__c":"Internet","LeadSource":"LDV Facebook - Book a Test Drive","FirstName":"Stephen","LastName":"Ross","Id":"00Q5500000AvbtbEAB","MobilePhone":"+61 414 404 774"},"errorCod
        e":"200","appraisalId":null}

根据 For-Each 和 Iterate 中介的功能,整个消息将根据您提供的表达式拆分为多个部分。因此,每个中介只处理了 jsonValue 的一部分。

要去除斜杠,可以直接调用scrip mediator。或者,如果您想为每个中介删除每个对象的斜线,您当前的代码是正确的,但它不会一次处理所有消息。

作为替代方法,您可以使用聚合中介将所有拆分消息合并到一个负载中。

编辑#1:

试试这个删除斜杠的代码。

<foreach id="foreach_id" expression="//jsonValue">
   <sequence>
      <property name="jsonString" expression="json-eval($)" scope="default" type="STRING"/>
      <script language="js">var log = mc.getServiceLog();
       var payload = mc.getProperty('jsonString').toString();
       log.info("script payload::::" + payload); 
       var payloadRemoveSlash = payload.replace('\', '').replace('"{','{').replace('}"','}'); 
       mc.setProperty('payloadRemoveSlash',payloadRemoveSlash.toString());
       </script>
       <log>
         <property name=":: Body Inside payloadRemoveSlash::" expression="$ctx:payloadRemoveSlash"/>
      </log>
   </sequence>
</foreach>

现在,您可以使用 enrich mediator 将此 属性 转换为 Body,然后调用所需的端点。假设您使用 Iterate Mediator 而不是 For Each mediator。

我找到了解决问题的方法。我使用 属性 表达式作为 "$body/[1]" 而不是 "json-eval($)"迭代器。首先尝试使用 json-eval($) 每次迭代都保持相同的 json 即脚本中介日志为每次迭代打印相同的有效负载,然后将其更改为 "$body/[1 ]”,它幸运地生成了不同的有效载荷。

         <iterate continueParent="true" expression="//jsonValue" sequential="true">
                        <target>
                            <sequence>
                                <log level="full"/>
                                <property expression="$body/*[1]" name="jsonString" scope="default" type="STRING"/>
                                <script language="js"><![CDATA[var log = mc.getServiceLog();        
                                var payload = mc.getProperty('jsonString').toString(); 
                                payloadRemoveSlash = payload.replace('\', '').replace('"{','{').replace('}"','}');
                                //payloadRemoveSlash = payload.replace("\", "");
                                 mc.setProperty('payloadRemoveSlash',payloadRemoveSlash);
                                //log.info("payloadRemoveSlash:::" +payloadRemoveSlash)]]></script>
                                <enrich>
                                    <source clone="true" xpath="$ctx:payloadRemoveSlash"/>
                                    <target type="body"/>
                                </enrich>
                          </sequence>
                        </target>
                    </iterate>