You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Pascal Schumacher <pa...@gmx.net> on 2018/12/02 11:49:51 UTC
onException onWhen behavior
Hi everybody,
I expected exceptionMessage() of onWhen() for a specific onException()
to refer to the message of the exception instance in the exception
hierarchy. E.g. I expected this to work:
public void configure() {
onException(IOException.class)
.onWhen(exceptionMessage().contains("root exception message"))
.to("mock:ioexception");
from("seda:start")
.throwException(new RuntimeException("leaf exception message",
new IOException("root exception message")));
}
Then I tried a custom predicate instead:
public void configure() {
onException(IOException.class)
.onWhen(method(IOExceptionMatcher.class))
.to("mock:ioexception");
from("seda:start")
.throwException(new RuntimeException("leaf exception message",
new IOException("root exception message")));
}
public static class IOExceptionMatcher {
public static boolean matches(IOException e) {
return e.getMessage().contains("root exception message");
}
}
This also did not work. Therefore I tried:
public void configure() {
onException(IOException.class)
.onWhen(method(ExceptionMatcher.class))
.to("mock:ioexception");
from("seda:start")
.throwException(new RuntimeException("leaf exception message",
new IOException("root exception message")));
}
public static class ExceptionMatcher {
public static boolean matches(Exception e) {
return e.getMessage().contains("root exception message");
}
}
This also did not work. This "workaround" does work:
public void configure() {
onException(IOException.class)
.onWhen(method(ExceptionMatcher.class))
.to("mock:ioexception");
from("seda:start")
.throwException(new RuntimeException("leaf exception message",
new IOException("root exception message")));
}
public static class ExceptionMatcher {
public static boolean matches(Exception e) {
return Throwables.getRootCause(e).getMessage().contains("root
exception message");
}
}
Is any of this supposed to work, or are my expectations wrong?
Thanks,
Pascal
Re: onException onWhen behavior
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
This is not supported, that code uses the simple ${exception.message}
which invokes the getMessage method on the top exception.
On Sun, Dec 2, 2018 at 12:50 PM Pascal Schumacher
<pa...@gmx.net> wrote:
>
> Hi everybody,
>
> I expected exceptionMessage() of onWhen() for a specific onException()
> to refer to the message of the exception instance in the exception
> hierarchy. E.g. I expected this to work:
>
> public void configure() {
> onException(IOException.class)
> .onWhen(exceptionMessage().contains("root exception message"))
> .to("mock:ioexception");
>
> from("seda:start")
> .throwException(new RuntimeException("leaf exception message",
> new IOException("root exception message")));
> }
>
> Then I tried a custom predicate instead:
>
> public void configure() {
> onException(IOException.class)
> .onWhen(method(IOExceptionMatcher.class))
> .to("mock:ioexception");
>
> from("seda:start")
> .throwException(new RuntimeException("leaf exception message",
> new IOException("root exception message")));
> }
>
> public static class IOExceptionMatcher {
> public static boolean matches(IOException e) {
> return e.getMessage().contains("root exception message");
> }
> }
>
> This also did not work. Therefore I tried:
>
> public void configure() {
> onException(IOException.class)
> .onWhen(method(ExceptionMatcher.class))
> .to("mock:ioexception");
>
> from("seda:start")
> .throwException(new RuntimeException("leaf exception message",
> new IOException("root exception message")));
> }
>
> public static class ExceptionMatcher {
> public static boolean matches(Exception e) {
> return e.getMessage().contains("root exception message");
> }
> }
>
> This also did not work. This "workaround" does work:
>
> public void configure() {
> onException(IOException.class)
> .onWhen(method(ExceptionMatcher.class))
> .to("mock:ioexception");
>
> from("seda:start")
> .throwException(new RuntimeException("leaf exception message",
> new IOException("root exception message")));
> }
>
> public static class ExceptionMatcher {
> public static boolean matches(Exception e) {
> return Throwables.getRootCause(e).getMessage().contains("root
> exception message");
> }
> }
>
> Is any of this supposed to work, or are my expectations wrong?
>
> Thanks,
> Pascal
>
>
>
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2