Gerold Broser
Gerold Broser

Reputation: 14782

Can a Camel Bean be supplied or injected with additional data?

According to Camel's doc the Bean component has a parameters query parameter. If I understand Parameter binding correctly this works with bean handler methods only, right?

Now, with a class:

class MyBean implements Consumer<Object> {

    String id;

    MyBean( final String id ) {
        this.id = id;
    }

    MyBean setId( final String id ) {
        this.id = id;
        return this;
    }

    @Override
    @Handler
    public void accept(Object o) {
        // ...
    }

is it possible to do something like:

  1. setting attributes with an associative array or a Map:
String[] attributes = { "id", "My bean's id.", "attr2", "value2", ... };
.bean( MyBean.class, attributes )
.bean( MyBean.class, Map.of( "id", "My bean's id.", "attr2", "value2", ... ) )
  1. or via (positional) constructor parameters:
.bean( MyBean.class, { "MyBean()", "My bean's id." } )
  1. or by invoking methods:
.bean( MyBean.class, { "setId(\"My bean's id.\")" } )
  1. or with URIs:
.to( "bean:MyBean?id=\"My bean's id.\"&ctorArgs=\"My bean's id.\"&method=setId(\"My bean's id.\")" )

Upvotes: 0

Views: 80

Answers (0)

Related Questions