Camel Spring DSL Route:设置http查询参数

时间:2016-10-27 09:33:52

标签: spring http routes apache-camel dsl

我是骆驼新手,在我看来,文档很大但可以更好地构建。所以很难找到你想要的东西。

我的问题:我已经在spring DSL中定义了一个camel路由,用于从camel servlet重定向到另一个http端点。在重定向时,应设置一些http查询参数,如PARAM1:

<route id="bridge">
    <from uri="servlet:bridge" />
    <setHeader headerName="HTTP_QUERY">
        <constant>PARAM1=value1</constant>
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>

重定向有效,但是&#34; TO&#34;端点没有获取参数PARAM1。 我的错误在哪里?

关于jundl

3 个答案:

答案 0 :(得分:2)

要将查询参数发送到http端点,您可以使用HTTP_QUERY标头,如下所示

   <route>
    <from uri="servlet:bridge" />
    <setHeader headerName="HTTP_QUERY">
     <constant>param1=value1&param2=value2</constant>        
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
   </route>

如果您想要一些动态值,例如标头值为value1,则必须使用驼峰简单标记,如下所示

  <route>
    <from uri="servlet:bridge" />
    <setHeader headerName="HTTP_QUERY">
     <simple>param1=${headerNameOfValue1}&param2=value2</simple>        
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
   </route>

希望它有所帮助!

答案 1 :(得分:1)

试试这个http://camel.apache.org/constant.html

<route>
   <from uri="servlet:bridge" />
  <setHeader headerName="PARAM1">
    <constant>value1</constant>        
  </setHeader>
  <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>

答案 2 :(得分:1)

您使用了错误的headerName。如果要在DSL路由中使用Exchange.HTTP_QUERY常量,则需要写入其值。也就是说,您不必编写“ HTTP_QUERY”,而必须编写“ CamelHttpQuery”。看看https://camel.apache.org/maven/current/camel-core/apidocs/constant-values.html

如果您以这种方式更改代码,它将起作用:

<route id="bridge">
    <from uri="servlet:bridge" />
    <setHeader headerName="CamelHttpQuery">
        <constant>PARAM1=value1</constant>
    </setHeader>
    <to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>