onWhen closure support

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

onWhen closure support

boris.stanojevic

Hi,

I was wondering if we could also add the closure support for the
“onWhen” statement to be easily able to do some fine grained Exception
handling, based on e.g. regular expressions.

So we would have in CoreModelExtensions something like:

ExceptionType.metaClass.onWhen = { String regExp, Closure exceptionExpression ->
    delegate.onWhen(new ValueBuilder(new DelegatingExpression(exceptionExpression)).regex(regExp))
}


And the users would be able to make:

   from('direct:input1')
       .onException(HttpOperationFailedException.class)
           .onWhen('^5(\\d{2})$'){
               it.exception.statusCode
           }

           .maximumRedeliveries(0)
           .handled(true)
           .to('direct:error1')
           .end()
       .onException(HttpOperationFailedException.class)
           .onWhen('^4(\\d{2})$'){
               it.exception.statusCode
           }

           .maximumRedeliveries(0)
           .handled(true)
           .to('direct:error2')
           .end()
       .onException(Exception.class)
           .onWhen('^.+Read$'){
               it.exception.message
           }

           .maximumRedeliveries(5)
           .useExponentialBackoff()
           .handled(true)
           .to('direct:error3')
           .end()
       .to('
http://localhost/test')

Cheers,

Boris

InterComponentWare AG:
Vorstand: Peter Reuschel (Vors.), Norbert Olsacher / Aufsichtsratsvors.: Prof. Dr. Christof Hettich
Firmensitz: 69190 Walldorf, Industriestraße 41 / AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516

_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer
Reply | Threaded
Open this post in threaded view
|

Re: onWhen closure support

mrt1nz
Administrator
[hidden email] schrieb:
>
> Hi,
>
> I was wondering if we could also add the closure support for the
> “onWhen” statement to be easily able to do some fine grained Exception
> handling, based on e.g. regular expressions.
Makes sense to me.
>
> So we would have in CoreModelExtensions something like:
> …
> ExceptionType.metaClass.*onWhen* = { String regExp, Closure
> exceptionExpression ->
> delegate.onWhen(new ValueBuilder(new
> DelegatingExpression(exceptionExpression)).regex(regExp))
> }
This extension limits usage of onWhen to regular expressions. What about
something like that:

ExceptionType.metaClass.onWhen = { Closure predicate ->
delegate.onWhen(new DelegatingCamelPredicate(predicate))
}

Here, the closure implements the predicate and your example can be
written as

. from('direct:input1')
.onException(HttpOperationFailedException.class)
*.onWhen {it.exception.statusCode =~ /^5(\d{2})$/}
* .maximumRedeliveries(0)
...

This example uses the Groovy syntax for regular expressions but you
could write anything returning a boolean.

Any thoughts?

> …
>
> And the users would be able to make:
>
> from('direct:input1')
> .onException(HttpOperationFailedException.class)
> *.onWhen('^5(\\d{2})$'){
> it.exception.statusCode
> }*
> .maximumRedeliveries(0)
> .handled(true)
> .to('direct:error1')
> .end()
> .onException(HttpOperationFailedException.class)
> *.onWhen('^4(\\d{2})$'){
> it.exception.statusCode
> }*
> .maximumRedeliveries(0)
> .handled(true)
> .to('direct:error2')
> .end()
> .onException(Exception.class)
> *.onWhen('^.+Read$'){
> it.exception.message
> }*
> .maximumRedeliveries(5)
> .useExponentialBackoff()
> .handled(true)
> .to('direct:error3')
> .end()
> .to('_http://localhost/test_')
>
> Cheers,
> Boris
> InterComponentWare AG:
> Vorstand: Peter Reuschel (Vors.), Norbert Olsacher /
> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
> Firmensitz: 69190 Walldorf, Industriestraße 41 / AG Mannheim HRB
> 351761 / USt.-IdNr.: DE 198388516
> ------------------------------------------------------------------------
>
> _______________________________________________
> Ipf-developer mailing list
> [hidden email]
> http://gforge.openehealth.org/mailman/listinfo/ipf-developer
>  

_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer
Reply | Threaded
Open this post in threaded view
|

Re: onWhen closure support

mrt1nz
Administrator
... just seen that somwthing went wrong with the formatting of my
example. Here it is again:

. from('direct:input1')
.onException(HttpOperationFailedException.class)
.onWhen {it.exception.statusCode =~ /^5(\d{2})$/}
.maximumRedeliveries(0)
...


Martin Krasser schrieb:

> [hidden email] schrieb:
>>
>> Hi,
>>
>> I was wondering if we could also add the closure support for the
>> “onWhen” statement to be easily able to do some fine grained Exception
>> handling, based on e.g. regular expressions.
> Makes sense to me.
>>
>> So we would have in CoreModelExtensions something like:
>> …
>> ExceptionType.metaClass.*onWhen* = { String regExp, Closure
>> exceptionExpression ->
>> delegate.onWhen(new ValueBuilder(new
>> DelegatingExpression(exceptionExpression)).regex(regExp))
>> }
> This extension limits usage of onWhen to regular expressions. What
> about something like that:
>
> ExceptionType.metaClass.onWhen = { Closure predicate ->
> delegate.onWhen(new DelegatingCamelPredicate(predicate))
> }
>
> Here, the closure implements the predicate and your example can be
> written as
>
> . from('direct:input1')
> .onException(HttpOperationFailedException.class)
> *.onWhen {it.exception.statusCode =~ /^5(\d{2})$/}
> * .maximumRedeliveries(0)
> ...
>
> This example uses the Groovy syntax for regular expressions but you
> could write anything returning a boolean.
>
> Any thoughts?
>
>> …
>>
>> And the users would be able to make:
>>
>> from('direct:input1')
>> .onException(HttpOperationFailedException.class)
>> *.onWhen('^5(\\d{2})$'){
>> it.exception.statusCode
>> }*
>> .maximumRedeliveries(0)
>> .handled(true)
>> .to('direct:error1')
>> .end()
>> .onException(HttpOperationFailedException.class)
>> *.onWhen('^4(\\d{2})$'){
>> it.exception.statusCode
>> }*
>> .maximumRedeliveries(0)
>> .handled(true)
>> .to('direct:error2')
>> .end()
>> .onException(Exception.class)
>> *.onWhen('^.+Read$'){
>> it.exception.message
>> }*
>> .maximumRedeliveries(5)
>> .useExponentialBackoff()
>> .handled(true)
>> .to('direct:error3')
>> .end()
>> .to('_http://localhost/test_')
>>
>> Cheers,
>> Boris
>> InterComponentWare AG:
>> Vorstand: Peter Reuschel (Vors.), Norbert Olsacher /
>> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
>> Firmensitz: 69190 Walldorf, Industriestraße 41 / AG Mannheim HRB
>> 351761 / USt.-IdNr.: DE 198388516
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Ipf-developer mailing list
>> [hidden email]
>> http://gforge.openehealth.org/mailman/listinfo/ipf-developer
>>  
>
>

_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer
Reply | Threaded
Open this post in threaded view
|

Re: onWhen closure support

boris.stanojevic

Hi,

yes I agree, that's even better.

The users should be aware that the Exception Object is sometimes available only as a property ( exchange.properties['org.apache.camel.processor.DeadLetterChannel.FAILURE_HANDLED']) and we should point that out in the docs.

Many thanks,
Cheers,
Boris

Boris Stanojevic | R&D ProfessionalGate
InterComponentWare AG | Industriestraße 41 | 69190 Walldorf (Baden) | Germany
Tel.: +49 (0) 6227 385 557 | Fax: +49 (0) 6227 385 491
[hidden email] |
www.icw.de| www.lifesensor.com


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Neues erfahren, kommentieren, beisteuern: Was es Spannendes
zum Thema Gesundheit, eHealth und LifeSensor gibt, finden Sie
aktuell in unserem Weblog:
www.lifesensor.com/weblog
Treffen Sie uns dort – wir freuen uns auf Ihre Anregungen.  
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *



From:Martin Krasser <[hidden email]>
To:[hidden email]
Date:31.05.2009 21:49
Subject:Re: [Ipf-developer] onWhen closure support
Sent by:[hidden email]





... just seen that somwthing went wrong with the formatting of my
example. Here it is again:

. from('direct:input1')
.onException(HttpOperationFailedException.class)
.onWhen {it.exception.statusCode =~ /^5(\d{2})$/}
.maximumRedeliveries(0)
...


Martin Krasser schrieb:

> [hidden email] schrieb:
>>
>> Hi,
>>
>> I was wondering if we could also add the closure support for the
>> “onWhen” statement to be easily able to do some fine grained Exception
>> handling, based on e.g. regular expressions.
> Makes sense to me.
>>
>> So we would have in CoreModelExtensions something like:
>> …
>> ExceptionType.metaClass.*onWhen* = { String regExp, Closure
>> exceptionExpression ->
>> delegate.onWhen(new ValueBuilder(new
>> DelegatingExpression(exceptionExpression)).regex(regExp))
>> }
> This extension limits usage of onWhen to regular expressions. What
> about something like that:
>
> ExceptionType.metaClass.onWhen = { Closure predicate ->
> delegate.onWhen(new DelegatingCamelPredicate(predicate))
> }
>
> Here, the closure implements the predicate and your example can be
> written as
>
> . from('direct:input1')
> .onException(HttpOperationFailedException.class)
> *.onWhen {it.exception.statusCode =~ /^5(\d{2})$/}
> * .maximumRedeliveries(0)
> ...
>
> This example uses the Groovy syntax for regular expressions but you
> could write anything returning a boolean.
>
> Any thoughts?
>
>> …
>>
>> And the users would be able to make:
>>
>> from('direct:input1')
>> .onException(HttpOperationFailedException.class)
>> *.onWhen('^5(\\d{2})$'){
>> it.exception.statusCode
>> }*
>> .maximumRedeliveries(0)
>> .handled(true)
>> .to('direct:error1')
>> .end()
>> .onException(HttpOperationFailedException.class)
>> *.onWhen('^4(\\d{2})$'){
>> it.exception.statusCode
>> }*
>> .maximumRedeliveries(0)
>> .handled(true)
>> .to('direct:error2')
>> .end()
>> .onException(Exception.class)
>> *.onWhen('^.+Read$'){
>> it.exception.message
>> }*
>> .maximumRedeliveries(5)
>> .useExponentialBackoff()
>> .handled(true)
>> .to('direct:error3')
>> .end()
>> .to('_http://localhost/test_')
>>
>> Cheers,
>> Boris
>> InterComponentWare AG:
>> Vorstand: Peter Reuschel (Vors.), Norbert Olsacher /
>> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
>> Firmensitz: 69190 Walldorf, Industriestraße 41 / AG Mannheim HRB
>> 351761 / USt.-IdNr.: DE 198388516
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Ipf-developer mailing list
>> [hidden email]
>>
http://gforge.openehealth.org/mailman/listinfo/ipf-developer
>>  
>
>

_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer

InterComponentWare AG:
Vorstand: Peter Reuschel (Vors.), Norbert Olsacher / Aufsichtsratsvors.: Prof. Dr. Christof Hettich
Firmensitz: 69190 Walldorf, Industriestraße 41 / AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516

_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer
Reply | Threaded
Open this post in threaded view
|

Re: onWhen closure support

mrt1nz
Administrator

Cheers,
Martin

2009/6/2 <[hidden email]>

Hi,

yes I agree, that's even better.

The users should be aware that the Exception Object is sometimes available only as a property ( exchange.properties['org.apache.camel.processor.DeadLetterChannel.FAILURE_HANDLED']) and we should point that out in the docs.
 
that's already described in the docs: the exceptionObject() and exceptionMessage() DSL extensions (see core features). However, when using Camel's onWhen, the exception object is set on the exchange.

I'll check in the onWhen closure support today.



Many thanks,
Cheers,
Boris

Boris Stanojevic | R&D ProfessionalGate
InterComponentWare AG | Industriestraße 41 | 69190 Walldorf (Baden) | Germany
Tel.: +49 (0) 6227 385 557 | Fax: +49 (0) 6227 385 491
[hidden email] |
www.icw.de| www.lifesensor.com


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Neues erfahren, kommentieren, beisteuern: Was es Spannendes
zum Thema Gesundheit, eHealth und LifeSensor gibt, finden Sie
aktuell in unserem Weblog:
www.lifesensor.com/weblog
Treffen Sie uns dort – wir freuen uns auf Ihre Anregungen.  
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *



From: Martin Krasser <[hidden email]>
To: [hidden email]
Date: 31.05.2009 21:49
Subject:Re: [Ipf-developer] onWhen closure support
Sent by:[hidden email]





... just seen that somwthing went wrong with the formatting of my
example. Here it is again:

. from('direct:input1')
.onException(HttpOperationFailedException.class)
.onWhen {it.exception.statusCode =~ /^5(\d{2})$/}
.maximumRedeliveries(0)
...


Martin Krasser schrieb:
> [hidden email] schrieb:
>>
>> Hi,
>>
>> I was wondering if we could also add the closure support for the
>> “onWhen” statement to be easily able to do some fine grained Exception
>> handling, based on e.g. regular expressions.
> Makes sense to me.
>>
>> So we would have in CoreModelExtensions something like:
>> …
>> ExceptionType.metaClass.*onWhen* = { String regExp, Closure
>> exceptionExpression ->

>> delegate.onWhen(new ValueBuilder(new
>> DelegatingExpression(exceptionExpression)).regex(regExp))
>> }
> This extension limits usage of onWhen to regular expressions. What
> about something like that:
>
> ExceptionType.metaClass.onWhen = { Closure predicate ->
> delegate.onWhen(new DelegatingCamelPredicate(predicate))
> }
>
> Here, the closure implements the predicate and your example can be
> written as
>
> . from('direct:input1')
> .onException(HttpOperationFailedException.class)
> *.onWhen {it.exception.statusCode =~ /^5(\d{2})$/}
> * .maximumRedeliveries(0)
> ...

>
> This example uses the Groovy syntax for regular expressions but you
> could write anything returning a boolean.
>
> Any thoughts?
>
>> …
>>
>> And the users would be able to make:
>>
>> from('direct:input1')
>> .onException(HttpOperationFailedException.class)
>> *.onWhen('^5(\\d{2})$'){
>> it.exception.statusCode
>> }*
>> .maximumRedeliveries(0)
>> .handled(true)
>> .to('direct:error1')
>> .end()
>> .onException(HttpOperationFailedException.class)
>> *.onWhen('^4(\\d{2})$'){
>> it.exception.statusCode
>> }*
>> .maximumRedeliveries(0)
>> .handled(true)
>> .to('direct:error2')
>> .end()
>> .onException(Exception.class)
>> *.onWhen('^.+Read$'){
>> it.exception.message
>> }*
>> .maximumRedeliveries(5)
>> .useExponentialBackoff()
>> .handled(true)
>> .to('direct:error3')
>> .end()
>> .to('_http://localhost/test_')
>>

>> Cheers,
>> Boris
>> InterComponentWare AG:
>> Vorstand: Peter Reuschel (Vors.), Norbert Olsacher /
>> Aufsichtsratsvors.: Prof. Dr. Christof Hettich
>> Firmensitz: 69190 Walldorf, Industriestraße 41 / AG Mannheim HRB
>> 351761 / USt.-IdNr.: DE 198388516
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Ipf-developer mailing list
>> [hidden email]
>>
http://gforge.openehealth.org/mailman/listinfo/ipf-developer
>>  
>
>

_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer

InterComponentWare AG:
Vorstand: Peter Reuschel (Vors.), Norbert Olsacher / Aufsichtsratsvors.: Prof. Dr. Christof Hettich
Firmensitz: 69190 Walldorf, Industriestraße 41 / AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516

_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer



_______________________________________________
Ipf-developer mailing list
[hidden email]
http://gforge.openehealth.org/mailman/listinfo/ipf-developer