aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/xmpp
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-11 09:49:48 +0300
committerGravatar Vitaly Takmazov2018-09-11 09:49:48 +0300
commit4270d6b384b72491a7cc3440cc154049e9ad567e (patch)
tree553026305bca6cbd86988a7695f1e8ef5c76b7dd /juick-server/src/main/java/com/juick/server/xmpp
parentc7145b18652e9a4264910853133e7bf29559cdc5 (diff)
XMPP: do not start when jid is not set
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/xmpp')
-rw-r--r--juick-server/src/main/java/com/juick/server/xmpp/XMPPStatusPage.java30
-rw-r--r--juick-server/src/main/java/com/juick/server/xmpp/router/XMPPRouter.java1
2 files changed, 30 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/server/xmpp/XMPPStatusPage.java b/juick-server/src/main/java/com/juick/server/xmpp/XMPPStatusPage.java
new file mode 100644
index 00000000..90c8fe59
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/xmpp/XMPPStatusPage.java
@@ -0,0 +1,30 @@
+package com.juick.server.xmpp;
+
+import com.juick.server.XMPPServer;
+import com.juick.server.xmpp.helpers.XMPPStatus;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+import rocks.xmpp.addr.Jid;
+
+import javax.inject.Inject;
+import java.util.stream.Collectors;
+
+@RestController
+@ConditionalOnProperty("xmppbot_jid")
+public class XMPPStatusPage {
+ @Inject
+ private XMPPServer xmpp;
+ @RequestMapping(method = RequestMethod.GET, value = "/api/xmpp-status", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+ public XMPPStatus xmppStatus() {
+ XMPPStatus status = new XMPPStatus();
+ if (xmpp != null) {
+ status.setInbound(xmpp.getInConnections().stream().map(c -> c.from).flatMap(j -> j.stream().map(Jid::getDomain)).collect(Collectors.toList()));
+ status.setOutbound(xmpp.getOutConnections().keySet().stream()
+ .map(c -> c.to).map(Jid::getDomain).collect(Collectors.toList()));
+ }
+ return status;
+ }
+}
diff --git a/juick-server/src/main/java/com/juick/server/xmpp/router/XMPPRouter.java b/juick-server/src/main/java/com/juick/server/xmpp/router/XMPPRouter.java
index 4464262c..6d67fa9c 100644
--- a/juick-server/src/main/java/com/juick/server/xmpp/router/XMPPRouter.java
+++ b/juick-server/src/main/java/com/juick/server/xmpp/router/XMPPRouter.java
@@ -39,7 +39,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
-@Component
public class XMPPRouter implements StreamHandler {
private static final Logger logger = LoggerFactory.getLogger("com.juick.server.xmpp");