Search code examples
javaspringapache-camelenterprise-integration

Apache Camel Java DSL pass class parameter to bean method


I am using Camel 2.13.1 I want to pass a class as parameter to one of my methods in the bean

Can I do something like

In Route
    --
     .beanRef("someSpringBeanRef","someMethod(${body},com.test.TestObject)")
    --

And in Bean
      public Object someMethod(String testBody, Class type){

I know I can send the qualified class name in header and use it within the bean but it doesn't feel too right. Are there any other alternatives?

I saw this link but it did not work for me Apache Camel - Spring DSL - Pass String argument to bean method


Solution

  • A method parameter of type Class is not supported. From the Camel documentation:

    Camel uses the following rules to determine if it's a parameter value in the method option

    • The value is either true or false which denotes a boolean value
    • The value is a numeric value such as 123 or 7
    • The value is a String enclosed with either single or double quotes
    • The value is null which denotes a null value
    • It can be evaluated using the Simple language, which means you can use, e.g., body, header.foo and other Simple tokens. Notice the tokens must be enclosed with ${ }.