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/configuration/WebsocketConfiguration.java31
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java13
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 5e035dac4..db37edc4f 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 89017f8ba..4829710f3 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};
}
}