aboutsummaryrefslogtreecommitdiff
path: root/juick-ws
diff options
context:
space:
mode:
Diffstat (limited to 'juick-ws')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/StatusController.java23
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java12
2 files changed, 33 insertions, 2 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/StatusController.java b/juick-ws/src/main/java/com/juick/ws/StatusController.java
new file mode 100644
index 000000000..3f1de4133
--- /dev/null
+++ b/juick-ws/src/main/java/com/juick/ws/StatusController.java
@@ -0,0 +1,23 @@
+package com.juick.ws;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.inject.Inject;
+
+/**
+ * Created by vitalyster on 19.07.2016.
+ */
+@Controller
+@ResponseBody
+public class StatusController {
+ @Inject
+ WebsocketComponent websocketComponent;
+
+ @RequestMapping(method = RequestMethod.GET, headers = "Connection!=Upgrade", value = "/")
+ public String status() {
+ return String.format("Clients: %d", websocketComponent.clients.size());
+ }
+}
diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
index 223f8d631..fbc6226b1 100644
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
+++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
@@ -10,7 +10,10 @@ import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping;
+import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
@@ -23,11 +26,10 @@ import java.util.concurrent.Executors;
* Created by vitalyster on 28.06.2016.
*/
@Configuration
-@EnableWebMvc
@EnableWebSocket
@ComponentScan(basePackages = {"com.juick"})
@PropertySource("classpath:juick.conf")
-public class WebsocketConfiguration extends WebMvcConfigurerAdapter implements WebSocketConfigurer {
+public class WebsocketConfiguration extends WebMvcConfigurationSupport implements WebSocketConfigurer {
@Inject
Environment env;
ExecutorService xmppThread = Executors.newSingleThreadExecutor();
@@ -49,6 +51,12 @@ public class WebsocketConfiguration extends WebMvcConfigurerAdapter implements W
return new JdbcTemplate(dataSource);
}
@Override
+ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
+ RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
+ mapping.setUseSuffixPatternMatch(false);
+ return mapping;
+ }
+ @Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*");
}