Getting a Header property on a exception in the DSL

2013-08-19 Thread abdiels
Hello,

I am trying to print the client id on a exception message like this:

from("seda:AddDataToCache").routeId("AddDataToCache")
.threads()
.choice()
.when(header("CamelJdbcRowCount").isEqualTo(0))
.log("No database record")
.throwException(new
ConfigurationNotFoundException("Client Configuration not found for clientid:
${header." + FMSHeaders.CLIENT_ID + "}"))
.otherwise()
.log("FOUND database record")
.end()
;

Now that of course does not work since we are passing a string to a
constructor and the simple language will not kick in...I tried this

new ConfigurationNotFoundException((new SimpleBuilder(
"Client Configuration not found for clientid:
${header." + FMSHeaders.CLIENT_ID + "}")).evaluate(???,String.class)) 

but I don't know how to get the exchange...Is there a way to accomplish
putting this client id here?  I know I can get in the error handler itself
for example and I could do other things, but I am wondering if there is a
way to just grab data like this from the message sort of mixing simple with
strings.  Please let me know your thoughts.

Thank you,

Abdiel




--
View this message in context: 
http://camel.465427.n5.nabble.com/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Getting a Header property on a exception in the DSL

2013-08-19 Thread Bart Horré
Hello,

I don't think there is a need to concatenate like that (header. + " ... ").
In my experience with using simples in log messages you can just write:
"Client config not found for id ${header.myHeader}."

Or you could check out the docs below:

http://camel.apache.org/simple.html


On Tue, Aug 20, 2013 at 6:42 AM, abdiels  wrote:

> Hello,
>
> I am trying to print the client id on a exception message like this:
>
> from("seda:AddDataToCache").routeId("AddDataToCache")
> .threads()
> .choice()
> .when(header("CamelJdbcRowCount").isEqualTo(0))
> .log("No database record")
> .throwException(new
> ConfigurationNotFoundException("Client Configuration not found for
> clientid:
> ${header." + FMSHeaders.CLIENT_ID + "}"))
> .otherwise()
> .log("FOUND database record")
> .end()
> ;
>
> Now that of course does not work since we are passing a string to a
> constructor and the simple language will not kick in...I tried this
>
> new ConfigurationNotFoundException((new SimpleBuilder(
> "Client Configuration not found for clientid:
> ${header." + FMSHeaders.CLIENT_ID + "}")).evaluate(???,String.class))
>
> but I don't know how to get the exchange...Is there a way to accomplish
> putting this client id here?  I know I can get in the error handler itself
> for example and I could do other things, but I am wondering if there is a
> way to just grab data like this from the message sort of mixing simple with
> strings.  Please let me know your thoughts.
>
> Thank you,
>
> Abdiel
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Bart Horré
Anova r&d bvba


Re: Getting a Header property on a exception in the DSL

2013-08-20 Thread abdiels
barthorre,

First, thanks for replying and second, I do that all the time too!!!
However, in this particular it does not work.  Look at the code, I am
passing it when throwing the exception, it is not in the regular DSL where
simple will just work.  You can try it and you will see.  What comes in the
Exception string is:  Client Configuration not found for clientid:
${header.ClientID}.  If you try to add simple around it, it does not work
since simple returns a SimpleBuilder so I tried the other code that I showed
on my post, but I am not sure how to get the exchange so I have not been
able to get the value here.




--
View this message in context: 
http://camel.465427.n5.nabble.com/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551p5737592.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Getting a Header property on a exception in the DSL

2013-08-20 Thread Claus Ibsen
This is not possible as you use the new constructor in Java that will
instantiate the exception once.

What you want is to create a new exception when it happens with data
from the message. For that you can call a method and let it throw the
exception.

For throwException to work with your use case, it would require to not
use the new constructor, and let Camel instantiate the exception and
evaluate eg any simple expresisons prior etc.

eg we could do something alike,

throwException(ConfigurationNotFoundException.class, simple("Something
got wrong due ${header.bar}"))

which then would create the exception using a 1 arg constructor,
assuming that would be a String type etc.

Though when you need 2+ args then it gets more complicated.

Also we should also try to avoid keep expanding the DSL to avoid it
growing to large. Though I can see your use-case is probably more
common to create an exception with a cause String message that has
details from the Camel message.

If other feel we need something a like this, then we could raise a JIRA



On Tue, Aug 20, 2013 at 2:25 PM, abdiels  wrote:
> barthorre,
>
> First, thanks for replying and second, I do that all the time too!!!
> However, in this particular it does not work.  Look at the code, I am
> passing it when throwing the exception, it is not in the regular DSL where
> simple will just work.  You can try it and you will see.  What comes in the
> Exception string is:  Client Configuration not found for clientid:
> ${header.ClientID}.  If you try to add simple around it, it does not work
> since simple returns a SimpleBuilder so I tried the other code that I showed
> on my post, but I am not sure how to get the exchange so I have not been
> able to get the value here.
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551p5737592.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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


Re: Getting a Header property on a exception in the DSL

2013-08-20 Thread abdiels
Thanks Claus...I can find many ways around it, I was just wondering if
there was something I was missing or doing wrong...What you are saying
makes sense and I don't think we need to add that at this point.


On Tue, Aug 20, 2013 at 10:59 AM, Claus Ibsen-2 [via Camel] <
ml-node+s465427n5737601...@n5.nabble.com> wrote:

> This is not possible as you use the new constructor in Java that will
> instantiate the exception once.
>
> What you want is to create a new exception when it happens with data
> from the message. For that you can call a method and let it throw the
> exception.
>
> For throwException to work with your use case, it would require to not
> use the new constructor, and let Camel instantiate the exception and
> evaluate eg any simple expresisons prior etc.
>
> eg we could do something alike,
>
> throwException(ConfigurationNotFoundException.class, simple("Something
> got wrong due ${header.bar}"))
>
> which then would create the exception using a 1 arg constructor,
> assuming that would be a String type etc.
>
> Though when you need 2+ args then it gets more complicated.
>
> Also we should also try to avoid keep expanding the DSL to avoid it
> growing to large. Though I can see your use-case is probably more
> common to create an exception with a cause String message that has
> details from the Camel message.
>
> If other feel we need something a like this, then we could raise a JIRA
>
>
>
> On Tue, Aug 20, 2013 at 2:25 PM, abdiels <[hidden 
> email]<http://user/SendEmail.jtp?type=node&node=5737601&i=0>>
> wrote:
>
> > barthorre,
> >
> > First, thanks for replying and second, I do that all the time too!!!
> > However, in this particular it does not work.  Look at the code, I am
> > passing it when throwing the exception, it is not in the regular DSL
> where
> > simple will just work.  You can try it and you will see.  What comes in
> the
> > Exception string is:  Client Configuration not found for clientid:
> > ${header.ClientID}.  If you try to add simple around it, it does not
> work
> > since simple returns a SimpleBuilder so I tried the other code that I
> showed
> > on my post, but I am not sure how to get the exchange so I have not been
> > able to get the value here.
> >
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551p5737592.html
>
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -
> Red Hat, Inc.
> Email: [hidden email]<http://user/SendEmail.jtp?type=node&node=5737601&i=1>
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551p5737601.html
>  To unsubscribe from Getting a Header property on a exception in the DSL, 
> click
> here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5737551&code=YWJkaWVsc0BnbWFpbC5jb218NTczNzU1MXwtNjU1OTY1MDc=>
> .
> 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/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551p5737611.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Getting a Header property on a exception in the DSL

2014-12-29 Thread Chris Melikian
You could use a new Processor inline in the Java DSL and throw the 
exception from within the Processor? The exchange is the parameter in the
interface method so you can create the exception with anything you want in
it. 




--
View this message in context: 
http://camel.465427.n5.nabble.com/Getting-a-Header-property-on-a-exception-in-the-DSL-tp5737551p5761117.html
Sent from the Camel - Users mailing list archive at Nabble.com.