You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bonnahu <bo...@gmail.com> on 2013/08/20 00:01:35 UTC

Apply change to a route after loading camelcontext xml using GenericApplicationContext

Hi guys,
I have a piece of code below. What I want to do is to load a camelcontext
from a xml file by using
GenericApplicationContext and XmlBeanDefinitionReader. Then I want to make
some change on one route,
for example, setting the autoStartup property to false. At last, start
camelcontext using Main class.
However, for some reason, the changing to the route has not been effective,
the route still starts.
Did I make any mistake here? Thanks a lot!

        GenericApplicationContext ctx = new GenericApplicationContext();
        XmlBeanDefinitionReader xmlReader = new
XmlBeanDefinitionReader(ctx);
        xmlReader.loadBeanDefinitions(new
ClassPathResource("camelcontext.xml"));
        ctx.refresh();
        // get the camelContext by using getBean()
        CamelContext context = (CamelContext) ctx.getBean("mycontextID"); 
        context.getRoute("route1").getRouteContext().setAutoStartup(false);
              
        Main main = new Main();
	main.setApplicationContext(ctx);
	main.enableHangupSupport();
	main.run();

               



--
View this message in context: http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by bonnahu <bo...@gmail.com>.
thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541p5737628.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by Christian Posta <ch...@gmail.com>.
Yep, that should work :)


On Tue, Aug 20, 2013 at 10:26 AM, bonnahu <bo...@gmail.com> wrote:

> Hi Claus,
> If I understand correctly, you are saying adding a property placeholders
> for
> the auto startup option,
>
>  <propertyPlaceholder id="properties"
>                 location="autostartup.properties"
>             xmlns="http://camel.apache.org/schema/spring"/>
>
> In autostartup.properties, define
>
> autostartupOption = true/false
>
>
> Then in the route,  add the autoStartup property like followings?
> <route id="subscribeDsp4Route" autoStartup="{{autostartupOption}}"
> startupOrder="200">
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541p5737615.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by bonnahu <bo...@gmail.com>.
Hi Claus,
If I understand correctly, you are saying adding a property placeholders for
the auto startup option,

 <propertyPlaceholder id="properties"
        	location="autostartup.properties"
            xmlns="http://camel.apache.org/schema/spring"/>    

In autostartup.properties, define

autostartupOption = true/false


Then in the route,  add the autoStartup property like followings?
<route id="subscribeDsp4Route" autoStartup="{{autostartupOption}}"
startupOrder="200">



--
View this message in context: http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541p5737615.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by Claus Ibsen <cl...@gmail.com>.
You can use property placeholders for the auto startup option, then
you can control it using that way. And dont have to change the XML.

On Tue, Aug 20, 2013 at 3:41 PM, bonnahu <bo...@gmail.com> wrote:
> Hi Claus, thanks for your reply! So do think whether there is way to set the
> autoStartup property to a route before the spring code starts the Camel,  if
> I don't want to change the existing camelcontext.xml.
> Thanks again!
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541p5737595.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by bonnahu <bo...@gmail.com>.
Hi Claus, thanks for your reply! So do think whether there is way to set the 
autoStartup property to a route before the spring code starts the Camel,  if
I don't want to change the existing camelcontext.xml. 
Thanks again!



--
View this message in context: http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541p5737595.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by Claus Ibsen <cl...@gmail.com>.
The spring code starts the Camel since you load the app context, call
refresh and getting the bean, etc.
So its already started when you use the Camel main class.

On Tue, Aug 20, 2013 at 2:45 AM, bonnahu <bo...@gmail.com> wrote:
> Hi Christian,
> Thanks for your response. However, I don't understand that why I need to
> stop the route first, since I haven't started the route yet until
> main.run(); Please explain it a little bit more.
>
> thanks
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541p5737544.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by bonnahu <bo...@gmail.com>.
Hi Christian,
Thanks for your response. However, I don't understand that why I need to
stop the route first, since I haven't started the route yet until 
main.run(); Please explain it a little bit more.

thanks





--
View this message in context: http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541p5737544.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Apply change to a route after loading camelcontext xml using GenericApplicationContext

Posted by Christian Posta <ch...@gmail.com>.
You might want to stop the route first.


On Mon, Aug 19, 2013 at 3:01 PM, bonnahu <bo...@gmail.com> wrote:

> Hi guys,
> I have a piece of code below. What I want to do is to load a camelcontext
> from a xml file by using
> GenericApplicationContext and XmlBeanDefinitionReader. Then I want to make
> some change on one route,
> for example, setting the autoStartup property to false. At last, start
> camelcontext using Main class.
> However, for some reason, the changing to the route has not been effective,
> the route still starts.
> Did I make any mistake here? Thanks a lot!
>
>         GenericApplicationContext ctx = new GenericApplicationContext();
>         XmlBeanDefinitionReader xmlReader = new
> XmlBeanDefinitionReader(ctx);
>         xmlReader.loadBeanDefinitions(new
> ClassPathResource("camelcontext.xml"));
>         ctx.refresh();
>         // get the camelContext by using getBean()
>         CamelContext context = (CamelContext) ctx.getBean("mycontextID");
>         context.getRoute("route1").getRouteContext().setAutoStartup(false);
>
>         Main main = new Main();
>         main.setApplicationContext(ctx);
>         main.enableHangupSupport();
>         main.run();
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Apply-change-to-a-route-after-loading-camelcontext-xml-using-GenericApplicationContext-tp5737541.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta