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