I have a small issue ... I am exposing a REST service which fetch a list of data in JSON format.. The following is my flow :-
<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<jersey:resources doc:name="REST">
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl"/>
</jersey:resources>
</flow>
Now If I hit the service I am getting the response in following format :-
{
"retrieveAllData":
[
{
"response": "The Data retrieved from the Database",
"id": 1231,
"name": "abc",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 165,
"name": "test",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 134,
"name": "test2",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 7,
"name": "test3",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 9,
"name": "testagain",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 10,
"name": "newteat",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 11,
"name": "ani",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 12,
"name": "test",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 135,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 166,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 167,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 444,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 446,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 447,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 442,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 133,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 4,
"name": "againtest",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 3,
"name": "fdf",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 8,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 445,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
}
]
}
Now, Since this response is long and huge, I want to split this response in smaller part in a batch of 5 like :-
{
"response": "The Data retrieved from the Database",
"id": 447,
"name": "test",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 442,
"name": "test2",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 133,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 4,
"name": "test3",
"age": 561,
"designation": "Senior Software Engineer"
},
{
"response": "The Data retrieved from the Database",
"id": 3,
"name": "fff",
"age": 561,
"designation": "Senior Software Engineer"
}
So, I followed the following :- Mule - split a big JSON list into multiple smaller JSON lists
and after the jersey component in my flow I put the following :-
<json:json-to-object-transformer returnClass="java.util.Map"/>
<foreach batchSize="5">
<json:object-to-json-transformer/>
<logger message="ResponseLogdadasd :- #[message.payload]" level="INFO" doc:name="ResponseLogger"/>
</foreach>
Now, I am getting the following exception :-
********************************************************************************
Message : Infinite recursion (StackOverflowError) (through reference chain: ->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContext"]->org.mule.DefaultMuleContext["workManager"]->org.mule.work.MuleWorkManager["muleContex...--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.StackOverflowError
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Am I doing right ?? Is this the way will I can get to break the response into a smaller part in a batch size of 5 ?? Your suggestion please