java Apache Camel:查询参数与标头参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16075758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:49:14  来源:igfitidea点击:

Apache Camel: Query Params vs Header Params

javahttp-headersapache-camelquery-parametersspring-dsl

提问by Chris

I'm currently trying out Apache camel (as routing engine). I understand that Camel supports multiple DSLs and that it could be configured using Java (Java DSL) or Spring (Spring DSL).

我目前正在试用 Apache 骆驼(作为路由引擎)。我知道 Camel 支持多种 DSL,并且可以使用 Java (Java DSL) 或 Spring (Spring DSL) 进行配置。

Question:
I have the following Spring DSL configuration. The idea is that if the incoming request has header-param called "name", it would hit when clause or else to would route the request to google:

问题:
我有以下 Spring DSL 配置。这个想法是,如果传入的请求具有名为“name”的标头参数,它将命中 when 子句,否则将请求路由到谷歌:

 <camel:route>
    <camel:from uri="servlet:///test" />
    <camel:choice>
        <camel:when>
            <camel:header>name</camel:header>
            <camel:transform>
                <camel:simple>Hello ${header.name} how are you?</camel:simple>
            </camel:transform>
        </camel:when>
        <camel:otherwise>
                <camel:to uri="http://www.google.com?bridgeEndpoint=true" />
        </camel:otherwise>
    </camel:choice>
</camel:route>

I expected the above config to work only for Header Param. However, I noticed that this configuration is working even for Query params as shown in the following request:

我希望上述配置仅适用于 Header Param。但是,我注意到此配置甚至适用于查询参数,如以下请求所示:

http://localhost:8080/<war-context>/test?name=test

Is there a way to make sure that it is made to work only for header params ?

有没有办法确保它仅适用于标题参数?

回答by Petter Nordlander

It's well documented herethat query params are copied to exchange headers in the servlet component.

此处有详细记录,查询参数被复制以交换 servlet 组件中的标头。