JAMES-2199 Improved logging of byte array icsContent

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/00b1a0c7
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/00b1a0c7
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/00b1a0c7

Branch: refs/heads/master
Commit: 00b1a0c767ce51d5c1e31fcb5a9242f82193fba4
Parents: f49e2ea
Author: Daniel Trebbien <[email protected]>
Authored: Thu Oct 19 22:01:58 2017 -0500
Committer: Antoine Duprat <[email protected]>
Committed: Mon Dec 18 20:31:50 2017 +0100

----------------------------------------------------------------------
 .../transport/mailets/ICalendarParser.java      | 24 ++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/00b1a0c7/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICalendarParser.java
----------------------------------------------------------------------
diff --git 
a/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICalendarParser.java
 
b/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICalendarParser.java
index 3855bcd..a571248 100644
--- 
a/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICalendarParser.java
+++ 
b/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICalendarParser.java
@@ -21,11 +21,13 @@ package org.apache.james.transport.mailets;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.Serializable;
+import java.nio.charset.Charset;
 import java.util.Map;
 import java.util.stream.Stream;
 
 import javax.mail.MessagingException;
 
+import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.GenericMailet;
@@ -134,10 +136,28 @@ public class ICalendarParser extends GenericMailet {
             ByteArrayInputStream inputStream = new 
ByteArrayInputStream(icsContent);
             return Stream.of(Pair.of(key, builder.build(inputStream)));
         } catch (IOException e) {
-            LOGGER.error("Error while reading input: " + icsContent, e);
+            if (LOGGER.isErrorEnabled()) {
+                String icsContentAsString;
+                try {
+                    icsContentAsString = new String(icsContent, 
Charset.forName("UTF-8"));
+                } catch (Throwable t) {
+                    LOGGER.error("Error while decoding ics content", t);
+                    icsContentAsString = new String(Hex.encodeHex(icsContent));
+                }
+                LOGGER.error("Error while reading input: " + 
icsContentAsString, e);
+            }
             return Stream.of();
         } catch (ParserException e) {
-            LOGGER.error("Error while parsing ICal object: " + icsContent, e);
+            if (LOGGER.isErrorEnabled()) {
+                String icsContentAsString;
+                try {
+                    icsContentAsString = new String(icsContent, 
Charset.forName("UTF-8"));
+                } catch (Throwable t) {
+                    LOGGER.error("Error while decoding ics content", t);
+                    icsContentAsString = new String(Hex.encodeHex(icsContent));
+                }
+                LOGGER.error("Error while parsing ICal object: " + 
icsContentAsString, e);
+            }
             return Stream.of();
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to