aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server/src/main/java/com/juick/server/ServerManager.java64
-rw-r--r--juick-server/src/main/java/com/juick/server/XMPPConnection.java4
2 files changed, 8 insertions, 60 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ServerManager.java b/juick-server/src/main/java/com/juick/server/ServerManager.java
index efa4b3f0..22b78905 100644
--- a/juick-server/src/main/java/com/juick/server/ServerManager.java
+++ b/juick-server/src/main/java/com/juick/server/ServerManager.java
@@ -23,7 +23,6 @@ import com.juick.server.component.MessageEvent;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -31,21 +30,11 @@ import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import rocks.xmpp.addr.Jid;
-import rocks.xmpp.core.XmppException;
-import rocks.xmpp.core.session.Extension;
-import rocks.xmpp.core.session.XmppSessionConfiguration;
import rocks.xmpp.core.stanza.model.Message;
-import rocks.xmpp.extensions.component.accept.ExternalComponent;
import rocks.xmpp.extensions.oob.model.x.OobX;
-import rocks.xmpp.util.XmppUtils;
-import javax.annotation.PostConstruct;
import javax.inject.Inject;
-import javax.xml.bind.JAXBException;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
import java.io.IOException;
-import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
@@ -55,21 +44,9 @@ import java.util.stream.Collectors;
* @author Ugnich Anton
*/
@Component
-public class ServerManager implements AutoCloseable, ApplicationListener<MessageEvent> {
+public class ServerManager implements ApplicationListener<MessageEvent> {
private static Logger logger = LoggerFactory.getLogger(ServerManager.class);
- private ExternalComponent xmpp;
-
- @Value("${xmpp_host:localhost}")
- private String xmppHost;
- @Value("${xmpp_password:secret}")
- private String xmppPassword;
- @Value("${ws_jid:ws.localhost}")
- private String xmppJid;
- @Value("${xmpp_port:5347}")
- private int xmppPort;
- @Value("${xmpp_disabled:false}")
- private boolean isXmppDisabled;
@Inject
private ObjectMapper jsonMapper;
@Inject
@@ -80,44 +57,11 @@ public class ServerManager implements AutoCloseable, ApplicationListener<Message
private WebsocketManager wsHandler;
@Value("${service_user:juick}")
private String serviceUser;
-
- @PostConstruct
- public void init() {
- if (!isXmppDisabled) {
- setupXmppComponent(xmppHost, xmppPort, xmppJid, xmppPassword);
- } else {
- logger.warn("XMPP is not enabled");
- }
- }
-
- @Override
- public void close() {
- try {
- if (xmpp != null)
- xmpp.close();
-
- logger.info("ExternalComponent on juick-server destroyed");
- } catch (Exception e) {
- logger.warn("Exception occurs on juick-server destroy", e);
- }
- }
-
- public void setupXmppComponent(final String host, final int port, final String jid, final String password) {
- XmppSessionConfiguration configuration = XmppSessionConfiguration.builder()
- .extensions(Extension.of(com.juick.Message.class))
- .build();
- xmpp = ExternalComponent.create(jid, password, configuration, host, port);
- try {
- xmpp.connect();
- } catch (XmppException e) {
- logger.warn("xmpp extension", e);
- }
- }
+ @Inject
+ private XMPPConnection xmppConnection;
public void sendMessage(Message message) {
- if (!isXmppDisabled) {
- xmpp.sendMessage(message);
- }
+ xmppConnection.getRouter().sendMessage(message);
}
public void processMessage(User visitor, String body, String attachmentName) {
diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java
index 69d39c18..03720a3f 100644
--- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java
+++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java
@@ -417,4 +417,8 @@ public class XMPPConnection implements AutoCloseable {
router.close();
}
}
+
+ public ExternalComponent getRouter() {
+ return router;
+ }
}