Mule ESB:使用XPATH搜索XML时,对象不是正确类型错误

时间:2013-11-24 02:17:17

标签: mule esb

大卫,

再次发送您的配置,提前感谢您的输入:

<flow name="IntegrationFlow" doc:name="IntegrationFlow">
        <jdbc-ee:inbound-endpoint queryTimeout="-1" doc:name="Database" connector-ref="jdbcConnector" queryKey="selectAll" pollingFrequency="10000">
            <jdbc-ee:transaction action="NONE"/>
        </jdbc-ee:inbound-endpoint>
        <logger message="************Payload is #[message.payload]*************" level="INFO" doc:name="Logger"/>
        <logger message="************Payload is #[message.payload.destination]*************" level="INFO" doc:name="Logger"/>
        <logger message="************Payload is #[message.payload.price]*************" level="INFO" doc:name="Logger"/>
         <foreach doc:name="Foreach">
            <choice doc:name="Choice">
                <when expression="#[message.payload.price > 750]"> 
                   <!--   <when expression="#[message.payload.price > 750]"> -->
                        <processor-chain doc:name="Processor Chain">
                        <jdbc-ee:maps-to-xml-transformer doc:name="Maps to XML"/>
                        <jms:outbound-endpoint queue="queue1" connector-ref="jmsConnector" doc:name="JMS"/>
                    </processor-chain>
                </when>
                <otherwise>
                    <custom-transformer returnClass="java.util.List" class="org.mule.confluex.java.MapToListTransformer" doc:name="Java"/>
                    <logger message="Payload is #[message.payload]" level="INFO" doc:name="Logger1"/>
                    <jdbc-ee:maps-to-csv-transformer mimeType="text/plain" delimiter="," mappingFile="C:\Downloads\Temp\mapping.xml" doc:name="Maps to CSV"/>
                    <logger message="CSV Payload is #[message.payload]" level="INFO" doc:name="Logger2"/>
                    <file:outbound-endpoint path="C:\Downloads\toAmazon" responseTimeout="10000" mimeType="text/plain" connector-ref="fileConnector" doc:name="File"/>
                    <s3:create-object config-ref="Amazon_S3" bucketName="confluexdemo" contentType="text/plain" key="*.*" doc:name="Amazon S3"/>
                </otherwise>
            </choice>
        </foreach>
    </flow>

这是运行日志:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'ConfluexDemo'                               +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2013-11-24 19:18:32,563 [[ConfluexDemo].IntegrationFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ************Payload is {DESTINATION=SFO, PRICE=300, ID=0}*************
INFO  2013-11-24 19:18:32,563 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.api.processor.LoggerMessageProcessor: ************Payload is {DESTINATION=MLT, PRICE=1200, ID=1}*************
INFO  2013-11-24 19:18:32,611 [[ConfluexDemo].IntegrationFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ************Payload is SFO*************
INFO  2013-11-24 19:18:32,611 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.api.processor.LoggerMessageProcessor: ************Payload is MLT*************
INFO  2013-11-24 19:18:32,658 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.api.processor.LoggerMessageProcessor: ************Payload is 1200*************
INFO  2013-11-24 19:18:32,658 [[ConfluexDemo].IntegrationFlow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: ************Payload is 300*************
ERROR 2013-11-24 19:18:32,704 [[ConfluexDemo].IntegrationFlow.stage1.03] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Execution of the expression "message.payload.price > 750" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: could not access: price; in class: java.lang.String]
[Near : {... message.payload.price > 750 ....}]
             ^
[Line: 1, Column: 1] (org.mvel2.PropertyAccessException)
  org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:690 (null)
2. Execution of the expression "message.payload.price > 750" failed. (org.mule.api.expression.ExpressionRuntimeException)
  org.mule.el.mvel.MVELExpressionLanguage:213 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3. Execution of the expression "message.payload.price > 750" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.MessagingException)
  org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
[Error: could not access: price; in class: java.lang.String]
[Near : {... message.payload.price > 750 ....}]
             ^
[Line: 1, Column: 1]
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:690)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanPropertyAO(ReflectiveAccessorOptimizer.java:472)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:374)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

从我的角度来看,当我打印出它时,它看起来像是Map Payload,当我点击'表达时'时,它似乎似乎读了一个字符串。希望这应该给出完整的图片。如果还有其他需要,请告诉我。

为了完成,我还包括JDBC定义:

<spring:beans> 
    <spring:bean id="SetupDatabaseNotificationListener" class="org.mule.confluex.database.SetupDatabaseNotificationListener"></spring:bean>  
      <spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown"> 
       <spring:property name="driverName" value="org.apache.derby.jdbc.EmbeddedDriver"></spring:property>  
        <spring:property name="url" value="jdbc:derby:memory:muleEmbeddedDB;create=true"></spring:property>  
     </spring:bean> 
 </spring:beans>

 <notifications> 
    <notification event="CONTEXT"></notification>  
    <notification-listener ref="SetupDatabaseNotificationListener"></notification-listener>  
 </notifications>

 <jdbc-ee:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource" doc:name="Database"  queryTimeout="-1" transactionPerMessage="false" validateConnections="true">
     <jdbc-ee:query key="selectAll" value="Select * from PriceTickets"></jdbc-ee:query>

 </jdbc-ee:connector>

关心 小号

1 个答案:

答案 0 :(得分:0)

错误很明显:您正在将一个String传递给foreach处理器,而不是可以迭代的东西(Iterator,Collection等)。