Mule 3.8.3运行时 - 数据库连接器 - 使用来自流变量的查询返回java.lang.IllegalArgumentException

时间:2017-04-29 12:31:03

标签: mule

我无法从数据库连接器内的flowVariable引用查询。我已经读到这是mule 3.5中的一个已知问题。我不确定它在3.8中是否仍然是一个未解决的问题。有人知道吗?

以下是流程 -

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:db="http://www.mulesoft.org/schema/mule/db" 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <db:mysql-config name="MySQL_Configuration5" host="localhost" port="3306" user="root" password="root" database="world" doc:name="MySQL Configuration"/>
    <flow name="selectFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/db/select" allowedMethods="GET" doc:name="HTTP"/>
        <db:select config-ref="MySQL_Configuration5" doc:name="local mysql database">
            <db:parameterized-query><![CDATA[select * from country where code='IND']]></db:parameterized-query>
        </db:select>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>
    <flow name="deleteFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/db/delete" allowedMethods="DELETE" doc:name="HTTP"/>
        <db:delete config-ref="MySQL_Configuration5" doc:name="local mysql database">
            <db:parameterized-query><![CDATA[delete from countrylanguage where countrycode='PAK']]></db:parameterized-query>
        </db:delete>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    </flow>
    <flow name="postFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/db/insert" allowedMethods="POST" doc:name="HTTP"/>
        <set-variable variableName="jsonString" value="#[payload]" doc:name="Variable"/>
        <flow-ref name="cleanUpBeforeInserting" doc:name="cleanUpBeforeInserting"/>
        <json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Collection"/>
        <flow-ref name="InsertEachRecord" doc:name="Flow Reference"/>
    </flow>
    <flow name="cleanUpBeforeInserting">
        <db:delete config-ref="MySQL_Configuration5" doc:name="Database">
            <db:parameterized-query><![CDATA[delete from countrylanguage where countrycode='PAK']]></db:parameterized-query>
        </db:delete>
        <set-payload value="#[flowVars.jsonString]" doc:name="Set Payload"/>
        <logger message="************* cleaned up data **************** " level="INFO" doc:name="Logger"/>
    </flow>
    <sub-flow name="InsertEachRecord">
        <foreach doc:name="For Each">
            <set-variable variableName="sqlStatement" value="Insert into countrylanguage (countrycode, language, percentage, isofficial) values(#[payload.CountryCode], #[payload.Language],#[payload.Percentage], #[payload.IsOfficial])" doc:name="Variable"/>
            <logger message="#[flowVars.sqlStatement]" level="INFO" doc:name="Logger"/>
            <db:insert config-ref="MySQL_Configuration5" doc:name="Database">
                <db:parameterized-query><![CDATA[#[flowVars.sqlStatement]]]></db:parameterized-query>
            </db:insert>
            <json:object-to-json-transformer doc:name="Object to JSON"/>
        </foreach>
    </sub-flow>
</mule>

如果我用#[flowVars.sqlStatement]

替换Insert into countrylanguage (countrycode, language, percentage, isofficial) values(#[payload.CountryCode], #[payload.Language],#[payload.Percentage], #[payload.IsOfficial]),它可以正常工作

任何指针都会有所帮助。提前谢谢。

1 个答案:

答案 0 :(得分:1)

而是使用<db:parameterized-query>尝试<db:dynamic-query>,如下所示

<db:insert config-ref="MySQL_Configuration5" doc:name="Database">
  <db:dynamic-query><![CDATA[#[flowVars.sqlStatement]]]></db:dynamic-query>
</db:insert>