From cb3069187881fff788dd1155c95d65b406494cf4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 1 Nov 2017 17:03:16 +0300 Subject: api: reload web context on ws reconnection --- juick-api/src/main/java/com/juick/api/ApiServer.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'juick-api/src/main/java') 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 110d8e2f..d7862952 100644 --- a/juick-api/src/main/java/com/juick/api/ApiServer.java +++ b/juick-api/src/main/java/com/juick/api/ApiServer.java @@ -24,6 +24,9 @@ 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.context.support.AbstractApplicationContext; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.standard.StandardWebSocketClient; import rocks.xmpp.addr.Jid; @@ -38,6 +41,7 @@ import rocks.xmpp.extensions.oob.model.x.OobX; import javax.annotation.Nonnull; import javax.annotation.PostConstruct; import javax.inject.Inject; +import javax.servlet.ServletContext; import java.net.URI; import java.net.URISyntaxException; @@ -60,11 +64,7 @@ public class ApiServer implements ApplicationListener, AutoCl @Value("${xmpp_disabled:false}") private boolean isXmppDisabled; @Inject - private WebSocketConnectionManager webSocketConnectionManager; - @Inject - private StandardWebSocketClient client; - @Inject - private DefaultListableBeanFactory beanFactory; + private ServletContext servletContext; @PostConstruct public void init() { @@ -122,8 +122,8 @@ public class ApiServer implements ApplicationListener, AutoCl @Override public void onApplicationEvent(@Nonnull DisconnectedEvent event) { - logger.info("reconnecting websocket..."); - beanFactory.destroySingleton("client"); - beanFactory.destroySingleton("webSocketConnectionManager"); + logger.info("reloading app..."); + WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext); + ((AbstractApplicationContext) context).refresh(); } } -- cgit v1.2.3