Mule 数据库操作发布成Webservice和Rest的例子

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

<mule xmlns:context="http://www.springframework.org/schema/context"
xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" 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/context http://www.springframework.org/schema/context/spring-context-current.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
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.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" version="EE-3.6.0">

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8333" basePath="soap" doc:name="HTTP Listener Configuration"/>
<db:oracle-config name="Oracle_Configuration" host="127.0.0.1" port="1521" instance="orcl" user="hlyy" password="hlyy" doc:name="Oracle Configuration"/>

<spring:beans>

<!-- <context:component-scan base-package="com.test" /> -->
<spring:bean id="myData" name="myData" class="java.util.HashMap" scope="singleton"/>
<spring:bean id="myData1" name="myData1" class="java.util.HashMap" scope="singleton"/>
<!-- <spring:bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> -->
</spring:beans>


<flow name="ws_PatMarkRegister">
<http:listener config-ref="HTTP_Listener_Configuration" path="/ws-service" doc:name="HTTP"/>
<cxf:jaxws-service serviceClass="com.test.MyService" doc:name="CXF"/>
<component class="com.test.MyServiceImpl" doc:name="Java">
</component>
<choice doc:name="Choice">
<when expression="#[app.registry.'myData'.get('TRANS_TYPE')=='2']">
<flow-ref name="TransType=2" doc:name="TransType=2"/>
</when>
<otherwise>
<flow-ref name="TransType=1" doc:name="TransType=1"/>
</otherwise>
</choice>
<!--
<component class="com.test.MyServiceImpl" doc:name="Java"/>
-->
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="TransType=1">
<db:update config-ref="Oracle_Configuration" doc:name="Update_valid_flag">
<db:parameterized-query><![CDATA[update msg_biz_patmark t set t.valid_flag = 0
where t.clinic_no =#[app.registry.'myData'.get('CLINIC_NO')]
and t.clinic_type =#[app.registry.'myData'.get('CLINIC_TYPE')]
and t.mark_guid = #[app.registry.'myData'.get('MARK_GUID')]
and t.trans_type = #[app.registry.'myData'.get('TRANS_TYPE')]]]></db:parameterized-query>
</db:update>
<db:insert config-ref="Oracle_Configuration" doc:name="InsertDatabase">
<db:parameterized-query><![CDATA[insert into msg_biz_patmark
(guid,
clinic_no,
name,
sex_code,
card_no,
oper_code,
oper_dtime,
clinic_type,
trans_type,
mark_guid,
mark_name,
valid_flag
)
select sys_guid(),
#[app.registry.'myData'.get('CLINIC_NO')] CLINIC_NO,
'' name,
'' sex_code,
'' card_no,
#[app.registry.'myData'.get('OPER_CODE')] oper_code,
sysdate oper_dtime,
#[app.registry.'myData'.get('CLINIC_TYPE')] clinic_type,
#[app.registry.'myData'.get('TRANS_TYPE')] trans_type,
#[app.registry.'myData'.get('MARK_GUID')] mark_guid,
t.mark_name mark_name,
1 valid_flag
from msg_com_mark t
where t.guid = #[app.registry.'myData'.get('MARK_GUID')]]]></db:parameterized-query>

</db:insert>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</sub-flow>
<sub-flow name="TransType=2">
<db:update config-ref="Oracle_Configuration" doc:name="Update_valid_flag">
<db:parameterized-query><![CDATA[update msg_biz_patmark t set t.valid_flag = 0
where t.clinic_no =#[app.registry.'myData'.get('CLINIC_NO')]
and t.clinic_type =#[app.registry.'myData'.get('CLINIC_TYPE')]
and t.mark_guid = #[app.registry.'myData'.get('MARK_GUID')]]]></db:parameterized-query>
</db:update>
<db:insert config-ref="Oracle_Configuration" doc:name="InsertDatabase">
<db:parameterized-query><![CDATA[insert into msg_biz_patmark
(guid,
clinic_no,
name,
sex_code,
card_no,
oper_code,
oper_dtime,
clinic_type,
trans_type,
mark_guid,
mark_name,
valid_flag
)
select sys_guid(),
#[app.registry.'myData'.get('CLINIC_NO')] CLINIC_NO,
'' name,
'' sex_code,
'' card_no,
#[app.registry.'myData'.get('OPER_CODE')] oper_code,
sysdate oper_dtime,
#[app.registry.'myData'.get('CLINIC_TYPE')] clinic_type,
#[app.registry.'myData'.get('TRANS_TYPE')] trans_type,
#[app.registry.'myData'.get('MARK_GUID')] mark_guid,
t.mark_name mark_name,
1 valid_flag
from msg_com_mark t
where t.guid = #[app.registry.'myData'.get('MARK_GUID')]]]></db:parameterized-query>

</db:insert>
<json:object-to-json-transformer doc:name="Object to JSON"/>

</sub-flow>
<flow name="rest_PatQuery" doc:description="http://localhost:8333/soap/querypat?clinic_no=123&amp;clinic_type=1&amp;range=ALL">
<http:listener config-ref="HTTP_Listener_Configuration" path="/querypat" doc:name="HTTP" doc:description="http://localhost:8333/soap/querypat?clinic_no=123&amp;clinic_type=1&amp;range=ALL"/>
<db:select config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select a.clinic_no,a.clinic_type,a.oper_code,to_char(a.oper_dtime,'yyyy-mm-dd hh24:mi:ss') oper_dtime,a.mark_guid,b.mark_name,b.mark_color,b.mark_content,b.mark_icon,b.mark_range,b.remark
from MSG_BIZ_PATMARK a
inner join msg_com_mark b on a.mark_guid = b.guid
where
a.clinic_no = #[message.inboundProperties['http.query.params']['clinic_no']]
and a.clinic_type = #[message.inboundProperties['http.query.params']['clinic_type']]
and (('VALID'= #[message.inboundProperties['http.query.params']['range']] and a.trans_type = 1 and a.valid_flag =1)
or 'ALL' = #[message.inboundProperties['http.query.params']['range']])
order by oper_dtime]]></db:parameterized-query>
</db:select>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="rest_MarkDictOper">
<http:listener config-ref="HTTP_Listener_Configuration" path="/markcommit" doc:name="HTTP"/>
<custom-transformer class="com.test.MsgComMarkTF" doc:name="Java"/>
<choice doc:name="Choice">
<when expression="#[app.registry.'myData1'.get('GUID') == '']">
<db:insert config-ref="Oracle_Configuration" doc:name="Insert_msg_com_mark">
<db:parameterized-query><![CDATA[insert into msg_com_mark
(
guid,
mark_name,
mark_color,
mark_content,
mark_icon,
mark_range,
remark)
select
sys_guid(),
#[app.registry.'myData1'.get('MARK_NAME')],
#[app.registry.'myData1'.get('MARK_COLOR')],
#[app.registry.'myData1'.get('MARK_CONTENT')],
#[app.registry.'myData1'.get('MARK_ICON')],
#[app.registry.'myData1'.get('MARK_RANGE')],
#[app.registry.'myData1'.get('REMARK')]
from dual]]></db:parameterized-query>
</db:insert>
</when>
<otherwise>
<db:update config-ref="Oracle_Configuration" doc:name="Update_msg_com_mark">
<db:parameterized-query><![CDATA[UPDATE msg_com_mark
SET MARK_NAME = #[app.registry.'myData1'.get('MARK_NAME')],
MARK_COLOR = #[app.registry.'myData1'.get('MARK_COLOR')],
MARK_CONTENT = #[app.registry.'myData1'.get('MARK_CONTENT')],
MARK_ICON = #[app.registry.'myData1'.get('MARK_ICON')],
MARK_RANGE = #[app.registry.'myData1'.get('MARK_RANGE')],
REMARK = #[app.registry.'myData1'.get('REMARK')]
WHERE GUID = #[app.registry.'myData1'.get('GUID')]]]></db:parameterized-query>
</db:update>
</otherwise>
</choice>
<json:object-to-json-transformer doc:name="Object to JSON"/>


</flow>
<flow name="rest_MarkDictQuery" doc:description="http://localhost:8333/soap/querymark">
<http:listener config-ref="HTTP_Listener_Configuration" path="/querymark" doc:name="HTTP"/>
<db:select config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select guid,
mark_name,
mark_color,
mark_content,
mark_icon,
mark_range,
remark from msg_com_mark]]></db:parameterized-query>
</db:select>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
</mule>

posted on 2018-06-03 13:27  巍巍之道  阅读(184)  评论(0编辑  收藏  举报

导航