【问题标题】:Camel how to bypass request header from entering to http dsl component request?Camel如何绕过请求头进入http dsl组件请求?
【发布时间】:2021-01-30 10:23:09
【问题描述】:

我遇到以下骆驼 http 请求问题。我想保留 url 查询字符串参数的值,而不将其传递给需要在路由上完成的另一个 http 请求。 http请求外部api处理数据后需要该值。下面是对问题的澄清:

rest("/api")//We get requests as /camel/api?param1=xyz...
    .get()
        .route()
        .setHeader(Exchange.HTTP_METHOD, constant("GET"))
        .setHeader("Accept-Encoding", constant("gzip"))
        .setHeader("Accept", constant("*/*"))
        .removeHeader(Exchange.HTTP_URI)//Remove this
        //How do I prevent the {header.param1} from being passed to the following http request but still be able to use it after the request on the route?
        .to("https://someapi.org/api/...")
        //To process the result, we need the original {header.param1} value from the request to this /camel/api endpoint

    .endRest();

实现这一目标的正确方法是什么?

【问题讨论】:

标签: http apache-camel query-string


【解决方案1】:

如果您收到仅在当前路由中需要且不应传递到任何其他端点的参数,您也可以将它们复制到to Exchange propertiesdelete the headers

与消息头相比,Camel Exchange 属性不会传播到路由,并且当消息到达当前路由的末端时,它们会与 Exchange 一起被删除。

.setProperty("param1", header("param1")) // create property from header
.removeHeader("param1") // remove the header

这是一种非常明确和透明的方法,但您必须在需要的任何地方进行。因此,它适用于您想要明确说明的特殊情况

另一方面,HeaderFilterStrategy 可防止将特定标头(基于模式)发送到您配置的端点。因此,非常适合一般标头规则,您希望将其应用于特定类型的所有端点(例如所有 HTTP 端点)。

【讨论】:

    猜你喜欢
    • 2010-09-24
    • 1970-01-01
    • 2016-12-28
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多