Mule - 如何在Mule JDBC查询中引用字符串查询参数?

时间:2014-07-29 19:41:03

标签: xml json jdbc mule

我的xml如下

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core 
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd" version="EE-3.5.1">
    <apikit:config name="flights-config" raml="flights.raml" consoleEnabled="false" consolePath="console" doc:name="Router" />
    <apikit:mapping-exception-strategy name="flights-apiKitGlobalExceptionMapping" doc:name="Mapping Exception Strategy">
        <apikit:mapping statusCode="404">
            <apikit:exception value="org.mule.module.apikit.exception.NotFoundException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property" />
            <set-payload value="{ &quot;message&quot;: &quot;Resource not found&quot; }" doc:name="Set Payload" />
        </apikit:mapping>
        <apikit:mapping statusCode="405">
            <apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property" />
            <set-payload value="{ &quot;message&quot;: &quot;Method not allowed&quot; }" doc:name="Set Payload" />
        </apikit:mapping>
        <apikit:mapping statusCode="415">
            <apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property" />
            <set-payload value="{ &quot;message&quot;: &quot;Unsupported media type&quot; }" doc:name="Set Payload" />
        </apikit:mapping>
        <apikit:mapping statusCode="406">
            <apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property" />
            <set-payload value="{ &quot;message&quot;: &quot;Not acceptable&quot; }" doc:name="Set Payload" />
        </apikit:mapping>
        <apikit:mapping statusCode="400">
            <apikit:exception value="org.mule.module.apikit.exception.BadRequestException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property" />
            <set-payload value="{ &quot;message&quot;: &quot;Bad request&quot; }" doc:name="Set Payload" />
        </apikit:mapping>
    </apikit:mapping-exception-strategy>
    <db:mysql-config name="MySQL_Configuration" url="jdbc:mysql://my.connection.details" doc:name="MySQL Configuration" />
    <flow name="flights-main" doc:name="flights-main">
        <http:inbound-endpoint address="http://localhost:8082" doc:name="HTTP" exchange-pattern="request-response" />
        <apikit:router config-ref="flights-config" doc:name="APIkit Router" />

        <db:select config-ref="MySQL_Configuration" doc:name="Database">
            <db:parameterized-query><![CDATA[select * from currentFlights where destination = #[payload] and availableSeats > 0;]]></db:parameterized-query>

        </db:select>
        <json:object-to-json-transformer doc:name="Object to JSON" />
        <exception-strategy ref="flights-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy" />
    </flow>
    <flow name="get:/flights:flights-config" doc:name="get:/flights:flights-config">
        <set-payload value="#[message.inboundProperties[destination]]" doc:name="Set Payload"/>
    </flow>
</mule>

0 个答案:

没有答案