diff options
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/ApiServer.java')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/ApiServer.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/juick-api/src/main/java/com/juick/api/ApiServer.java b/juick-api/src/main/java/com/juick/api/ApiServer.java index a5bf5d38..110d8e2f 100644 --- a/juick-api/src/main/java/com/juick/api/ApiServer.java +++ b/juick-api/src/main/java/com/juick/api/ApiServer.java @@ -17,10 +17,15 @@ package com.juick.api; import com.juick.User; +import com.juick.server.component.DisconnectedEvent; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.context.ApplicationListener; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; import rocks.xmpp.addr.Jid; import rocks.xmpp.core.XmppException; import rocks.xmpp.core.session.Extension; @@ -30,14 +35,16 @@ import rocks.xmpp.core.stanza.model.Message; import rocks.xmpp.extensions.component.accept.ExternalComponent; import rocks.xmpp.extensions.oob.model.x.OobX; +import javax.annotation.Nonnull; import javax.annotation.PostConstruct; +import javax.inject.Inject; import java.net.URI; import java.net.URISyntaxException; /** * @author Ugnich Anton */ -public class ApiServer implements AutoCloseable { +public class ApiServer implements ApplicationListener<DisconnectedEvent>, AutoCloseable { private static Logger logger = LoggerFactory.getLogger(ApiServer.class); private ExternalComponent xmpp; @@ -52,6 +59,12 @@ public class ApiServer implements AutoCloseable { private int xmppPort; @Value("${xmpp_disabled:false}") private boolean isXmppDisabled; + @Inject + private WebSocketConnectionManager webSocketConnectionManager; + @Inject + private StandardWebSocketClient client; + @Inject + private DefaultListableBeanFactory beanFactory; @PostConstruct public void init() { @@ -106,4 +119,11 @@ public class ApiServer implements AutoCloseable { logger.warn("attachment error", e1); } } + + @Override + public void onApplicationEvent(@Nonnull DisconnectedEvent event) { + logger.info("reconnecting websocket..."); + beanFactory.destroySingleton("client"); + beanFactory.destroySingleton("webSocketConnectionManager"); + } } |