I need to set Body by new Pojo each time the router called

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

I need to set Body by new Pojo each time the router called

ayman.elshayb
Hello All,

I have a problem . I have a sub router . The router get in the body an object with type x  then i need to convert x to y then i need to do series of changes to x and return back x . To do this , i have done the following DSL


from("direct:Subrouter").setExchangePattern(ExchangePattern.InOut)
  .setHeader(ORGINAL_ENTITY,body()).setBody().constant(new Y())
                                                .bean(changeYbean,"transform");

The problem is that ".setBody().Constant(new Y())" adds extra object each time the router is called by new X and did not forget the old Y so in the end i got a list of Ys

For example if the subrouter is called 4 times each time with new X . the last called  will return List of Y not one Y

Note: i use spring boot as bean context and i need Y object  for each call

Thanks,
Ayman El Shayeb
Reply | Threaded
Open this post in threaded view
|

Re: I need to set Body by new Pojo each time the router called

souciance
Why don't you do the new Y() part in your changeYbean?

On Wed, Mar 15, 2017 at 12:23 PM, ayman.elshayb [via Camel] <[hidden email]> wrote:
Hello All,

I have a problem . I have a sub router . The router get in the body an object with type x  then i need to convert x to y then i need to do series of changes to x and return back x . To do this , i have done the following DSL


from("direct:Subrouter").setExchangePattern(ExchangePattern.InOut)
  .setHeader(ORGINAL_ENTITY,body()).setBody().constant(new Y())
                                                .bean(changeYbean,"transform");

The problem is that ".setBody().Constant(new Y())" adds extra object each time the router is called by new X and did not forget the old Y so in the end i got a list of Ys

For example if the subrouter is called 4 times each time with new X . the last called  will return List of Y not one Y

Note: i use spring boot as bean context and i need Y object  for each call

Thanks,
Ayman El Shayeb


If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/I-need-to-set-Body-by-new-Pojo-each-time-the-router-called-tp5795518.html
To start a new topic under Camel - Users, email [hidden email]
To unsubscribe from Camel - Users, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: I need to set Body by new Pojo each time the router called

Claus Ibsen-2
In reply to this post by ayman.elshayb
A constant is a one time constant. So if you want a new instance, you
need to use a bean or process and return a newly created instance

On Wed, Mar 15, 2017 at 12:23 PM, ayman.elshayb <[hidden email]> wrote:

> Hello All,
>
> I have a problem . I have a sub router . The router get in the body an
> object with type x  then i need to convert x to y then i need to do series
> of changes to x and return back x . To do this , i have done the following
> DSL
>
>
> from("direct:Subrouter").setExchangePattern(ExchangePattern.InOut)
>   .setHeader(ORGINAL_ENTITY,body()).setBody().constant(new Y())
>                                                 .bean(changeYbean,"transform");
>
> The problem is that ".setBody().Constant(new Y())" adds extra object each
> time the router is called by new X and did not forget the old Y so in the
> end i got a list of Ys
>
> For example if the subrouter is called 4 times each time with new X . the
> last called  will return List of Y not one Y
>
> Note: i use spring boot as bean context and i need Y object  for each call
>
> Thanks,
> Ayman El Shayeb
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/I-need-to-set-Body-by-new-Pojo-each-time-the-router-called-tp5795518.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2