From ecd0131695cf8c7360c4d5675e3fde22325fc4df Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 6 Feb 2017 10:32:23 +0300 Subject: juick-ws: create XMLStreamWrite using babbler --- .../src/main/java/com/juick/ws/XMPPConnection.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'juick-ws') 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); -- cgit v1.2.3