|
Hi,
I have a route that returns a bean, and I would like to call a method in the bean that was returned (which isn't in the registry). I've been looking at the bean binding documentation but I didn't find this scenario. Bellow is a sample code: <bean id="myBean" class="com.MyBean"> </bean> <route> <from uri="direct:start" /> <to ref="myBean" method="getBean" /> <to ref="myReturnedBean" method="doSomething" /> </route> class MyBean { MyReturnedBean getBean () { return new MyReturnedBean(); } } class MyReturnedBean { void doSomething() { } } I really appreciate your help. |
|
On Mon, Apr 30, 2012 at 9:26 PM, Purple Tea <[hidden email]> wrote:
> Hi, > > I have a route that returns a bean, and I would like to call a method in the > bean that was returned (which isn't in the registry). > I've been looking at the bean binding documentation but I didn't find this > scenario. > > Bellow is a sample code: > > <bean id="myBean" class="com.MyBean"> > </bean> > > <route> > <from uri="direct:start" /> > <to ref="myBean" method="getBean" /> > > <to ref="myReturnedBean" method="doSomething" /> > </route> > You would need to use a dynamic language or simple language to invoke a method on the message body. And use the message translator EIP For example the simple language supports OGNL like method invocation chains. See more at http://camel.apache.org/simple And for bean parameter bindings you can see details at http://camel.apache.org/bean-binding.html So you should be able to do something a like this: <route> <from uri="direct:start" /> <to ref="myBean" method="getBean" /> <transform><simple>${body.doSomething}</simple></transform> </route> > > class MyBean { > MyReturnedBean getBean () { > return new MyReturnedBean(); > } > } > > class MyReturnedBean { > void doSomething() { > } > } > > I really appreciate your help. > > -- > View this message in context: http://camel.465427.n5.nabble.com/Invoking-a-bean-returned-by-a-previous-bean-invocation-tp5676696.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ |
|
Thank you for your reply.
Does the simple language also allows us to send multiple method parameters like the new features offered in the bean binding? |
|
On Tue, May 1, 2012 at 8:11 PM, Purple Tea <[hidden email]> wrote:
> Thank you for your reply. > > Does the simple language also allows us to send multiple method parameters > like the new features offered in the bean binding? > Yes, just provide a method signature such with the parameters separated by comma. There is a limitation on what can be passed in as parameters, but thats documented on that bean binding page <simple>${body.doSomething("Hi Camel", ${header.bar}, true)}</simple> For example from an unit test public void testBodyOgnlOnStringWithOgnlParams() throws Exception { exchange.getIn().setBody("Camel"); exchange.getIn().setHeader("max", 4); exchange.getIn().setHeader("min", 2); assertExpression("${body.substring(${header.min}, ${header.max})}", "me"); } > > -- > View this message in context: http://camel.465427.n5.nabble.com/Invoking-a-bean-returned-by-a-previous-bean-invocation-tp5676696p5678641.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ |
This seems to only work when the parameters are simple values such as strings, integers, etc. For example: public void testBodyOgnlOnAnimalWithOgnlParams() throws Exception { exchange.getIn().setBody(new Animal("tiger", 13)); exchange.getIn().setHeader("friend", new Animal("donkey", 4)); assertExpression("${body.setFriend(${header.friend})}", null); } Fails with org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.language.simple.SimpleTest.Animal with value donkey Is that a known limitation? -- Gavin Scott |
|
Gavin,
Type Converters only works with common types, but you can write your own if you need it (ie, Animal). On Thu, May 3, 2012 at 3:24 PM, gavindscott <[hidden email]> wrote: > > Claus Ibsen-2 wrote >> >> On Tue, May 1, 2012 at 8:11 PM, Purple Tea <maisa_manoel@> wrote: >>> Thank you for your reply. >>> >>> Does the simple language also allows us to send multiple method >>> parameters >>> like the new features offered in the bean binding? >>> >> >> Yes, just provide a method signature such with the parameters >> separated by comma. >> There is a limitation on what can be passed in as parameters, but >> thats documented on that bean binding page >> >> <simple>${body.doSomething("Hi Camel", ${header.bar}, true)}</simple> >> [ SNIP ] >> > > This seems to only work when the parameters are simple values such as > strings, integers, etc. For example: > > public void testBodyOgnlOnAnimalWithOgnlParams() throws Exception { > exchange.getIn().setBody(new Animal("tiger", 13)); > exchange.getIn().setHeader("friend", new Animal("donkey", 4)); > assertExpression("${body.setFriend(${header.friend})}", null); > } > > Fails with org.apache.camel.NoTypeConversionAvailableException: No type > converter available to convert from type: java.lang.String to the required > type: org.apache.camel.language.simple.SimpleTest.Animal with value donkey > > Is that a known limitation? > > -- > Gavin Scott > > -- > View this message in context: http://camel.465427.n5.nabble.com/Invoking-a-bean-returned-by-a-previous-bean-invocation-tp5676696p5684000.html > Sent from the Camel - Users mailing list archive at Nabble.com. |
|
In reply to this post by gavindscott
On Thu, May 3, 2012 at 8:24 PM, gavindscott <[hidden email]> wrote:
> > Claus Ibsen-2 wrote >> >> On Tue, May 1, 2012 at 8:11 PM, Purple Tea <maisa_manoel@> wrote: >>> Thank you for your reply. >>> >>> Does the simple language also allows us to send multiple method >>> parameters >>> like the new features offered in the bean binding? >>> >> >> Yes, just provide a method signature such with the parameters >> separated by comma. >> There is a limitation on what can be passed in as parameters, but >> thats documented on that bean binding page >> >> <simple>${body.doSomething("Hi Camel", ${header.bar}, true)}</simple> >> [ SNIP ] >> > > This seems to only work when the parameters are simple values such as > strings, integers, etc. For example: > > public void testBodyOgnlOnAnimalWithOgnlParams() throws Exception { > exchange.getIn().setBody(new Animal("tiger", 13)); > exchange.getIn().setHeader("friend", new Animal("donkey", 4)); > assertExpression("${body.setFriend(${header.friend})}", null); > } > > Fails with org.apache.camel.NoTypeConversionAvailableException: No type > converter available to convert from type: java.lang.String to the required > type: org.apache.camel.language.simple.SimpleTest.Animal with value donkey > > Is that a known limitation? > Yes its a limitation currently. I have logged a JIRA https://issues.apache.org/jira/browse/CAMEL-5252 > -- > Gavin Scott > > -- > View this message in context: http://camel.465427.n5.nabble.com/Invoking-a-bean-returned-by-a-previous-bean-invocation-tp5676696p5684000.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com FuseSource Email: [hidden email] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ |
| Powered by Nabble | Edit this page |
