简体   繁体   中英

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. i'm trying to iterate a json array to dispatch to different queues according to, for instance, the attribute "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:

<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 expression="#[json:activitylist]" doc:name="Splitter"/> <logger message="Activity #[json:activity/serviceConsumer]" level="INFO" doc:name="Logger"/> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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