From 73224cd774e32d3bf5bc9209cf6323f9b885fcab Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 3 Feb 2017 17:32:01 +0300 Subject: juick-ws: log xmpp messages using jaxb --- juick-ws/src/main/java/com/juick/ws/XMPPConnection.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java index ca792a1a..1f1e07c7 100644 --- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java +++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java @@ -21,7 +21,10 @@ import rocks.xmpp.core.stanza.model.Message; import rocks.xmpp.extensions.component.accept.ExternalComponent; import javax.inject.Inject; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; import java.io.IOException; +import java.io.StringWriter; import java.util.List; import java.util.stream.Collectors; @@ -71,8 +74,12 @@ public class XMPPConnection implements AutoCloseable { Message msg = e.getMessage(); com.juick.Message jmsg = msg.getExtension(com.juick.Message.class); if (jmsg != null) { - if (logger.isInfoEnabled()) // prevent writeValueAsString execution if log is disabled - logger.info("got msg: {}", ms.writeValueAsString(jmsg)); + if (logger.isInfoEnabled()) { // prevent writeValueAsString execution if log is disabled + Marshaller marshaller = xmpp.createMarshaller(); + StringWriter stanzaWriter = new StringWriter(); + marshaller.marshal(msg, stanzaWriter); + logger.info("got msg: {}", stanzaWriter.toString()); + } if (jmsg.getMid() == 0) { int uid_to = NumberUtils.toInt(msg.getTo().getLocal(), 0); if (uid_to > 0) { @@ -89,6 +96,8 @@ public class XMPPConnection implements AutoCloseable { } } catch (JsonProcessingException ex) { logger.error("mapper exception", ex); + } catch (JAXBException exc) { + logger.error("jaxb exception", exc); } }); try { -- cgit v1.2.3