gpt4 book ai didi

java - 为什么从 MEL 访问 ArrayList 的大小时会出现运行时异常?

转载 作者:行者123 更新时间:2023-12-02 18:18:15 29 4
gpt4 key购买 nike

在 Mulesoft 中,我有一个 ArrayList,它存储为带有一个元素的出站属性。它看起来像这样: enter image description here

但是如果我尝试访问该数组的大小,我会收到错误并且无法弄清楚原因: enter image description here

错误是

[Error: object is not an instance of declaring class]
[Near : {... message.outboundProperties.crm ....}]
^
[Line: 1, Column: 1]

这是一个抛出相同错误的流程:

    <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd">
<quartz:connector name="Quartz" validateConnections="true" doc:name="Quartz"/>
<flow name="tempFlow">
<quartz:inbound-endpoint jobName="job1" repeatInterval="1" repeatCount="0" connector-ref="Quartz" name="runOnce" doc:name="Quartz">
<quartz:event-generator-job>
<quartz:payload>foo</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="crmRequests" value="#[[]]"/>
</message-properties-transformer>
<dw:transform-message doc:name="Copy_of_buildUpdateRequest">
<dw:set-payload><![CDATA[
%dw 1.0
%output application/java
---
{
statecode: 0
}
]]></dw:set-payload>
</dw:transform-message>
<expression-component doc:name="Copy_of_Expression"><![CDATA[#[message.outboundProperties.crmRequests.add(payload)]]]></expression-component>
<set-payload value="#[message.outboundProperties.crmRequests.size()]" doc:name="Set Payload"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>

最佳答案

将表达式括在括号内:

<set-payload value="#[(message.outboundProperties.crmRequests).size()]" doc:name="Set Payload"/>

要进行进一步测试,您可以尝试其他 java.util.ArrayList 方法,例如:(message.outboundProperties.crmRequests).get(0)

关于java - 为什么从 MEL 访问 ArrayList 的大小时会出现运行时异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38128137/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com