aboutsummaryrefslogtreecommitdiff
path: root/juick-ws
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-02-03 17:32:01 +0300
committerGravatar Vitaly Takmazov2017-02-03 17:32:01 +0300
commit73224cd774e32d3bf5bc9209cf6323f9b885fcab (patch)
tree085bbc6730fd59392940a8a75c7080678ec437c8 /juick-ws
parent9742e8e43bfb29b83b5a8a88be7cc6610116d7c5 (diff)
juick-ws: log xmpp messages using jaxb
Diffstat (limited to 'juick-ws')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/XMPPConnection.java13
1 files 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 {