You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "michael.esmann" <ca...@gmail.com> on 2015/09/25 14:57:35 UTC

Errorhandling in setProperty/script

Hi,

I have a situation where I want to set some properties on my exchange, if it
is possible. But I dont want the exchange to fail, if the property is not
present. I have tried something like this:

<route>
    <from uri=.../>

    <doTry>
        <setProperty propertyName="info.MyProperty">
            <javaScript>request.body.substring(25, 33)</javaScript>
        </setProperty>
        <doFinally>
        </doFinally>
    </doTry>

    <to uri=.../>
</route>

where I do not want this exchange to fail, if the body is shorter than 32
characters. But it didn't work.
What is the best way to accomplish this? I would like to avoid using
"onException" handler or "errorHandler" because I am only interested in
ignoring script errors, but if its the only way I can do it then that would
be okay.

Any suggestions?

/Michael



--
View this message in context: http://camel.465427.n5.nabble.com/Errorhandling-in-setProperty-script-tp5771968.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Errorhandling in setProperty/script

Posted by Asaf Mesika <as...@gmail.com>.
How about using the Ternary conditional operator?
v.length < 32 ? "short" : v.substring

On Friday, 25 September 2015, michael.esmann <ca...@gmail.com>
wrote:

> Hi,
>
> I have a situation where I want to set some properties on my exchange, if
> it
> is possible. But I dont want the exchange to fail, if the property is not
> present. I have tried something like this:
>
> <route>
>     <from uri=.../>
>
>     <doTry>
>         <setProperty propertyName="info.MyProperty">
>             <javaScript>request.body.substring(25, 33)</javaScript>
>         </setProperty>
>         <doFinally>
>         </doFinally>
>     </doTry>
>
>     <to uri=.../>
> </route>
>
> where I do not want this exchange to fail, if the body is shorter than 32
> characters. But it didn't work.
> What is the best way to accomplish this? I would like to avoid using
> "onException" handler or "errorHandler" because I am only interested in
> ignoring script errors, but if its the only way I can do it then that would
> be okay.
>
> Any suggestions?
>
> /Michael
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Errorhandling-in-setProperty-script-tp5771968.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Errorhandling in setProperty/script

Posted by "michael.esmann" <ca...@gmail.com>.
I just found out - after reading a little in "Camel In Action" ;-) - that I
could use this:

    <onException>
     
<exception>org.apache.camel.builder.script.ScriptEvaluationException</exception>
      <continued>
        <constant>true</constant>
      </continued>
    </onException>

Mayby that is sufficient in my case. This exception would probably only
occur in my "javascript"(?)



--
View this message in context: http://camel.465427.n5.nabble.com/Errorhandling-in-setProperty-script-tp5771968p5771971.html
Sent from the Camel - Users mailing list archive at Nabble.com.