简体   繁体   English

ule子-无法将java.lang.String强制转换为java.util.Map

[英]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.

相关问题 java neo4j用cypher创建节点:java.lang.String不能强制转换为java.util.Map - java neo4j creating node with cypher: java.lang.String cannot be cast to java.util.Map 使用jersey的REST Service输出中的java.util.Map - java.util.Map in output of REST Service using jersey 使用Jersey / JAXB / Jackson的Java.util.Map到JSON对象 - Java.util.Map to JSON Object with Jersey / JAXB / Jackson Java Spring rest java.lang.ClassCastException:java.util.LinkedHashMap 不能转换为 Cuestionario - Java Spring rest java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to Cuestionario 获取错误Java类java.util.ArrayList / List的消息正文编写器 <java.lang.String> 没有找到 - Getting error A message body writer for Java class java.util.ArrayList/List<java.lang.String> was not found 使用Spring MVC和Jackson将JSON输入映射到java.util.Map - Map a JSON input to java.util.Map using Spring MVC and Jackson Jersy Rest服务接受MediaType.APPLICATION_JSON的java.util.Map - Jersy Rest service to accept java.util.Map for MediaType.APPLICATION_JSON Android JSONException:值 - Android JSONException: Value <script of type java.lang.String cannot be converted to JSONObject java.lang.Integer 不能转换为 java.lang.Long - java.lang.Integer cannot be cast to java.lang.Long Spring NumberFormatException:无法将类型&#39;java.lang.String&#39;的值转换为所需的类型&#39;java.lang.Long - Spring NumberFormatException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM