首先,感谢你们所做的出色工作。我在您的网站上花费的时间越来越多,这是我的第一个帮助请求。
我正在评估mule esb。 我试图迭代一个json数组,根据例如属性" activity"来调度到不同的队列。
{
"activitylist":[
{
"activity": {
"serviceConsumer":"channelrecord",
"project":"5004channel 500448319610 type=",
"activity":"Transcodage",
"serviceProvider":"Internal"
}
},
{
"activity":{
"serviceConsumer":"channelrecord",
"project":"5004channel 500448319610 type=",
"activity":"Doublage",
"serviceProvider":"DubbingBroz"
}
}
]
}
我写了一个简单的测试流来捕获json msg并尝试使用foreach:
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="activity/delegate/savelist" path="activity/delegate/savelist"/>
<foreach doc:name="For Each" collection="#[payload.activitylist]">
<logger message="#[payload.serviceConsumer]" level="INFO" doc:name="Logger"/>
</foreach>
但没有运气。我收到了这些错误:
ERROR 2014-06-12 17:40:34,723 [[verto].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:********************************************************************************
Message : Execution of the expression "payload.activitylist" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: ContentLengthInputStream
Code : MULE_ERROR--2 --------------------------------------------------------------------------------
Exception stack is:
1. [Error: could not access: activitylist; in class: org.apache.commons.httpclient.ContentLengthInputStream] [Near : {... payload.activitylist ....}]
[Line: 1, Column: 1] (org.mvel2.PropertyAccessException) org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:690 (null)
2. Execution of the expression "payload.activitylist" failed (org.mule.api.expression.ExpressionRuntimeException) org.mule.el.mvel.MVELExpressionLanguage:213 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3. Execution of the expression "payload.activitylist" failed (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: ContentLengthInputStream (org.mule.api.MessagingException) org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)--------------------------------------------------------------------------------
任何帮助我优雅地发送这些东西的建议都将非常感激。
答案 0 :(得分:3)
在http:inbound-endpoint
和forEach
之间添加以下内容:
<json:json-to-object-transformer returnClass="java.lang.Object" />
答案 1 :(得分:0)
使用拆分器组件作为替代方案,并使用json路径到json字符串,
<splitter expression="#[json:activitylist]" doc:name="Splitter"/>
<logger message="Activity #[json:activity/serviceConsumer]" level="INFO" doc:name="Logger"/>
&#13;