git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: onException onWhen behavior


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
<pascalschumacher@xxxxxxx> 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