"Script" 1 : 1" 评估 mule 4 中的表达式错误

"Script" 1 : 1" evaluating expression error in mule 4

我正在尝试使用肥皂信封、header 和 body 设置负载。

然后通过 payload.indexOf("?>")+2

子字符串有效负载

基于以下表达式:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://decisionresearch.com/RateMaker">
<soapenv:Header/>
<soapenv:Body>
#[payload.substring(payload.indexOf("?>")+2)]
</soapenv:Body>
</soapenv:Envelope> 

输入请求:https://github.com/Manikandan99/Map_request/blob/main/Request_map.xml

预期输出:https://github.com/Manikandan99/Map_request/blob/main/Response_map.xml

骡子流量:

<flow name="map_requestFlow" doc:id="21d0d652-3766-47ed-95aa-a451f62c5776" >
        <http:listener doc:name="Listener" doc:id="7312114b-2857-40b3-98cd-f52b628b3a28" config-ref="HTTP_Listener_config" path="/map"/>
        <ee:transform doc:name="Transform Message" doc:id="7f061325-473b-4f63-8e95-990827b03259" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/xml
---
payload]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" doc:id="21051f39-bb9f-412c-af73-f65051317757" message="#[payload]"/>
        <set-payload value='#[&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://decisionresearch.com/RateMaker"&gt;
&#10;&lt;soapenv:Header/&gt;
&#10;&lt;soapenv:Body&gt;
&#10;#[payload.substring(payload.indexOf("?&gt;")+2)]
&#10;&lt;/soapenv:Body&gt;
&#10;&lt;/soapenv:Envelope&gt;]' doc:name="Set Payload" doc:id="faf2bc3b-e7a3-4708-910b-daeb05bb5f6e" />
</flow>

错误信息:https://github.com/Manikandan99/Map_request/blob/main/Error.txt

如何用当前有效负载封装 soap?

由于多种原因,这是错误的。首先,您不能在表达式中使用表达式。其次,当 DataWeave 已经生成有效的 XML 时,您正在尝试使用字符串生成 XML。直接使用字符串非常容易出错。每当您看到字符串操作生成或解析 XML 时,您应该质疑原因。

而是使用 DataWeave 在简单的转换中完全生成 XML:

%dw 2.0
output application/xml
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
---
{
    soapenv#Envelop: {
        soapenv#Header: null,
        soapenv#Body: payload
    }
}

输出(假设输入格式为application/xml):

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelop xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header/>
  <soapenv:Body>
    <ns0:rate xmlns:ns0="http://decisionresearch.com/RateMaker">
      <ns0:BrokerData>
        <ns0:taxa>TOPA/CISG01/ALL</ns0:taxa>
        <ns0:effectiveMode>effective</ns0:effectiveMode>
        <ns0:requestDate>20190101</ns0:requestDate>
        <ns0:function>rate</ns0:function>
      </ns0:BrokerData>
      <ns0:RateRequest>
        <ns0:Policy>
          <PolType>CNPK</PolType>
          <ClassCode>CANDIS</ClassCode>
          <Zip>80003</Zip>
          <State>CO</State>
          <EffDate>20211117</EffDate>
          <ExpDate>20221117</ExpDate>
          <Payroll>1200</Payroll>
          <OHPayroll/>
          <WAPayroll/>
          <FTE>5</FTE>
          <OccAgg>1000000/2000000</OccAgg>
          <DmgPrem>500000</DmgPrem>
          <MedPay>10000</MedPay>
          <EmpBen>Yes</EmpBen>
          <StopGap>None</StopGap>
          <OHStopGap>None</OHStopGap>
          <WAStopGap>None</WAStopGap>
          <HNO>1000000</HNO>
          <AssBat>100000/200000</AssBat>
          <PerLocAgg>Yes</PerLocAgg>
          <NumLoc>1</NumLoc>
          <WSUB>0</WSUB>
          <PICO>No</PICO>
          <AIML>0</AIML>
          <AIVS>0</AIVS>
          <AIPA>0</AIPA>
          <AIMA>0</AIMA>
          <AILL>0</AILL>
          <LLEA>0</LLEA>
          <AIDP>0</AIDP>
          <BAIV>No</BAIV>
          <WACombo>No</WACombo>
          <IRPMGL>2</IRPMGL>
          <LPDPGL>1.00</LPDPGL>
        </ns0:Policy>
        <ns0:Location>
          <LocationRef>Location-465697646-800339871</LocationRef>
          <State>CO</State>
          <Zip>80003</Zip>
        </ns0:Location>
        <ns0:Class>
          <Id>Risk-1296379588-1802098261</Id>
          <Number>1</Number>
          <ClassCode>CANDIS</ClassCode>
          <Exposure>2000000</Exposure>
          <GLBR>25</GLBR>
          <IsPrimary>Yes</IsPrimary>
        </ns0:Class>
      </ns0:RateRequest>
    </ns0:rate>
  </soapenv:Body>
</soapenv:Envelop>