diff options
author | Vitaly Takmazov | 2017-11-02 16:02:17 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-11-02 16:12:40 +0300 |
commit | ee20020d9c576a48173c13b68b03d349c0ec3e47 (patch) | |
tree | 7c59dcac74cde4e5b819a245dc0fbbb315020f10 /juick-crosspost/src/main/java/com/juick/components | |
parent | 61c6a3fe338a5cbbef55081f8ac26011c053125d (diff) |
server-web: base websocket component with autoreconnect
Diffstat (limited to 'juick-crosspost/src/main/java/com/juick/components')
2 files changed, 15 insertions, 16 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostAppConfiguration.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostAppConfiguration.java index eae12e6c..76a909ad 100644 --- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostAppConfiguration.java +++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostAppConfiguration.java @@ -17,6 +17,8 @@ package com.juick.components.configuration; +import com.juick.server.component.JuickServerComponent; +import com.juick.server.component.JuickServerReconnectManager; import com.juick.server.configuration.BaseWebConfiguration; import com.juick.service.Crosspost; import org.springframework.beans.factory.annotation.Value; @@ -29,8 +31,6 @@ import org.springframework.http.client.InterceptingClientHttpRequestFactory; import org.springframework.http.client.support.BasicAuthorizationInterceptor; import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; import java.util.Collections; import java.util.List; @@ -47,7 +47,14 @@ public class CrosspostAppConfiguration extends BaseWebConfiguration { private String apiUser; @Value("${api_password:secret}") private String apiSecret; - + @Bean + public JuickServerComponent juickServerComponent() { + return new JuickServerComponent(); + } + @Bean + public JuickServerReconnectManager juickServerReconnectManager() { + return new JuickServerReconnectManager(); + } @Bean public RestTemplate rest() { RestTemplate rest = new RestTemplate(); @@ -57,22 +64,10 @@ public class CrosspostAppConfiguration extends BaseWebConfiguration { rest.setRequestFactory(new InterceptingClientHttpRequestFactory(rest.getRequestFactory(), interceptors)); return rest; } - private static final String WS_URI = "wss://ws.juick.com/"; @Bean public Crosspost crosspost() { return new Crosspost(); } - @Bean - public WebSocketConnectionManager connectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), crosspost(), WS_URI); - manager.setAutoStartup(true); - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } } diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java index 6a95c1f0..88280480 100644 --- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java +++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java @@ -17,6 +17,7 @@ package com.juick.components.configuration; +import com.juick.server.configuration.JuickServerComponentConfiguration; import org.apache.commons.codec.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -30,7 +31,10 @@ public class CrosspostInitializer extends AbstractAnnotationConfigDispatcherServ @Override protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{ CrosspostAppConfiguration.class }; + return new Class<?>[]{ + CrosspostAppConfiguration.class, + JuickServerComponentConfiguration.class + }; } @Override |