aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp-ft
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-11-12 01:34:07 +0700
committerGravatar Vitaly Takmazov2016-11-12 11:14:56 +0300
commit194a9a763c6b11d207e682b2f93de94475c473b4 (patch)
tree196317662017b716066eadfa413ecbdc7532c52d /juick-xmpp-ft
parent7d86347a351aa5263c19cd03aa0bda4650c8bfca (diff)
extracted application configuration from Mvc configuration with application specific beans;
extracted bean initialization from constructor; force using properties;
Diffstat (limited to 'juick-xmpp-ft')
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferAppConfiguration.java38
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferConfiguration.java107
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java19
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferMvcConfiguration.java33
4 files changed, 84 insertions, 113 deletions
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferAppConfiguration.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferAppConfiguration.java
new file mode 100644
index 00000000..88579328
--- /dev/null
+++ b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferAppConfiguration.java
@@ -0,0 +1,38 @@
+package com.juick.components.configuration;
+
+import com.juick.components.XMPPFTServer;
+import com.juick.configuration.DataConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.inject.Inject;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Created by aalexeev on 11/12/16.
+ */
+@Configuration
+@PropertySource("classpath:juick.conf")
+@Import(DataConfiguration.class)
+public class FileTransferAppConfiguration {
+ @Inject
+ private Environment env;
+ @Inject
+ private JdbcTemplate jdbc;
+
+ @Bean
+ public XMPPFTServer xmpp() {
+ return new XMPPFTServer(env);
+ }
+
+ @Bean
+ public ExecutorService service() {
+ return Executors.newCachedThreadPool();
+ }
+
+}
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferConfiguration.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferConfiguration.java
deleted file mode 100644
index de47ddc9..00000000
--- a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferConfiguration.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package com.juick.components.configuration;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import com.juick.components.XMPPFTServer;
-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.apache.commons.dbcp2.BasicDataSource;
-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.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.ViewResolver;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * Created by vitalyster on 28.06.2016.
- */
-@Configuration
-@ComponentScan(basePackages = {"com.juick"})
-@PropertySource(value = "classpath:juick.conf", ignoreResourceNotFound = true)
-public class FileTransferConfiguration extends WebMvcConfigurationSupport {
- @Inject
- Environment env;
- @Inject
- ExecutorService service;
-
- @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(){
- return new ServletLoader(servletContext);
- }
-
- @Bean
- public SpringExtension springExtension() {
- return new SpringExtension();
- }
-
- @Bean
- public PebbleEngine pebbleEngine() {
- return new PebbleEngine.Builder()
- .loader(this.templateLoader())
- .extension(springExtension())
- .build();
- }
-
- @Bean
- public ViewResolver viewResolver() {
- PebbleViewResolver viewResolver = new PebbleViewResolver();
- viewResolver.setPrefix("/WEB-INF/templates/");
- viewResolver.setSuffix(".html");
- viewResolver.setPebbleEngine(pebbleEngine());
- return viewResolver;
- }
- @Bean
- public XMPPFTServer xmpp() {
- return new XMPPFTServer(env);
- }
- @Bean
- public ExecutorService service() {
- return Executors.newCachedThreadPool();
- }
-
- @Override
- protected void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.setOrder(0);
- 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);
- }
-}
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java
index db514e21..bf0e7257 100644
--- a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java
+++ b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java
@@ -1,4 +1,6 @@
package com.juick.components.configuration;
+
+import com.juick.configuration.DataConfiguration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -8,26 +10,31 @@ import javax.servlet.Filter;
* Created by vt on 09/02/16.
*/
public class FileTransferInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
+
@Override
protected Class<?>[] getRootConfigClasses() {
- return new Class[] {FileTransferConfiguration.class};
+ return new Class<?>[]{FileTransferAppConfiguration.class, DataConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
- return null;
+ return new Class<?>[]{FileTransferMvcConfiguration.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};
+ }
+
+ @Override
+ protected String getServletName() {
+ return "File transfer dispantcher servlet";
}
}
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferMvcConfiguration.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferMvcConfiguration.java
new file mode 100644
index 00000000..9500f4e6
--- /dev/null
+++ b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferMvcConfiguration.java
@@ -0,0 +1,33 @@
+package com.juick.components.configuration;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+
+import java.util.List;
+
+/**
+ * Created by vitalyster on 28.06.2016.
+ */
+@Configuration
+@ComponentScan(basePackages = {"com.juick.components.controllers"})
+public class FileTransferMvcConfiguration extends WebMvcConfigurationSupport {
+
+ @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);
+ }
+}