json - 如何提取Mule ind中的所有JSON值插入数据库

标签 json xpath mule mule-el

我的 Mule 流程中有一个 REST 服务:-

<flow name="restServiceFlow1" doc:name="restFlow1">
        <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>

我还有另一个流程,它将 JSON 请求从文件发送到该服务流程并使用它:-

<flow name="restFlow2" doc:name="restFlow2">
 <file:inbound-endpoint path="E:\backup\test" responseTimeout="10000" doc:name="File" connector-ref="File_Global">
                        <file:filename-regex-filter pattern="aa.txt" caseSensitive="false"/>
 </file:inbound-endpoint>

        <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
        <http:outbound-endpoint exchange-pattern="request-response" contentType="application/json" method="GET" address="http://localhost:8082/getData/insert/?id=#[payload.insertDataRequest[0].id]&amp;name=#[payload.insertDataRequest[0].name]&amp;age=#[payload.insertDataRequest[0].age]&amp;designation=#[payload.insertDataRequest[0].designation]" doc:name="HTTP"/>
     </flow>

现在我的 JSON 请求是:-

{
    "insertDataRequest": [
        {
            "id": "6",
            "name": "ddddd",
            "age": "55",
            "designation": "WQQQQQ"
        },
        {
            "id": "64",
            "name": "mmmm",
            "age": "545",
            "designation": "TTTTTTTTTT"
        }
    ]
}

现在,问题是每当我将 JSON 请求作为文件放置时......仅插入第一个数据......这只是

{
                "id": "6",
                "name": "ddddd",
                "age": "55",
                "designation": "WQQQQQ"
 }

正在插入数据库.. enter image description here

.... ....现在我想将所有数据插入数据库...我怎样才能实现它? ..我需要每个人都获取所有数据吗??...请帮助...

最佳答案

对每个 block 使用 a 来迭代 insertDataRequest 条目:

<flow name="restFlow2">
  <file:inbound-endpoint path="E:\backup\test" responseTimeout="10000" connector-ref="File_Global">
    <file:filename-regex-filter pattern="aa.txt" caseSensitive="false"/>
  </file:inbound-endpoint>

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

  <foreach collection="#[payload.insertDataRequest]">
    <http:outbound-endpoint exchange-pattern="request-response"
          contentType="application/json" method="GET"
          address="http://localhost:8082/getData/insert/?id=#[payload.id]&amp;name=#[payload.name]&amp;age=#[payload.age]&amp;designation=#[payload.designation]"/>
  </foreach>
</flow>

请注意,您使用 GET 而不是 POST 执行插入的事实不尊重 REST 原则...

关于json - 如何提取Mule ind中的所有JSON值插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721509/

相关文章:

java - 请建议序列化 JAXB 列表的最佳模式

Python在JSON结构中获取 sibling

java - 如何使用java为XML中的节点生成Xpath?

XSLT 选择//​​ 和 .//

java - 将 POJO 值传递到 Mule ESB 中的数据库

mule - MULE 中的默认线程池大小

android - 使用 robospice google http 客户端在 Post 中发送 JSON

javascript - 如何从具有数组的json绑定(bind)网格

python - 使用 dryscrape 进行网页抓取 : error selecting radio button CSS

从 JBoss 发出 http 请求时,Mule 出错