【发布时间】:2016-09-26 13:19:55
【问题描述】:
我想编写一个 mule 应用程序,它将读取数据库中未处理的记录,以 JSON 有效负载格式将它们组合起来,然后访问 REST Web 服务。 我能够从数据库中读取记录并能够将数据库记录转换为 JSON。但是,每当我运行应用程序时,都会出现以下异常
java.lang.ClassCastException: java.lang.String 无法转换为 java.util.Map
这是我的 Mule 配置 XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" database="my_database_name" doc:name="MySQL Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="example.net" port="8000" basePath="API" doc:name="HTTP Request Configuration"/>
<flow name="cwg_clientFlow">
<poll doc:name="Poll">
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT * FROM cwg_ws_data WHERE SyncFlag = 0]]></db:parameterized-query>
</db:select>
</poll>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<json:object-to-json-transformer doc:name="Object to JSON" />
<logger message="JSON Payload is #[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/cwg" method="POST" doc:name="HTTP">
<http:request-builder>
<http:query-params expression="#[payload]"/>
<http:header headerName="access_token" value="MQTgpMUmyQLt134maB6vPp6oWFgMtGsqzIlpCN74"/>
</http:request-builder>
</http:request>
<logger message="webservice response #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
我不明白哪里出了问题
请帮帮我,我从前 2 天开始就在尝试这个。
提前致谢
-Paresh (kendreparesh@gmail.com)
【问题讨论】:
-
您似乎正在使用有效负载作为 HTTP 请求的查询参数,但为了将它们设置为表达式,它们需要是 Map(查询键/查询值)。这就是铸造错误的意义所在。您实际需要什么作为查询参数?
-
Web 服务需要 JSON 格式的有效负载,因为我正在将数据库行转换为 JSON 格式并尝试将此 JSON 传递给 Web 服务。
-
那你就不需要查询参数了。
标签: rest mule classcastexception http-request