我正在使用Apache Camel 的 SQL Stored Procedure Component调用 Oracle 存储过程。
我正在调用的存储过程有几个 OUT 参数,它们都作为字符串在 BODY 中返回,例如:
{param1=0, param2=-, param3=<?xmlversion="1.0"?><Client><Item><PHONE>1234567890</PHONE></Item></Client>}
目前我正在标记/解析 BODY 以便能够提取参数。这可行,但效率不高(并且容易出错)。
我的代码如下所示:
...
<bean id="od" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driver">
<bean class="oracle.jdbc.OracleDriver"/>
</property>
<property name="url" value="${connURL}"/>
</bean>
...
<camel:to uri="sql-stored:PACKAGE.STORED_PROCEDURE(VARCHAR ${exchangeProperty.param0},OUT VARCHAR param1,OUT VARCHAR param2,OUT VARCHAR param3,OUT VARCHAR param4)?dataSource=od">
...
<!-- I tried this but "abc" always has no value -->
<camel:setHeader headerName="abc">
<camel:description layoutX="280" layoutY="20" layoutWidth="120" layoutHeight="120"/>
<camel:simple>$simple{header.param3}</camel:simple>
</camel:setHeader>
<!-- This is how I parse the BODY (inefficient!) -->
<camel:groovy><![CDATA[
def outParams = [
param1: "NO_VALUE",
param2: "NO_VALUE",
param3: "NO_VALUE",
param4: "NO_VALUE"
]
def retERR = "yes"
def t = ""
def bd = exchange.getIn().getBody(String.class)
try {
def varList = bd.replaceAll("\n","").replaceAll("^\\{","").replaceAll("\\}\$","")
varList = varList.tokenize(',')
for (keyVal in varList) {
keyVal = keyVal.trim()
i = keyVal.indexOf('=')
outParams[keyVal.take(i)] = keyVal.substring(i+1)
}
retERR = "no"
} catch(all) {
retERR = "yes"
}
exchange.setProperty("outParams",outParams)
exchange.setProperty("retERR",retERR)
]]>
</camel:groovy>
...
<camel:to uri="bean:varpop?method=MYBEAN('outParams,retERR,param3,abc')">
<camel:description layoutX="20" layoutY="470" layoutWidth="120" layoutHeight="120"/>
</camel:to>
是否有直接访问param1
,param2
等的直接方式而无需解析 BODY?