You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "ayman.elshayb" <ay...@gmail.com> on 2017/03/15 11:23:58 UTC

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

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.

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

Posted by souciance <so...@gmail.com>.
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] <
ml-node+s465427n5795518h21@n5.nabble.com> 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
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/I-need-to-set-Body-by-new-Pojo-each-time-the-router-called-tp5795518p5795551.html
Sent from the Camel - Users mailing list archive at Nabble.com.

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

Posted by Claus Ibsen <cl...@gmail.com>.
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 <ay...@gmail.com> 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