Question

I'm trying to invoke a bean in an interceptor and bind some parameters using the annotations but when the method is invoked it seems like the annotations are ignored and instead the body is bound to the first parameter and the second parameter is null.

I've tried the same XPath using the Blueprint DSL and it works fine so I'm sure this isn't the issue. My method is something like this: -

public void intercept(
        @XPath(value = "//custom:myElement/text()", 
               namespaces = { @NamespacePrefix(prefix = "custom", uri = "http://my.website.com/custom") }, 
               resultType = String.class) String elementValue,
        @Body String body) {
    LOG.info("elementValue {}", elementValue);
    LOG.info("body {}", body);
}

And my interceptor is something like this.

<camel:interceptSendToEndpoint uri="direct:core-service">
    <camel:to uri="bean:interceptor?method=intercept" />
</camel:interceptSendToEndpoint>

When the interceptor is invoked I get a full soap envelope printed for the first log statement and null for the other.

Do I need to do anything to make this bean annotation aware? From the documentation it seems like I just need to add the annotations as above. I can't believe it just doesn't work.

This is running in JBose Fuse so it's camel 2.10 if that makes a difference.

Update

I've tried removing the interceptor from the question and just performing in a simple route and it still doesn't work. Do I need to type cast the incoming String as XML somehow or does it need to be a JAXB entity in the body for @XPath to work?

Était-ce utile?

La solution

There was a a bug in Camel that caused @XPath on bean parameters to not work when using OSGi blueprint AFAIR.

Its fixed in recent Camel released and also in patches for JBoss Fuse available in the customer portal.

As a workaround you can always do the xpath in the bean yourself.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top