我想从数据库中选择记录并在mule
.
我的方法是使用 Spring bean 获取记录并将其传递给hashmap
然后返回hashmap
并将其保存在会话变量中。
目前收到此错误:
Message : Execution of the expression "message.payload.getServiceCodes()" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: HashMap
Code : MULE_ERROR--2
它有更好的方法吗?或者我做错了什么?
我的配置 XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:xm="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" 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" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.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/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"></jms:activemq-connector>
<xm:jaxb-context name="myJaxb" doc:name="myJaxb" packageNames="com.test.jaxb"></xm:jaxb-context>
<spring:beans>
<spring:bean id="springDataSource" name="Bean" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<spring:property name="url" value="jdbc:mysql://localhost:3306/muledb"></spring:property>
<spring:property name="maxActive" value="30"></spring:property>
<spring:property name="removeAbandoned" value="true"></spring:property>
<spring:property name="driverClassName" value="com.mysql.jdbc.Driver"></spring:property>
<spring:property name="initialSize" value="20"></spring:property>
<spring:property name="username" value="root"></spring:property>
</spring:bean>
</spring:beans>
<quartz:connector name="quartzConnector" doc:name="Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName" value="MuleScheduler1"></quartz:factory-property>
<quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool"></quartz:factory-property>
<quartz:factory-property key="org.quartz.threadPool.threadCount" value="3"></quartz:factory-property>
<quartz:factory-property key="org.quartz.scheduler.rmi.proxy" value="false"></quartz:factory-property>
<quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false"></quartz:factory-property>
<quartz:factory-property key="org.quartz.jobStore.class" value="org.quartz.simpl.RAMJobStore"></quartz:factory-property>
</quartz:connector>
<jdbc-ee:mysql-data-source name="MySQL_Data_Source" user="root" password="" url="jdbc:mysql://localhost:3306/muledb" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"></jdbc-ee:mysql-data-source>
<jdbc-ee:connector name="Database" dataSource-ref="MySQL_Data_Source" validateConnections="true" transactionPerMessage="false" queryTimeout="-1" pollingFrequency="0" doc:name="Database"></jdbc-ee:connector>
<!-- <flow name="JMSMessageFlow1" doc:name="JMSMessageFlow1" >
<jdbc-ee:inbound-endpoint queryKey="FirstUpdate" queryTimeout="-1" connector-ref="Database" doc:name="Database" pollingFrequency="0">
<jdbc-ee:query key="FirstUpdate" value="SELECT * FROM gcp_txn_log WHERE PROCESSED= 'Y'"></jdbc-ee:query>
<jdbc-ee:query key="FirstUpdate.ack" value="update gcp_txn_log set PROCESSED='N' where service_id = #[map-payload:service_id]"></jdbc-ee:query>
</jdbc-ee:inbound-endpoint>
<logger level="INFO" doc:name="Logger"/>
</flow> -->
<!-- <flow name="JMSMessageFlow2" doc:name="JMSMessageFlow2">
<jdbc-ee:inbound-endpoint queryKey="SelectAll" queryTimeout="-1" connector-ref="Database" doc:name="Database" pollingFrequency="0">
<jdbc-ee:transaction action="ALWAYS_BEGIN"></jdbc-ee:transaction>
<jdbc-ee:query key="SelectAll" value="SELECT * FROM gcp_txn_log WHERE PROCESSED= 'N'"></jdbc-ee:query>
<jdbc-ee:query key="SelectAll.ack" value="update gcp_txn_log set PROCESSED='Y' where service_id = #[map-payload:service_id] "></jdbc-ee:query>
</jdbc-ee:inbound-endpoint>
<xm:object-to-xml-transformer doc:name="Object to XML"></xm:object-to-xml-transformer>
<file:outbound-endpoint path="C:\Users\FASYL\Downloads" outputPattern="test#[function:datestamp:dd-MM-yy]_#[function:systime].xml" responseTimeout="10000" doc:name="File"></file:outbound-endpoint>
<jdbc-ee:outbound-endpoint queryKey="FirstUpdate" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:query key="FirstUpdate" value="update gcp_txn_log set PROCESSED = 'N' WHERE PROCESSED = 'Y'"></jdbc-ee:query>
</jdbc-ee:outbound-endpoint>
</flow> -->
<flow name="JMSMessageFlow3" doc:name="JMSMessageFlow3">
<quartz:inbound-endpoint jobName="job2" repeatInterval="1" repeatCount="0" responseTimeout="10000" doc:name="Quartz" connector-ref="quartzConnector">
<quartz:event-generator-job>
<quartz:payload>Setting Session Variable</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<component class="com.test.SchedulerComponent" doc:name="Java"></component>
<component doc:name="Java">
<singleton-object class="com.test.ServiceDAO">
<property key="dataSource" value-ref="springDataSource" value="null"/>
</singleton-object>
</component>
<message-properties-transformer scope="session" doc:name="Message Properties">
<add-message-property key="serviceDAO" value="#[message.payload]"/>
</message-properties-transformer>
<logger level="INFO" doc:name="Logger" message="#[sessionVars['serviceDAO']['1001']]"/>
</flow>
<!-- <flow name="JMSMessageFlow1" doc:name="JMSMessageFlow1">
</flow> -->
<flow name="JMSMessageFlow4" doc:name="JMSMessageFlow4">
<jms:inbound-endpoint queue="StudioIns" connector-ref="Active_MQ" doc:name="JMS"/>
<xm:jaxb-xml-to-object-transformer jaxbContext-ref="myJaxb" returnClass="com.test.jaxb.MsgContent"></xm:jaxb-xml-to-object-transformer>
<choice doc:name="Choice">
<when expression="payload.getMsgBody().getValue() == 'fundstransfer'" >
<pooled-component doc:name="Java">
<prototype-object class="com.test.PersonComponent">
<property key="dataSource" value-ref="springDataSource" value="null"/>
</prototype-object>
</pooled-component>
</when>
<when expression="#[sessionVars['serviceDAO']['1001'] == 1] ">
<pooled-component doc:name="Java">
<prototype-object class="com.test.SecondPersonComponent">
<property key="dataSource" value-ref="springDataSource" value="null"/>
</prototype-object>
</pooled-component>
</when>
</choice>
<logger message="#[sessionVars['serviceDAO']]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="D:\Documents\MuleStudio\workspace\jms_amq\bin\com\test" outputPattern="new.txt" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>