骆驼如何绕过请求头从进入到http dsl组件请求?



我有骆驼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();

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

如果接收到的参数仅在当前路由中需要并且不应该传递到任何其他端点,您也可以将它们复制到Exchange属性并删除头。

与消息头相反,骆驼交换属性不会传播到路由当消息到达当前路由的终点时,它们将与Exchange一起被删除。

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

这是一种非常明确和透明的方式,但是你必须在需要的地方这样做。所以在特殊情况下可以显式使用.

另一方面,HeaderFilterStrategy防止将特定的头(基于模式)发送到您配置它的端点。所以对于一般头文件规则来说非常好你想要应用于特定类型的所有端点(例如所有HTTP端点)。

最新更新