无法在骆驼路线中使用标头中的数据

时间:2014-02-21 23:05:32

标签: spring apache-camel

在我的驼峰路线中,我正在尝试设置自定义标头,并将该标头的值设置为正文中包含的数据。此标头稍后在SQL查询中使用,但它无法正常工作。我得到一个异常,似乎SQL查询永远不会得到我的标头的值。这是我的骆驼路线:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring">
<route>
    <from uri="cxf:bean:soapEndpoint"/>
    <log message="${body}"/>
    <setHeader headerName="accountNumber">
        <simple>${body}</simple>
    </setHeader>
    <log message="The header value is ${header.accountNumber}" />
    <to uri="sql:select account_name from hz_cust_accounts where account_number=:#accountNumber"/>
</route>
</camelContext>
<!-- this is the JDBC data source -->
<bean id="OracleDS" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@myserver:1558:mydb" />
    <property name="username" value="someuser" />
    <property name="password" value="somepass" />
</bean>

<!-- configure the Camel SQL component to use the JDBC data source -->
<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
    <property name="dataSource" ref="OracleDS" />
</bean>

<cxf:cxfEndpoint id="soapEndpoint" address="http://localhost:10001/erpsoap"
    serviceClass="apps.vci.camel.erptest.ERPSoapImpl"
    wsdlURL="META-INF/wsdl/GetHzCustDetailsService.wsdl"
    endpointName="s:getHzCustDetailsPort"
    serviceName="s:getHzCustDetailsService"
    xmlns:s="http://apps.vci.camel.erptest" />

</beans>

当数据通过路线时,这就是我得到的错误:

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [select account_name from hz_cust_accounts where account_number=?]; SQL state [99999]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type

就像SQL组件没有得到标题中的值一样。我设置它后记录该值,我确实看到它设置正确,因为我在我的日志中得到了这个:

[               qtp665755841-45] route1                         INFO  The header value is 4089699

任何人都知道为什么会发生这种情况?

由于

1 个答案:

答案 0 :(得分:0)

强制标题accountNumberInteger

<setHeader headerName="accountNumber">
    <simple>${bodyAs(Integer)}</simple>
</setHeader>

有一些类型有速记符号,因此我们可以使用String而不是java.lang.String。它们是:byte [],String,Integer,Long。所有其他类型必须使用其FQN名称,例如org.w3c.dom.Document(Camel documentation)。