diff options
author | Alexander Alexeev | 2016-11-11 01:29:01 +0700 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-11 17:27:58 +0300 |
commit | 6604dc96558028c0095f33eca1852de5e61f8466 (patch) | |
tree | 5da1118a468d7142250112ee83f81b5849accdf0 /juick-ws/src/main/java | |
parent | 9077e9f21d785a6507aeb79d04faca2107aa80e4 (diff) |
common data configuration is added
Diffstat (limited to 'juick-ws/src/main/java')
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java | 31 | ||||
-rw-r--r-- | juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java | 13 |
2 files changed, 20 insertions, 24 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 5e035dac..db37edc4 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 @@ -9,7 +9,6 @@ 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.apache.commons.dbcp2.BasicDataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -40,29 +39,22 @@ import java.util.concurrent.Executors; @Configuration @EnableWebSocket @ComponentScan(basePackages = {"com.juick"}) -@PropertySource(value = "classpath:juick.conf", ignoreResourceNotFound = true) +@PropertySource(value = {"classpath:juick.conf", "file:${user.home}/juick.conf"}) public class WebsocketConfiguration extends WebMvcConfigurationSupport implements WebSocketConfigurer { @Inject - Environment env; + private Environment env; @Inject - ExecutorService service; + private JdbcTemplate jdbc; + @Inject + private ServletContext servletContext; + @Bean - WebsocketComponent wsHandler() { + public WebsocketComponent wsHandler() { return new WebsocketComponent(); } @Bean - JdbcTemplate jdbc() { - BasicDataSource dataSource = new BasicDataSource(); - dataSource.setDriverClassName(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver")); - dataSource.setUrl(env.getProperty("datasource_url")); - return new JdbcTemplate(dataSource); - } - @Inject - private ServletContext servletContext; - - @Bean - public Loader templateLoader(){ + public Loader templateLoader() { return new ServletLoader(servletContext); } @@ -87,10 +79,12 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement viewResolver.setPebbleEngine(pebbleEngine()); return viewResolver; } + @Bean public XMPPConnection ws() { - return new XMPPConnection(env, service); + return new XMPPConnection(env, service()); } + @Bean public ExecutorService service() { return Executors.newCachedThreadPool(); @@ -102,9 +96,10 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement mapping.setUseSuffixPatternMatch(false); return mapping; } + @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - ((ServletWebSocketHandlerRegistry)registry).setOrder(2); + ((ServletWebSocketHandlerRegistry) registry).setOrder(2); registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*"); } 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 89017f8b..4829710f 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 @@ -1,4 +1,6 @@ package com.juick.ws.configuration; + +import com.juick.configuration.DataConfiguration; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -10,24 +12,23 @@ import javax.servlet.Filter; public class WebsocketInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { - return new Class[] {WebsocketConfiguration.class}; + return new Class[]{DataConfiguration.class}; } @Override protected Class<?>[] getServletConfigClasses() { - return null; + return new Class[]{WebsocketConfiguration.class}; } @Override protected String[] getServletMappings() { - return new String[] { - "/" - }; + return new String[]{"/"}; } + @Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); - return new Filter[] { characterEncodingFilter}; + return new Filter[]{characterEncodingFilter}; } } |