简体   繁体   English

ule子如何迭代json请求

[英]mule how to iterate a json request

First, thank you for the amazing job you guys are doing. 首先,感谢你们所做的出色工作。 I'm spending more and more time on your site, and this is my first help request. 我在您的网站上花费的时间越来越多,这是我的第一个帮助请求。

I'm evaluating mule esb. 我正在评估m子。 i'm trying to iterate a json array to dispatch to different queues according to, for instance, the attribute "activity". 我正在尝试迭代一个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"
        }
    }
]

} }

i wrote a simple test flow to capture the json msg and trying to use foreach: 我编写了一个简单的测试流程来捕获json消息并尝试使用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>

but no luck. 但没有运气。 I'm getting these errors: 我收到这些错误:

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)--------------------------------------------------------------------------------

any suggestion to help me to dispatch this stuff gracefully would be greatly appreciated. 任何建议,以帮助我优雅地分发这些东西将不胜感激。

http:inbound-endpointforEach之间添加以下内容:

<json:json-to-object-transformer returnClass="java.lang.Object" />

Use splitter component as for the alternative and use json path to json string, 使用splitter组件作为替代,并使用json路径指向json字符串,

 <splitter expression="#[json:activitylist]" doc:name="Splitter"/> <logger message="Activity #[json:activity/serviceConsumer]" level="INFO" doc:name="Logger"/> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM