假设我有一个基于 REST 的服务,它返回一个 JSON 对象,如下所示
{
"AlertDetails":
{
"start":0,
"left":0,
"_itemList":
[
{
"id":"badntp",
"text":"The time cannot be synchronized to the configured time server.",
"click":{
"text":"Click here to modify your time settings.",
"url":"datetime.html"
},
"severity":"warning",
"occurred":"20121031T10:18:54",
"args":null
},
{
"id":"updatesitefail",
"text":"The update site cannot be contacted to determine if software updates are available.",
"click":{
"text":"Click here to manually check for updates.",
"url":"http:\\\/\\\/xyz.com\\\/support\\\/xyz.html"
},
"severity":"info",
"occurred":"20121105T17:23:24",
"args":"[http:\\\/\\\/xyz.com\\\/support\\\/xyz.html]"
}
]
}
}
现在我在 PostgreSQL 中有一个表(比如testTable),其结构如下
ID (string)
Severity (string)
Occurred (string)
如何从可用的 JSON 字段中解析这些值,以将其插入 Mule ESB 工作室的 PostgreSQL 数据库中。
testTable 中的最终结果应该是
ID Severity Occured
--------- --------- --------
"badntp" "warning" "20121031T10:18:54"
"updatesitefail" "info" "20121105T17:23:24"
我的配置文件如下
<jdbc:postgresql-data-source name="PostgreSQL_Data_Source"
user="username" password="pwd" url="jdbc:postgresql://localhost:5432/TestDB"
transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source" />
<jdbc:connector name="PostgreSQL_Connector" dataSource-ref="PostgreSQL_Data_Source"
validateConnections="true" queryTimeout="-1" pollingFrequency="0"
doc:name="Database">
<jdbc:query key="InsertRecord"
value="INSERT INTO "testTable"("ID","Severity","Occured") VALUES (?,?,?)" />
</jdbc:connector>
<flow name="testRestFlow1" doc:name="testRestFlow1">
<http:inbound-endpoint exchange-pattern="request-response"
address="http://localhost:8082/index.html" doc:name="HTTP" />
<http:rest-service-component httpMethod="GET"
serviceUrl="http://localhost:35798/RestServiceImpl.svc/json/567" />
<object-to-string-transformer />
<jdbc:outbound-endpoint exchange-pattern="one-way"
queryKey="InsertRecord" queryTimeout="-1" connector-ref="PostgreSQL_Connector"
doc:name="Database" />
</flow>
#[message.payload] 将包含整个 JSON 字符串。VALUES (?,?,?)
解析 会出现什么(正则表达式或其他内容)#[message.payload]
?
提前致谢