2014-02-21 50 views
0

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

任何人有任何想法,爲什麼這會發生在我身上?

感謝

+0

基於這個例子,我會說你正在做的事情是正確的: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

+0

是的,它似乎是一個SQL錯誤的種類。您正在打印標題值。 – Namphibian

+0

你的例子沒有駱駝工作嗎?如果是的話,你檢查了SQL語句,特別是它的綁定參數值嗎? –

回答

0

強制頭accountNumber是一個Integer

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

存在具有速記符號幾種類型,所以我們可以使用字符串,而不是java.lang.String中。它們是:byte [],String,Integer,Long。所有其他類型必須使用其FQN名稱,例如org.w3c.dom.Document(Camel documentation)。

+0

我試圖給你推薦的變化,但現在當我 $ {bodyAs(整數)}我得到一個索引越界異常運行: java.lang.IndexOutOfBoundsException:指數:0,大小:0 [qtp1583275890-49] PhaseInterceptorChain WARN攔截器{HTTP://apps.vci.camel.erptest} getHzCustDetailsS​​ervice#{HTTP://erptest.camel.vci.apps/} getHzCustDetails已經拋出異常,現在平倉 組織。 apache.cxf.interceptor.Fault –

+0

我想這個問題與你原來的'無效列類型'問題無關。你是否在數據庫選擇後記錄輸出,並且是否返回任何結果?如果結果是好的,我會看一下'ERPSoapImpl'。 –

+0

我在這裏想出了我的問題。我有兩個部分的問題。首先,我確實需要將我的身體轉換爲Integer,如上所示。我的另一個問題是我查詢了一個不存在的帳號。 –