You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by DRy <di...@itellium.com> on 2009/11/14 19:57:35 UTC

Dynamicly enable or disable parts of a route ...

Hi,

is it possible to do something like this in a RouteBuilder ...

    // Get an object that in null ... or not null!
    // Depends on the weather forecast ... ! :drunk:

    Object object = ObjectGenerator.getObject()

    // Dynamicly enable or disable parts of a route depending on the object

    from(...)
    .choice()
        .when("object != null")
            .to(...)
        .otherwiese()
            .to(...)
    .end();

The aim of this is to dynamicly enable or disable parts of the route by
using boolean expressions based on created objects ...


... DRy

-- 
View this message in context: http://old.nabble.com/Dynamicly-enable-or-disable-parts-of-a-route-...-tp26352814p26352814.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Dynamicly enable or disable parts of a route ...

Posted by DRy <di...@itellium.com>.
Hi,


Claus Ibsen-2 wrote:
> 
> Try with
> 
> final myObject = ...
> 
> Predicate fooIsNotNull = new Predicate() {
>   ...
>    return myObject != null;
> }
> 
> when(fooIsNotNull)
> 

I tried 

        Predicate logBeanIsNotNull = new Predicate() {
            
            public boolean matches(Exchange exchange) {
                
                return logBean != null;
            }
        };

        ...
        .when(logBeanIsNotNull)

and in I've got no exception when it runs in the route-definition. But after
all route definition is done I got an exception 

Exception: java.lang.IllegalArgumentException: bean, ref or beanType must be
specified on: Bean[]
org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException:
bean, ref or beanType must be specified on: Bean[]
	at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1039)
	at
org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:103)
	at
org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:562)
	at
org.springframework.context.event.SimpleApplicationEventMulticaster$1.run(SimpleApplicationEventMulticaster.java:78)
	at
org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
	at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:76)
	at
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:274)
	at
org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:736)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:383)
	at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at
com.itellium.eai.gateway.tillserver.mbean.TillserverGateway.startCamel(TillserverGateway.java:76)
	at
com.itellium.eai.gateway.tillserver.mbean.TillserverGateway.start(TillserverGateway.java:31)
	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
com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:93)
	at
com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:27)
	at
com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:208)
	at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:120)
	at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:262)
	at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
	at
com.itellium.eai.gateway.tillserver.TillserverGatewayStart.main(TillserverGatewayStart.java:63)
Caused by: java.lang.IllegalArgumentException: bean, ref or beanType must be
specified on: Bean[]
	at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:260)
	at
org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:153)
	at
org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:260)
	at
org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:93)
	at
org.apache.camel.impl.DefaultRouteContext.createProcessor(DefaultRouteContext.java:105)
	at
org.apache.camel.model.ExpressionNode.createFilterProcessor(ExpressionNode.java:94)
	at
org.apache.camel.model.WhenDefinition.createProcessor(WhenDefinition.java:69)
	at
org.apache.camel.model.ChoiceDefinition.createProcessor(ChoiceDefinition.java:69)
	at
org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:260)
	at
org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:93)
	at
org.apache.camel.impl.DefaultRouteContext.createProcessor(DefaultRouteContext.java:105)
	at
org.apache.camel.model.OnExceptionDefinition.addRoutes(OnExceptionDefinition.java:134)
	at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:584)
	at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:132)
	at
org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:598)
	at
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1118)
	at
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1035)
	at
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:971)
	at
org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:158)
	at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:55)
	at
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:868)
	at
org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:197)
	at
org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:101)
	... 23 more


... DRy

but somehow 
-- 
View this message in context: http://old.nabble.com/Dynamicly-enable-or-disable-parts-of-a-route-...-tp26352814p26357429.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Dynamicly enable or disable parts of a route ...

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Nov 15, 2009 at 9:13 AM, DRy <di...@itellium.com> wrote:
>
> Hi,
>
>
> Claus Ibsen-2 wrote:
>>
>> Yes using predicates
>>
>> For example the constant used as a predicate will return true if the
>> value != null or if its a string that is "true" or "false".
>>
>> when(constant(myObject));
>>
>> Otherwise you can always use you own predicates.
>> See more here
>> http://davsclaus.blogspot.com/2009/02/apache-camel-and-using-compound.html
>>
>
> I can't do this by using when(constant(myObject)) because constant(myObject)
> no predicate - it a ValueBuilder.
>
> If I use when(constant(myObject).isNotNull()) and myObject is null I'll get
> an exception
>
> Caused by: java.lang.IllegalArgumentException: bean, ref or beanType must be
> specified on: Bean[]
>        at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:260)
>

Try with

final myObject = ...

Predicate fooIsNotNull = new Predicate() {
  ...
   return myObject != null;
}

Predicate fooIsNull = new Predicate() {
  ...
   return myObject == null;
}


when(fooIsNotNull)



>
> ... DRy
> --
> View this message in context: http://old.nabble.com/Dynamicly-enable-or-disable-parts-of-a-route-...-tp26352814p26357254.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Dynamicly enable or disable parts of a route ...

Posted by DRy <di...@itellium.com>.
Hi,


Claus Ibsen-2 wrote:
> 
> Yes using predicates
> 
> For example the constant used as a predicate will return true if the
> value != null or if its a string that is "true" or "false".
> 
> when(constant(myObject));
> 
> Otherwise you can always use you own predicates.
> See more here
> http://davsclaus.blogspot.com/2009/02/apache-camel-and-using-compound.html
> 

I can't do this by using when(constant(myObject)) because constant(myObject)
no predicate - it a ValueBuilder.

If I use when(constant(myObject).isNotNull()) and myObject is null I'll get
an exception

Caused by: java.lang.IllegalArgumentException: bean, ref or beanType must be
specified on: Bean[]
	at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:260)


... DRy
-- 
View this message in context: http://old.nabble.com/Dynamicly-enable-or-disable-parts-of-a-route-...-tp26352814p26357254.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Dynamicly enable or disable parts of a route ...

Posted by Claus Ibsen <cl...@gmail.com>.
On Sat, Nov 14, 2009 at 7:57 PM, DRy <di...@itellium.com> wrote:
>
> Hi,
>
> is it possible to do something like this in a RouteBuilder ...
>
>    // Get an object that in null ... or not null!
>    // Depends on the weather forecast ... ! :drunk:
>
>    Object object = ObjectGenerator.getObject()
>
>    // Dynamicly enable or disable parts of a route depending on the object
>
>    from(...)
>    .choice()
>        .when("object != null")
>            .to(...)
>        .otherwiese()
>            .to(...)
>    .end();
>
> The aim of this is to dynamicly enable or disable parts of the route by
> using boolean expressions based on created objects ...
>
>

Yes using predicates

For example the constant used as a predicate will return true if the
value != null or if its a string that is "true" or "false".

when(constant(myObject));

Otherwise you can always use you own predicates.
See more here
http://davsclaus.blogspot.com/2009/02/apache-camel-and-using-compound.html



> ... DRy
>
> --
> View this message in context: http://old.nabble.com/Dynamicly-enable-or-disable-parts-of-a-route-...-tp26352814p26352814.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus