aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/XMPPServer.java4
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Index.java7
-rw-r--r--juick-server/src/main/java/com/juick/server/xmpp/helpers/XMPPStatus.java12
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java22
4 files changed, 37 insertions, 8 deletions
diff --git a/juick-server/src/main/java/com/juick/server/XMPPServer.java b/juick-server/src/main/java/com/juick/server/XMPPServer.java
index 4a5d577d..675d79da 100644
--- a/juick-server/src/main/java/com/juick/server/XMPPServer.java
+++ b/juick-server/src/main/java/com/juick/server/XMPPServer.java
@@ -434,4 +434,8 @@ public class XMPPServer implements ConnectionListener {
service.shutdown();
logger.info("XMPP server destroyed");
}
+
+ public int getServerPort() {
+ return s2sPort;
+ }
}
diff --git a/juick-server/src/main/java/com/juick/server/api/Index.java b/juick-server/src/main/java/com/juick/server/api/Index.java
index eafde85b..5ffa6341 100644
--- a/juick-server/src/main/java/com/juick/server/api/Index.java
+++ b/juick-server/src/main/java/com/juick/server/api/Index.java
@@ -28,10 +28,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+import rocks.xmpp.addr.Jid;
import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
import java.net.URI;
+import java.util.stream.Collectors;
/**
* Created by vitalyster on 25.07.2016.
@@ -58,8 +60,9 @@ public class Index {
public XMPPStatus xmppStatus() {
XMPPStatus status = new XMPPStatus();
if (xmpp != null) {
- status.setInbound(xmpp.getInConnections());
- status.setOutbound(xmpp.getOutConnections().keySet());
+ 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/helpers/XMPPStatus.java b/juick-server/src/main/java/com/juick/server/xmpp/helpers/XMPPStatus.java
index 7978ceb3..99d89866 100644
--- a/juick-server/src/main/java/com/juick/server/xmpp/helpers/XMPPStatus.java
+++ b/juick-server/src/main/java/com/juick/server/xmpp/helpers/XMPPStatus.java
@@ -27,22 +27,22 @@ import java.util.Set;
* Created by vitalyster on 16.02.2017.
*/
public class XMPPStatus {
- private List<ConnectionIn> inbound;
- private Set<ConnectionOut> outbound;
+ private List<String> inbound;
+ private List<String> outbound;
- public List<ConnectionIn> getInbound() {
+ public List<String> getInbound() {
return inbound;
}
- public void setInbound(List<ConnectionIn> inbound) {
+ public void setInbound(List<String> inbound) {
this.inbound = inbound;
}
- public Set<ConnectionOut> getOutbound() {
+ public List<String> getOutbound() {
return outbound;
}
- public void setOutbound(Set<ConnectionOut> outbound) {
+ public void setOutbound(List<String> outbound) {
this.outbound = outbound;
}
}
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 297a3c88..abeb7424 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -28,6 +28,8 @@ import com.juick.server.helpers.CommandResult;
import com.juick.server.helpers.TagStats;
import com.juick.server.util.HttpUtils;
import com.juick.server.util.ImageUtils;
+import com.juick.server.xmpp.helpers.XMPPStatus;
+import com.juick.server.xmpp.s2s.ConnectionIn;
import com.juick.service.*;
import com.juick.util.DateFormattersHolder;
import com.juick.util.MessageUtils;
@@ -77,6 +79,7 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
+import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
@@ -85,6 +88,7 @@ import java.time.Instant;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
+import java.util.function.Supplier;
import java.util.stream.IntStream;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -1203,4 +1207,22 @@ public class ServerTests {
messagesService.recommendMessage(readerMid, recommenderId);
assertThat(subscribers.apply(recommenderId, messagesService.getMessage(readerMid)).size(), is(0));
}
+ @Test
+ public void xmppStatusApi() throws Exception {
+ Supplier<XMPPStatus> getStatus = () -> {
+ try {
+ MvcResult result = mockMvc.perform(get("/xmpp/status").with(httpBasic(ugnichName, ugnichPassword)))
+ .andExpect(status().isOk()).andReturn();
+ return jsonMapper.readValue(result.getResponse().getContentAsString(), XMPPStatus.class);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ };
+ assertThat(getStatus.get().getInbound().size(), is(0));
+ ConnectionIn test = new ConnectionIn(server, new Socket("localhost", server.getServerPort()));
+ test.from.add(Jid.of("test"));
+ server.addConnectionIn(test);
+ assertThat(getStatus.get().getInbound().size(), is(1));
+ }
}