Apache camel 如何将REST调用的选项作为参数添加到标头?

Apache camel 如何将REST调用的选项作为参数添加到标头?,apache-camel,esb,blueprint-osgi,Apache Camel,Esb,Blueprint Osgi,我正在使用ESB在SQL和REST调用之间路由数据。到目前为止,这一切都很好,但是当我想为REST调用添加选项时。例如: <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <camelContext xmlns="http://camel.apache.org/schema/blueprint">

我正在使用ESB在SQL和REST调用之间路由数据。到目前为止,这一切都很好,但是当我想为REST调用添加选项时。例如:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <propertyPlaceholder id="placeholder"
             location="file:${karaf.home}/etc/nl.test.astron.sql.cfg" />


<restConfiguration bindingMode="json" component="servlet">
            <endpointProperty key="servletName" value="ASTRONServlet" />
        </restConfiguration>

        <rest path="/get/astrondata">
            <get uri="">            
                <to pattern="InOut" uri="direct:get" />         
            </get>
        </rest>

        <route id="get_to_uri">
            <from uri="direct:get"/>
            <setHeader headerName="boundRaMin">
                <simple>70</simple>
            </setHeader>
            <setHeader headerName="boundRaMax">
                <simple>90</simple>
            </setHeader>
            <setHeader headerName="boundDecMin">
                <simple>0</simple>
            </setHeader>
            <setHeader headerName="boundDecMax">
                <simple>30</simple>
            </setHeader>    
            <to uri="sql:{{sql.getDatabase}}?
                outputType=SelectList&amp;
                greedy=true&amp;
                useIterator=false"/>
        </route>
SQL代码是:

sql.getDatabase=SElECT * FROM dbo.astron_data WHERE :#boundRaMin<ra AND 
                ra<:#boundRaMax AND :#boundDecMin<dec AND dec<:#boundDecMax
在这里可以看到,boundRaMin、boundRaMax、boundDecMin、boundDecMax都是在头中设置的,但是我想根据rest调用中定义的选项来设置这些变量。因此,例如以下调用:


应在标题中填入正确的值value1…value4。这些查询参数似乎没有映射到头。

根据camel sql组件,从camel 2.14开始,您可以使用简单的表达式。因此,请尝试将属性占位符sql.getDatabase修改为以下内容:

sql.getDatabase=SELECT * FROM dbo.astron_data WHERE :${header.boundRaMin} < ra AND 
                ra < ${header.boundRaMax} AND ${header.boundDecMin} < dec AND dec < ${header.boundDecMax}

您使用哪种骆驼版本?URL中的查询参数应该映射到驼峰头OOTB,这应该有效。但是,如果删除所有硬编码的头值,您是说它不存在。如果删除硬编码的头,我会得到以下错误:org.apache.camel.RuntimeExchangeException:在消息体或头中找不到键[boundRaMin],在查询中设置命名参数时要使用[从dbo.astron_数据中选择*,其中:?boundRaMincamel版本是2.16.5对我来说,您似乎在试图定义一些默认参数,以便在URI中不提供解释值的情况下使用。Camel的REST-DSL通过定义参数到各自的路由定义。正如Claus进一步提到的,HTTP头和查询p如果没有标题过滤器策略的阻止,参数将自动复制到入站消息标题;但这至少需要2.17.0。我安装了camel 2.17,这确实有效,谢谢:D。