You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Chirag Dewan <ch...@yahoo.in> on 2014/01/09 15:07:37 UTC

Passing a reference of MyObject to a bean

Hi all,

This may be a very straight forward thing,but I was not able to find it.

I have a route like: 

public class MyRouteBuilder extends RouteBuilder
{

    private MyObject myObject;

    public MyRouteBuilder(MyObject myObject)
    {

        this.myObject = myObject;

    }

    @Override
    public void configure() throws Exception
    {

        from( "file:./src/inbox").bean( MyBean.class, "process(myObject)"  ).to( "file:./src/outbox" );

    }

And my bean:

public class MyBean{

public void process(MyObject myObject){

//some processing on myObject

}

Now I want to pass myObject instance to the bean. But somehow I was not able to do that.

Any help is much appreciated.

Thanks.

Chirag

Re: Passing a reference of MyObject to a bean

Posted by Richard Kettelerij <ri...@gmail.com>.
What you can do is store MyObject as a property on the exchange and pass
this property as a variable to the process method. E.g:

from( "file:./src/inbox").setProperty("myobj", constant(myObject)).bean(
MyBean.class, "process(${property.myobj})" ).to( "file:./src/outbox" );

Regards,
Richard


On Thu, Jan 9, 2014 at 3:07 PM, Chirag Dewan <ch...@yahoo.in>wrote:

> Hi all,
>
> This may be a very straight forward thing,but I was not able to find it.
>
> I have a route like:
>
> public class MyRouteBuilder extends RouteBuilder
> {
>
>     private MyObject myObject;
>
>     public MyRouteBuilder(MyObject myObject)
>     {
>
>         this.myObject = myObject;
>
>     }
>
>     @Override
>     public void configure() throws Exception
>     {
>
>         from( "file:./src/inbox").bean( MyBean.class, "process(myObject)"
> ).to( "file:./src/outbox" );
>
>     }
>
> And my bean:
>
> public class MyBean{
>
> public void process(MyObject myObject){
>
> //some processing on myObject
>
> }
>
> Now I want to pass myObject instance to the bean. But somehow I was not
> able to do that.
>
> Any help is much appreciated.
>
> Thanks.
>
> Chirag