2014-12-30 14 views
0

我有一個小問題...我露出一個REST服務,以JSON格式獲取數據的列表.. 以下是我的流程: -如何突破一個JSON響應到特定批次尺寸較小的JSON一部分

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

現在,如果我打我得到在以下格式的響應服務: -

{ 
    "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" 
     } 
    ] 
} 

現在,由於這種反應是漫長的,巨大的,我想拆的小部分這種反應在一批5,如: -

{ 
       "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" 
      } 

所以,我也跟着以下內容: - Mule - split a big JSON list into multiple smaller JSON lists

,並在我的流程球衣組件後,我把以下內容: -

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

現在,我得到以下異常: -

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

我在做對嗎?這種方式是否可以將反應分成5個批量的小部分?您的建議,請

回答

0

根據您的問題的JSON,代碼

<json:json-to-object-transformer returnClass="java.util.Map"/> 

生成帶有一鍵通「retrieveAllData」(它將包含您正在尋找的集合)的地圖。

嘗試以下操作:

<foreach batchSize="5" collection="#[payload['retrieveAllData']]"> 
    <json:object-to-json-transformer/> 
    <logger message="ResponseLogdadasd :- #[message.payload]" level="INFO" doc:name="ResponseLogger"/> 
</foreach> 
+0

我收到了同樣的異常努諾 –