From 10d9407032b0eadeabc25ac7cd16a72b03be41bb Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 6 Feb 2017 16:24:38 +0300 Subject: juick-xmpp: refactor ConnectionRouter --- .../com/juick/components/s2s/ConnectionRouter.java | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'juick-xmpp/src/main') diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java index 61b216db..ef89671f 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java @@ -29,17 +29,11 @@ public class ConnectionRouter implements AutoCloseable { private static final Logger logger = LoggerFactory.getLogger(ConnectionRouter.class); - private String componentName; - private int componentPort; - private String password; private ExternalComponent router; private XMPPServer xmpp; public ConnectionRouter(XMPPServer s2s, String componentName, int componentPort, String password) { this.xmpp = s2s; - this.componentName = componentName; - this.componentPort = componentPort; - this.password = password; logger.info("stream router start"); router = ExternalComponent.create(componentName, password, xmpp.getSession().getConfiguration(), "localhost", componentPort); router.addInboundMessageListener(e -> { @@ -60,7 +54,13 @@ public class ConnectionRouter implements AutoCloseable { } } else if (jid.getDomain().endsWith(xmpp.HOSTNAME) && (jid.getDomain().equals(xmpp.HOSTNAME) || jid.getDomain().endsWith("." + xmpp.HOSTNAME))) { - logger.info("skip"); + if (logger.isInfoEnabled()) { + try { + logger.info("unhandled message: {}", stanzaToString(message)); + } catch (JAXBException | XMLStreamException ex) { + logger.error("JAXB exception", ex); + } + } } else { route(jid.getDomain(), message); } @@ -72,20 +72,25 @@ public class ConnectionRouter implements AutoCloseable { } } + String stanzaToString(Stanza stanza) throws XMLStreamException, JAXBException { + StringWriter stanzaWriter = new StringWriter(); + XMLStreamWriter xmppStreamWriter = XmppUtils.createXmppStreamWriter( + router.getConfiguration().getXmlOutputFactory().createXMLStreamWriter(stanzaWriter)); + router.createMarshaller().marshal(stanza, xmppStreamWriter); + xmppStreamWriter.flush(); + xmppStreamWriter.close(); + return stanzaWriter.toString(); + } + void route(String domain, Stanza stanza) { try { - StringWriter stanzaWriter = new StringWriter(); - XMLStreamWriter xmppStreamWriter = XmppUtils.createXmppStreamWriter( - router.getConfiguration().getXmlOutputFactory().createXMLStreamWriter(stanzaWriter)); - router.createMarshaller().marshal(stanza, xmppStreamWriter); - xmppStreamWriter.flush(); - xmppStreamWriter.close(); - String xml = stanzaWriter.toString(); + String xml = stanzaToString(stanza); logger.info("stream router (out): {}", xml); xmpp.sendOut(domain, xml); - } catch (XMLStreamException | JAXBException e1) { - logger.info("jaxb exception", e1); + } catch (XMLStreamException | JAXBException e) { + logger.error("JAXB exception", e); } + } void sendStanza(Stanza xml) { -- cgit v1.2.3