aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-02-06 16:24:38 +0300
committerGravatar Vitaly Takmazov2017-02-06 16:24:38 +0300
commit10d9407032b0eadeabc25ac7cd16a72b03be41bb (patch)
treed221dbdf4bd1192faf178126ffff45ec874105df /juick-xmpp/src
parentac9df0dd46640179869cc8285b9aadff0e88e242 (diff)
juick-xmpp: refactor ConnectionRouter
Diffstat (limited to 'juick-xmpp/src')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java37
1 files changed, 21 insertions, 16 deletions
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) {