Thanks Claus. 
So basically the best way would be to just validate the Strings I use to create 
the endpoints before using them, is that right?

It still crashes with the same exception when I set autoStartup false:
[DEBUG]                -              - Warming up route id: route1 having 
autoStartup=false [main] [o.a.c.s.SpringCamelContext]
But since I'd like to keep autoStartup anyway, there's no point investigating.


Re Christian - catching the exception: Is that what you're suggesting:

        static class BadRouteBuilder extends RouteBuilder {
                @Override
                public void configure() throws Exception {
                        try {
                                from("ftp://illegalUrl:::123";).to("direct:b");
                        } catch(Exception e) {
                                // we don't end up here                         
                        }
                }
        }

I believe that I'd have to catch the exception in the loop in 
DefaultCamelContext.doWarmUpRoutes - meaning I'd have to subclass 
SpringCamelContext, had to override doWarmUpRoutes, and then I'd have to clean 
up all references to the route ... I don't think I want to do that ...  or is 
there a clean, non-error-prone, easy way I'm missing?

Validating the strings before passing them to camel's "from" method sounds a 
lot safer.


Thanks,
Gerda


Here's the stack trace (just in case you're curious - thanks everyone for your 
help!):
java.lang.IllegalStateException: Failed to load ApplicationContext
        at 
org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
        at 
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
        at 
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
        at 
org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
        at 
org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:133)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
        at 
org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:551)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
        at 
org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
        at org.testng.TestRunner.privateRun(TestRunner.java:768)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
        at org.testng.SuiteRunner.run(SuiteRunner.java:240)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
        at org.testng.TestNG.run(TestNG.java:1022)
        at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.springframework.beans.factory.BeanCreationException: Error 
creating bean with name 'camelContext' defined in class 
at.erpel.messaginghub.unit.routes.BadRouteDefinitionTest$ContextConfig: 
Invocation of init method failed; nested exception is 
java.lang.IllegalArgumentException: host must be specified and not empty
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at 
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at 
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
        at 
org.apache.camel.spring.javaconfig.test.JavaConfigContextLoader.loadContext(JavaConfigContextLoader.java:125)
        at 
org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:130)
        at 
org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
        ... 28 more
Caused by: java.lang.IllegalArgumentException: host must be specified and not 
empty
        at org.apache.camel.util.ObjectHelper.notEmpty(ObjectHelper.java:319)
        at 
org.apache.camel.component.file.remote.RemoteFileEndpoint.afterPropertiesSet(RemoteFileEndpoint.java:108)
        at 
org.apache.camel.component.file.remote.RemoteFileEndpoint.createConsumer(RemoteFileEndpoint.java:75)
        at 
org.apache.camel.component.file.remote.RemoteFileEndpoint.createConsumer(RemoteFileEndpoint.java:31)
        at 
org.apache.camel.impl.EventDrivenConsumerRoute.addServices(EventDrivenConsumerRoute.java:65)
        at 
org.apache.camel.impl.DefaultRoute.onStartingServices(DefaultRoute.java:80)
        at org.apache.camel.impl.RouteService.warmUp(RouteService.java:133)
        at 
org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:1925)
        at 
org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1853)
        at 
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1646)
        at 
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1534)
        at 
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1421)
        at 
org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:179)
        at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
        at 
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1389)
        at 
org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:228)
        at 
org.apache.camel.spring.SpringCamelContext.afterPropertiesSet(SpringCamelContext.java:104)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
        ... 40 more

-----Original Message-----
From: Christian Müller [mailto:christian.muel...@gmail.com] 
Sent: Thursday, May 03, 2012 10:17 AM
To: users@camel.apache.org
Subject: Re: Mistakes in endpoints prevent start of camel context

But if you create the route at runtime via the Java DSL, you can catch the 
Exception and handle it in the way you want, e.g. ignore it.

Best,
Christian

On Thu, May 3, 2012 at 9:41 AM, Claus Ibsen <claus.ib...@gmail.com> wrote:

> On Wed, May 2, 2012 at 5:21 PM, Ilger Gerda <il...@big.tuwien.ac.at>
> wrote:
> > Hi all,
> >
> > We have a number of ftp consumer routes that we start based on URLs 
> > read
> from our database.
> > If there's a typo in the URL (e.g. "ftp://localhost::1023";), the 
> > whole
> camelContext won't start.
> > We're using SpringCamelContext.
> >
> > These routes are not essential, we still want our application to 
> > start &
> camel provide all the other routes we defined.
> > Is there a way to ignore routes that throw exceptions upon
> creation/camel context start (have camel behave as if we never added them)?
> >
>
> You can configure the routes with autoStartup=false.
>
> But there is currently no option to say, well I dont care if a route 
> cannot startup.
>
>
> > Thanks,
> > Gerda
>
>
>
> --
> Claus Ibsen
> -----------------
> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com 
> FuseSource
> Email: cib...@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>

Reply via email to