aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-25 22:48:10 +0300
committerGravatar Vitaly Takmazov2016-07-27 13:56:45 +0300
commita18f5e5012b862992af40db60c83a40098342b53 (patch)
tree73f72b1ec6c374d92cc1ac714d5dc768956b2f4c /juick-ws/src
parent69af3f60d399157a8951988fa2f91d29c553fbb5 (diff)
fix ws configuration
Diffstat (limited to 'juick-ws/src')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java3
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java23
-rw-r--r--juick-ws/src/main/static/scripts.js4
3 files changed, 26 insertions, 4 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java b/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
index ada19f89..82e15765 100644
--- a/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
+++ b/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
@@ -1,5 +1,7 @@
package com.juick.ws.api;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
/**
* Created by vitalyster on 25.07.2016.
*/
@@ -10,6 +12,7 @@ public class WebSocketStatus {
clientsCount = count;
}
+ @JsonProperty("status")
public int getClientsCount() {
return clientsCount;
}
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 c25f8f42..ecd44908 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
@@ -1,5 +1,7 @@
package com.juick.ws.configuration;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.juick.ws.WebsocketComponent;
import com.juick.ws.XMPPConnection;
import com.mitchellbosecke.pebble.PebbleEngine;
@@ -13,19 +15,22 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
-import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import javax.inject.Inject;
import javax.servlet.ServletContext;
+import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -95,6 +100,7 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement
}
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
+ ((ServletWebSocketHandlerRegistry)registry).setOrder(2);
registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*");
}
@@ -104,4 +110,17 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement
registry.addResourceHandler("/scripts.js").addResourceLocations("/");
registry.addResourceHandler("/style.css").addResourceLocations("/");
}
+
+ @Override
+ protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
+ Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
+ .serializationInclusion(JsonInclude.Include.NON_DEFAULT)
+ .serializationInclusion(JsonInclude.Include.NON_NULL)
+ .serializationInclusion(JsonInclude.Include.NON_ABSENT)
+ .serializationInclusion(JsonInclude.Include.NON_EMPTY);
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
+ converter.getObjectMapper().registerModule(new Jdk8Module());
+ converters.add(converter);
+ super.configureMessageConverters(converters);
+ }
}
diff --git a/juick-ws/src/main/static/scripts.js b/juick-ws/src/main/static/scripts.js
index 2691816d..9b4c721f 100644
--- a/juick-ws/src/main/static/scripts.js
+++ b/juick-ws/src/main/static/scripts.js
@@ -10,7 +10,7 @@ function ready(fn) {
}
ready(function() {
- var ws = new WebSocket('wss://ws.juick.com/_replies');
+ var ws = new WebSocket('wss://ws.juick.com/');
var term = new Terminal('terminal', {}, {});
var status = document.querySelector("#status");
ws.onopen = function() {
@@ -30,7 +30,7 @@ ready(function() {
.then(function(response) {
return response.text();
}).then(function(body) {
- status.textContent = JSON.parse(body).clientsCount;
+ status.textContent = JSON.parse(body).status;
})
}, 5000);
}) \ No newline at end of file