CAMEL-7804: MessageHelper - dump message for logging should catch throwable
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e5d9899f Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e5d9899f Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e5d9899f Branch: refs/remotes/origin/camel-2.13.x Commit: e5d9899ff90ee495e759ddc66194964ce9ea86d8 Parents: 5805379 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Sep 11 18:59:44 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Sep 12 07:27:53 2014 +0200 ---------------------------------------------------------------------- .../org/apache/camel/util/MessageHelper.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e5d9899f/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java index 0182594..ec088f3 100644 --- a/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java @@ -251,13 +251,17 @@ public final class MessageHelper { String body = null; if (message.getExchange() != null) { try { - body = message.getExchange().getContext().getTypeConverter().convertTo(String.class, message.getExchange(), obj); - } catch (Exception e) { + body = message.getExchange().getContext().getTypeConverter().tryConvertTo(String.class, message.getExchange(), obj); + } catch (Throwable e) { // ignore as the body is for logging purpose } } if (body == null) { - body = obj.toString(); + try { + body = obj.toString(); + } catch (Throwable e) { + // ignore as the body is for logging purpose + } } // reset stream cache after use @@ -359,13 +363,13 @@ public final class MessageHelper { // to String if (value != null) { try { - String xml = message.getExchange().getContext().getTypeConverter().convertTo(String.class, + String xml = message.getExchange().getContext().getTypeConverter().tryConvertTo(String.class, message.getExchange(), value); if (xml != null) { // must always xml encode sb.append(StringHelper.xmlEncode(xml)); } - } catch (Exception e) { + } catch (Throwable e) { // ignore as the body is for logging purpose } } @@ -433,7 +437,8 @@ public final class MessageHelper { // must not cause new exceptions so run this in a try catch block try { return doDumpMessageHistoryStacktrace(exchange, exchangeFormatter, logStackTrace); - } catch (Exception e) { + } catch (Throwable e) { + // ignore as the body is for logging purpose return ""; } } @@ -472,7 +477,7 @@ public final class MessageHelper { for (MessageHistory history : list) { routeId = history.getRouteId() != null ? history.getRouteId() : ""; id = history.getNode().getId(); - // we need to avoid leak the sensibale information here + // we need to avoid leak the sensible information here label = URISupport.sanitizeUri(history.getNode().getLabel()); elapsed = history.getElapsed();