在我的駱駝路線中,我試圖設置一個自定義標題並將該標題的值設置爲正文中包含的數據。該頭文件稍後在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
任何人有任何想法,爲什麼這會發生在我身上?
感謝
基於這個例子,我會說你正在做的事情是正確的:https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel- sql/src/test/java/org/apache/camel/component/sql/SqlProducerNamedParameterTest.java; h = d593bb16da03d4d6c214cceb8f930d1d22c004b7; hb = HEAD你確定列名是否正確?也許這只是一個SQL列錯字。 – hveiga
是的,它似乎是一個SQL錯誤的種類。您正在打印標題值。 – Namphibian
你的例子沒有駱駝工作嗎?如果是的話,你檢查了SQL語句,特別是它的綁定參數值嗎? –