2016-09-26 56 views
0

我想编写一个mule应用程序,它将读取未处理记录的数据库,将它们以JSON有效负载格式包装起来,然后打开REST web服务。 我能够从数据库中读取记录并能够以JSON格式转换数据库记录。但是,每当我运行该应用程序我得到以下异常Mule - java.lang.String不能转换为java.util.Map

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> 

我无法理解它出错的地方

请帮助我,我正在尝试此过去两天。

预先感谢

-Paresh([email protected]

+0

好像你正在使用的有效载荷作为HTTP请求的查询参数,但为了将它们设置为他们需要的是一个Map的表达式(查询键/查询值) 。这是铸造错误的关键。你实际需要什么作为查询参数? – afelisatti

+0

由于我以JSON格式转换数据库行并尝试将此JSON传递给webservice,因此webservice期望JSON格式的有效内容。 –

+0

然后你不需要查询参数。 – afelisatti

回答

1

尝试移除此行。

<http:query-params expression="#[payload]"/> 

它应该工作。由于您的负载是Json字符串,并且您试图将其映射到需要映射的查询参数。对于POST,您的有效载荷也将转换为正文。

+0

非常感谢。它为我工作:)但是我得到“响应代码401映射为失败”作为例外,但我可以从那里采取。谢谢... –

0

query-params中的表达式必须是一个映射。如果你打算把数据作为查询参数传递,你为什么要对json进行反对?尝试删除下面两行 -

<json:object-to-json-transformer doc:name="Object to JSON" /> 
     <logger message="JSON Payload is #[payload]" level="INFO" doc:name="Logger"/> 
+0

REST weebservice期待JSON格式的负载,因为我正在从JSON数据库转换记录。 –

+0

好吧,在这种情况下,你应该删除查询参数,就像@anupambhusari说的那样。 –

相关问题