git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Camel HeaderFilterStrategy Bean Registration in Spring


Hi,

You don't need to add @Bean annotation on the applyFilterToCamelHeaders
method,
Just keep @Component there should be fine.


Willem Jiang

Twitter: willemjiang
Weibo: 姜宁willem

On Thu, Jul 19, 2018 at 9:22 PM, Peck, Sean <pecks2@xxxxxxxx> wrote:

> I am having difficulty with Spring-Camel getting a HeaderFilterStrategy
> class registered as a Bean so it can be found by the Camel Route. My
> attempts to annotate the HeaderFilterStrategy custom class seem futile...
> so how do I register this thing so it gets found at run time?
>
> I have a camel application with a route utilizing a custom
> HeaderFilterStrategy
> The Strategy Class looks like :
>
> public class HeaderFilter implements HeaderFilterStrategy {
>     @Override
>     public boolean applyFilterToCamelHeaders(String s, Object o, Exchange
> exchange) {
>       return false;
>     }
>
>    @Override
>    public boolean applyFilterToExternalHeaders(String s, Object o,
> Exchange exchange) {
>     return true;
>    }
> }
>
> I register it with camel using a simple registry:
>
>     SimpleRegistry registry = new SimpleRegistry();
>     registry.put("HeaderFilter" ,new HeaderFilter());
>     .
>     .
>     final CamelContext ctx = new DefaultCamelContext(registry);
>
> And I reference it in my Route in
>
> .to("https://myhost/endpoint&headerFilterStrategy=#HeaderFilter";)
>
> And all like Ralphy on Christmas night with his trusty Red Rider BB Gun,
> all is right with the world.
>
> So, now I am trying to take this pure camel app and put it under Spring. I
> make sure all the appropriate Camel, and Spring-Camel and Spring things are
> imported.. However, when I attempt to annotate my HeaderStrategy as a Bean
> for Spring and it fails:
>
> @Component
> public class HeaderFilter implements HeaderFilterStrategy {
>
> @Bean
>   @Override
>   public boolean applyFilterToCamelHeaders(String s, Object o, Exchange
> exchange) {
>     return false;
>   }
>   @Override
>   public boolean applyFilterToExternalHeaders(String s, Object o,
> Exchange exchange) {
>     return true;
>   }
> }
>
> Now when I do this, the IDE basically tells me it can't autowire any of
> the parameters in the method calls because there is more than one bean of
> type String or Object and no beans of type Exchange found..
> At Runtime, Camel does attempt to interpret the route, but throws a
> failure with "No Qualifying bean type of "java.lang.String" available,
> since this is the first parameter in the method call...
> So, How do I get this thing to be able register with annotations
> correctly? Or manually register this bean without it attempting to
> autowire? All I need is the class to be registered as a BEAN so it can be
> found by camel at runtime... Or at least that is what I understand needs to
> happen... so how the heck to I do this?
>
>