Skip to content

Instantly share code, notes, and snippets.

@rsogo
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsogo/b574c5bef2b5f3c75b1f to your computer and use it in GitHub Desktop.
Save rsogo/b574c5bef2b5f3c75b1f to your computer and use it in GitHub Desktop.
[Mule] WebサービスでデータベースのSelect、Update
<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns="http://www.mulesoft.org/schema/mule/core"
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:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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
http://www.mulesoft.org/schema/mule/db
http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
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/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<db:generic-config doc:name="Generic Database Configuration" driverClassName="oracle.jdbc.driver.OracleDriver" name="Oracle_Configuration" url="jdbc:oracle:thin:{user}/{password}@localhost:1521:{SID}"/>
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" basePath="database" doc:name="HTTP Listener Configuration"/>
<flow name="GetFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="Recieve HTTP request" allowedMethods="GET"/>
<db:select config-ref="Oracle_Configuration" doc:name="Perform a query in Database">
<db:dynamic-query><![CDATA[select NAME, VALUE from TEST]]></db:dynamic-query>
</db:select>
<json:object-to-json-transformer doc:name="Convert Object to JSON"/>
</flow>
<flow name="PostFlow" doc:name="PostFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="Recieve HTTP request" allowedMethods="POST"/>
<logger doc:name="Log the payload" level="INFO" message="About to echo #[message.payload]"/>
<json:json-to-object-transformer returnClass="java.util.ArrayList" doc:name="JSON to Object"/>
<logger doc:name="Log the payload" level="INFO" message="About to echo #[message.payload]"/>
<foreach collection="#[message.payload]" doc:name="For Each">
<logger doc:name="Log the payload" level="INFO" message="About to echo #[payload.NAME]"/>
<logger doc:name="Log the payload" level="INFO" message="About to echo #[payload.VALUE]"/>
<db:insert config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[INSERT INTO TEST(NAME, VALUE)
VALUES (#[payload.NAME], #[payload.VALUE])]]></db:parameterized-query>
</db:insert>
</foreach>
</flow>
</mule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment