0
votes

I have the following bean declaration in camel-context.xml

<bean id="AmbiguousData" class="java.lang.Exception">
    <constructor-arg index="0" type="java.lang.String" value="${body}" />
</bean>

The value of body is set dynamically in camel. From the logs I am able to verify that the body is correct("Ambiguous data found for Test2"), but the value passed to the bean is wrong(${body}).

LOG:

...............

BodyType:String , Body:"Ambiguous data found for IMSI_Test2" , CaughtExceptionType:java.lang.Exception, CaughtExceptionMessage:${body}, StackTrace:java.lang.Exception: ${body} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:121) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280) ..........

How do I resolve this issue?

1

1 Answers

0
votes

The bean in which you are trying to access ${body} shall be created only once when the spring container boots up. At that time you don't have any message rather camel context itself is getting instantiated.

If you want to access Body of a Camel Message then you should use annotations that shall instruct camel to inject message body at runtime.

You need to do something as follows:

import org.apache.camel.Body; public class Foo { public void doSomething(@Body String body) { // do your stuff } and declare this bean in camel-context.