diff options
author | Vitaly Takmazov | 2017-02-06 10:32:23 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-02-06 10:32:23 +0300 |
commit | ecd0131695cf8c7360c4d5675e3fde22325fc4df (patch) | |
tree | efd7d8ee62b9ca31367fefaa6c491b9b1a94baaa /juick-ws/src | |
parent | 767e62fbf23460e6fb99a9c75e00798d85036326 (diff) |
juick-ws: create XMLStreamWrite using babbler
Diffstat (limited to 'juick-ws/src')
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/XMPPConnection.java | 20 |
1 files changed, 15 insertions, 5 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 1f1e07c7..7a01c501 100644 --- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java +++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java @@ -19,10 +19,12 @@ import rocks.xmpp.core.session.XmppSessionConfiguration; import rocks.xmpp.core.session.debug.LogbackDebugger; import rocks.xmpp.core.stanza.model.Message; import rocks.xmpp.extensions.component.accept.ExternalComponent; +import rocks.xmpp.util.XmppUtils; import javax.inject.Inject; import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; import java.io.IOException; import java.io.StringWriter; import java.util.List; @@ -75,10 +77,18 @@ public class XMPPConnection implements AutoCloseable { com.juick.Message jmsg = msg.getExtension(com.juick.Message.class); if (jmsg != null) { 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()); + try { + StringWriter stanzaWriter = new StringWriter(); + XMLStreamWriter xmppStreamWriter = XmppUtils.createXmppStreamWriter( + xmpp.getConfiguration().getXmlOutputFactory().createXMLStreamWriter(stanzaWriter)); + xmpp.createMarshaller().marshal(msg, xmppStreamWriter); + xmppStreamWriter.flush(); + xmppStreamWriter.close(); + logger.info("got msg: {}", stanzaWriter.toString()); + } catch (XMLStreamException e1) { + logger.info("jaxb exception", e1); + } + } if (jmsg.getMid() == 0) { int uid_to = NumberUtils.toInt(msg.getTo().getLocal(), 0); |