diff options
author | Alexander Alexeev | 2016-11-24 12:46:46 +0700 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-25 00:29:30 +0300 |
commit | d8f4849e84569436e36afb4c1e914b93d70370f7 (patch) | |
tree | 5727556dca69d406a567d753e16d0b055f15b239 /juick-ws | |
parent | 63f32f7c061d26b1bee8bba1c6c568a05e9d701f (diff) |
web socket configuration separated; header mapping fixed
Diffstat (limited to 'juick-ws')
4 files changed, 61 insertions, 38 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 new file mode 100644 index 00000000..e7f0042e --- /dev/null +++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java @@ -0,0 +1,53 @@ +package com.juick.ws.configuration; + +import com.juick.ws.WebsocketComponent; +import com.juick.ws.XMPPConnection; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; +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 org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; + +import javax.inject.Inject; + +/** + * Created by aalexeev on 11/24/16. + */ +@Configuration +@EnableWebSocket +@PropertySource("classpath:juick.conf") +class WebsocketConfiguration implements WebSocketConfigurer { + @Inject + private Environment env; + @Inject + private JdbcTemplate jdbc; + + @Bean + public WebsocketComponent wsHandler() { + return new WebsocketComponent(jdbc); + } + + @Bean + public XMPPConnection ws() { + return new XMPPConnection(env, wsHandler(), jdbc); + } + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + ((ServletWebSocketHandlerRegistry) registry).setOrder(2); + registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*"); + } + + @Bean + public ServletServerContainerFactoryBean createWebSocketContainer() { + ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); + container.setMaxTextMessageBufferSize(8192); + container.setMaxBinaryMessageBufferSize(8192); + return container; + } +} diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java index 785eefcf..751da635 100644 --- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java +++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java @@ -13,7 +13,7 @@ public class WebsocketInitializer extends AbstractAnnotationConfigDispatcherServ @Override protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{DataConfiguration.class}; + return new Class<?>[]{DataConfiguration.class, WebsocketConfiguration.class}; } @Override @@ -28,9 +28,7 @@ public class WebsocketInitializer extends AbstractAnnotationConfigDispatcherServ @Override protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); - characterEncodingFilter.setEncoding("UTF-8"); - return new Filter[]{characterEncodingFilter}; + return new Filter[]{new CharacterEncodingFilter("UTF-8")}; } @Override diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java index 4ae0a04a..fc373359 100644 --- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java +++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketMvcConfiguration.java @@ -2,30 +2,23 @@ package com.juick.ws.configuration; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.juick.configuration.DataConfiguration; -import com.juick.ws.WebsocketComponent; -import com.juick.ws.XMPPConnection; import com.mitchellbosecke.pebble.PebbleEngine; import com.mitchellbosecke.pebble.loader.Loader; import com.mitchellbosecke.pebble.loader.ServletLoader; import com.mitchellbosecke.pebble.spring4.PebbleViewResolver; import com.mitchellbosecke.pebble.spring4.extension.SpringExtension; -import org.springframework.context.annotation.*; -import org.springframework.core.env.Environment; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; 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.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.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 java.util.List; /** @@ -33,29 +26,8 @@ import java.util.List; */ @Configuration @ComponentScan(basePackages = {"com.juick.ws.controllers"}) -@EnableWebSocket @PropertySource("classpath:juick.conf") -public class WebsocketMvcConfiguration extends WebMvcConfigurationSupport implements WebSocketConfigurer { - @Inject - private Environment env; - @Inject - private JdbcTemplate jdbc; - - @Bean - public WebsocketComponent wsHandler() { - return new WebsocketComponent(jdbc); - } - - @Bean - public XMPPConnection ws() { - return new XMPPConnection(env, wsHandler(), jdbc); - } - - @Override - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - ((ServletWebSocketHandlerRegistry) registry).setOrder(2); - registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*"); - } +public class WebsocketMvcConfiguration extends WebMvcConfigurationSupport { @Bean public Loader templateLoader() { diff --git a/juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java b/juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java index 2fe55eeb..28766a29 100644 --- a/juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java +++ b/juick-ws/src/main/java/com/juick/ws/controllers/StatusController.java @@ -21,7 +21,7 @@ public class StatusController { @Inject XMPPConnection ws; - @RequestMapping(method = RequestMethod.GET, headers = "Connection!=upgrade", value = "/") + @RequestMapping(method = RequestMethod.GET, headers = "Connection!=Upgrade", value = "/") public ModelAndView status() { ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("clients", wsHandler.getClients().size()); |