简体   繁体   English

如何替换 DefaultHeaderFilterStrategy

[英]How to replace DefaultHeaderFilterStrategy

I know I can set the HeaderFilterStrategy for a particular end-point, but...我知道我可以为特定端点设置 HeaderFilterStrategy,但是......

How does one override the DefaultHeaderFilterStrategy with a custom strategy that will apply to all routes?如何使用适用于所有路由的自定义策略覆盖DefaultHeaderFilterStrategy

We are using Camel's Servlet Listener.我们正在使用 Camel 的 Servlet 监听器。 Can we supply something in the configuration (documented here) to replace the DefaultHeaderFilterStrategy with our own class?我们可以在配置中提供一些东西(在此处记录)以用我们自己的 class 替换DefaultHeaderFilterStrategy吗?

You could create your own implementation of HeaderFilterStrategy class and refer to it in the endpoint configuration您可以创建自己的HeaderFilterStrategy class 实现并在端点配置中引用它

<lang:groovy id="MyHeaderFilter">
    <lang:inline-script>
        import org.apache.camel.Exchange
        import org.apache.camel.spi.HeaderFilterStrategy

        class MyHeaderFilter implements HeaderFilterStrategy {
            public boolean applyFilterToCamelHeaders(String headerName, Object headerValue, Exchange exchange) {
                return false
            }
            public boolean applyFilterToExternalHeaders(String headerName, Object headerValue, Exchange exchange) {
                return !(headerName in ['desirableHeaderName'])
}
        }
    </lang:inline-script>
</lang:groovy>

and then接着

<to uri="activemq:dummy?headerFilterStrategy=#MyHeaderFilter"/>

UPD. UPD。
It is also possible to set custom header filter to the whole component也可以为整个组件设置自定义 header 过滤器

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
  <property name="headerFilterStrategy" ref="MyHeaderFilter"/>
</bean>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM