簡體   English   中英

在駱駝路線中使用標題中的數據時遇到麻煩

[英]Having trouble using data from a header in a camel route

在我的駱駝路線中,我試圖設置一個自定義標頭,並將該標頭的值設置為正文中包含的數據。 此標頭稍后在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

有人知道為什么這會發生在我身上嗎?

謝謝

強制標題accountNumberInteger

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

有幾種類型的縮寫符號,因此我們可以使用String代替java.lang.String。 它們是:byte [],String,Integer,Long。 所有其他類型都必須使用其FQN名稱,例如org.w3c.dom.Document( Camel文檔 )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM