[英]Mule - java.lang.String cannot be cast to java.util.Map
I want to write a mule application which will read the database for unprocessed records, club them in JSON payload format and then hit a REST webservice. 我想编写一个ule子应用程序,它将读取数据库中的未处理记录,将它们合并为JSON有效负载格式,然后单击REST Web服务。 I am able to read the records from the database and able to convert the database records in JSON.
我能够从数据库中读取记录,并能够以JSON转换数据库记录。 However, whenever I run the application I am getting following exception
但是,每当我运行应用程序时,都会出现以下异常
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map java.lang.ClassCastException:无法将java.lang.String强制转换为java.util.Map
Here is my Mule configuration XML 这是我的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>
I am unable to understand where it is going wrong 我不明白哪里出了问题
Please help me, I am trying this since last 2 days. 请帮助我,自最近两天以来,我一直在尝试此操作。
Thanks in advance 提前致谢
-Paresh (kendreparesh@gmail.com) -Paresh(kendreparesh@gmail.com)
Try removing this line. 尝试删除此行。
<http:query-params expression="#[payload]"/>
It should work. 它应该工作。 As your payload is Json String and you are trying to map it to Query params which expects Map.
由于您的有效负载是Json String,因此您尝试将其映射到需要Map的Query params。 Also for POST your payload will converted to body.
同样对于POST,您的有效负载将转换为主体。
expression in query-params must be a map. query-params中的表达式必须是一个映射。 If you are going to pass data as query-params, why are you doing object to json?
如果您要将数据作为查询参数传递,为什么要对json做对象? Try removing below two lines -
尝试删除以下两行-
<json:object-to-json-transformer doc:name="Object to JSON" />
<logger message="JSON Payload is #[payload]" level="INFO" doc:name="Logger"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.