You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Craig McDaniel <cp...@gmail.com> on 2011/12/12 17:48:01 UTC
Scala DSL - Calling Spring beans as predicates
I am trying to do something like
when (_.bean("myBean")) {
}
"myBean" has an (Exchange => Boolean) method, but the bean binding isn't
finding it. My bean is injected with database resources and such, thus I
can't really use a simpler scala-style predicate. It also has several other
methods which I am referencing later in my routes using
to("bean:myBean?method=foo").
Unfortunately, the scala DSL does not have a bean(ref, method) version to
work with. I am trying to avoid injecting my bean directly into my route
class, but perhaps that is the best solution in this case. Any thoughts?
--
View this message in context: http://camel.465427.n5.nabble.com/Scala-DSL-Calling-Spring-beans-as-predicates-tp5068888p5068888.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Scala DSL - Calling Spring beans as predicates
Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Dec 14, 2011 at 4:41 PM, Craig McDaniel <cp...@gmail.com> wrote:
>
> Claus Ibsen-2 wrote
>>
>> On Mon, Dec 12, 2011 at 5:53 PM, Craig McDaniel <cpmcdaniel@> wrote:
>>> I guess I should clarify that I'm getting an
>>> AmbiguousMethodCallException,
>>> not that the bean binding can't see the method.
>>>
>>
>> We can use help on the Scala DSL. Maybe we could add a method so you
>> can invoke a bean from the Scala predicates.
>>
>> However can you just do as in Java DSL
>>
>> when().method("myBean") instead?
>>
>
> The only way I can figure to do this is to make this one whole route a Java
> DSL route by using the inherited "builder" reference to the underlying Java
> RouteBuilder. It looks like this:
>
> builder.from("quartz://feeds/carbon?cron=0+00+8+?+*+2-6")
> .choice.when.method("myBean", "myMethod").to("mock:end")
>
> - or -
>
> builder.from("quartz://feeds/carbon?cron=0+00+8+?+*+2-6")
> .choice.when(builder.beanRef("myBean", "myMethod")).to("mock:end")
>
> The latter is more semantically similar to what I was trying to do.
>
> It looks rather simple to add this to the Scala DSL, so I think I'll take a
> stab at it. The DSL will look something like this:
>
> when (_.bean("myBean", "myMethod")) { ... }
> when (_.bean(myClass, "myMethod")) { ... }
> when (_.bean(myObj, "myMethod")) { ... }
>
> I think we should also add these to the DSL trait so the same pattern can be
> used by all of the *Definition wrappers. So something like this would also
> be supported:
>
> "direct:foo" bean("myBean", "myMethod")
>
Craig, great idea.
Please give it a go. We love contributions.
And create a JIRA ticket so we wont forget.
The Scala DSL could use a little love here and there, to make it more
powerful as you would expect from the combination of Scala + Camel.
> --
> View this message in context: http://camel.465427.n5.nabble.com/Scala-DSL-Calling-Spring-beans-as-predicates-tp5068888p5074843.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Scala DSL - Calling Spring beans as predicates
Posted by Craig McDaniel <cp...@gmail.com>.
Claus Ibsen-2 wrote
>
> On Mon, Dec 12, 2011 at 5:53 PM, Craig McDaniel <cpmcdaniel@> wrote:
>> I guess I should clarify that I'm getting an
>> AmbiguousMethodCallException,
>> not that the bean binding can't see the method.
>>
>
> We can use help on the Scala DSL. Maybe we could add a method so you
> can invoke a bean from the Scala predicates.
>
> However can you just do as in Java DSL
>
> when().method("myBean") instead?
>
The only way I can figure to do this is to make this one whole route a Java
DSL route by using the inherited "builder" reference to the underlying Java
RouteBuilder. It looks like this:
builder.from("quartz://feeds/carbon?cron=0+00+8+?+*+2-6")
.choice.when.method("myBean", "myMethod").to("mock:end")
- or -
builder.from("quartz://feeds/carbon?cron=0+00+8+?+*+2-6")
.choice.when(builder.beanRef("myBean", "myMethod")).to("mock:end")
The latter is more semantically similar to what I was trying to do.
It looks rather simple to add this to the Scala DSL, so I think I'll take a
stab at it. The DSL will look something like this:
when (_.bean("myBean", "myMethod")) { ... }
when (_.bean(myClass, "myMethod")) { ... }
when (_.bean(myObj, "myMethod")) { ... }
I think we should also add these to the DSL trait so the same pattern can be
used by all of the *Definition wrappers. So something like this would also
be supported:
"direct:foo" bean("myBean", "myMethod")
--
View this message in context: http://camel.465427.n5.nabble.com/Scala-DSL-Calling-Spring-beans-as-predicates-tp5068888p5074843.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Scala DSL - Calling Spring beans as predicates
Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Dec 12, 2011 at 5:53 PM, Craig McDaniel <cp...@gmail.com> wrote:
> I guess I should clarify that I'm getting an AmbiguousMethodCallException,
> not that the bean binding can't see the method.
>
We can use help on the Scala DSL. Maybe we could add a method so you
can invoke a bean from the Scala predicates.
However can you just do as in Java DSL
when().method("myBean") instead?
> --
> View this message in context: http://camel.465427.n5.nabble.com/Scala-DSL-Calling-Spring-beans-as-predicates-tp5068888p5068910.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Scala DSL - Calling Spring beans as predicates
Posted by Craig McDaniel <cp...@gmail.com>.
I guess I should clarify that I'm getting an AmbiguousMethodCallException,
not that the bean binding can't see the method.
--
View this message in context: http://camel.465427.n5.nabble.com/Scala-DSL-Calling-Spring-beans-as-predicates-tp5068888p5068910.html
Sent from the Camel - Users mailing list archive at Nabble.com.