aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java
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/main/java
parent69af3f60d399157a8951988fa2f91d29c553fbb5 (diff)
fix ws configuration
Diffstat (limited to 'juick-ws/src/main/java')
-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);
+ }
}