aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com/juick/ws
diff options
context:
space:
mode:
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws')
-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
2 files changed, 24 insertions, 2 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);
+ }
}