diff options
author | 2016-07-25 22:48:10 +0300 | |
---|---|---|
committer | 2016-07-27 13:56:45 +0300 | |
commit | a18f5e5012b862992af40db60c83a40098342b53 (patch) | |
tree | 73f72b1ec6c374d92cc1ac714d5dc768956b2f4c /juick-ws/src/main/java/com/juick/ws/configuration | |
parent | 69af3f60d399157a8951988fa2f91d29c553fbb5 (diff) |
fix ws configuration
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws/configuration')
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java | 23 |
1 files changed, 21 insertions, 2 deletions
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); + } } |