Commit 937d1c30 authored by Matija Obreza's avatar Matija Obreza
Browse files

Build: App configuration fixed

parent ad9cbb06
......@@ -24,20 +24,26 @@ import org.genesys.filerepository.service.impl.ClamAVScanner;
import org.genesys.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys.filerepository.service.impl.S3StorageServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@Configuration
@ComponentScan({"org.genesys.filerepository.service", "org.genesys.catalog.service.impl", "org.genesys.catalog.util",
"org.genesys.blocks.security.service.*", "org.genesys.blocks.auditlog.service.impl",
"org.genesys.catalog.server.components", "org.genesys.blocks.security.component"})
"org.genesys.blocks.security.component"})
@EnableAspectJAutoProxy
public class ApplicationConfig {
......@@ -47,6 +53,36 @@ public class ApplicationConfig {
@Value("${CLAMD_PORT}")
private String clamdPortStr;
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
propertyPlaceholderConfigurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
propertyPlaceholderConfigurer.setFileEncoding("utf-8");
List<Resource> locations = new ArrayList<>();
locations.add(new ClassPathResource("application.properties"));
locations.add(new ClassPathResource("genesys-catalog.properties"));
locations.add(new ClassPathResource("genesys-catalog-server.properties"));
String extraConfigFile = System.getenv("config.file");
if (StringUtils.isNotBlank(extraConfigFile)) {
File f = new File(extraConfigFile);
if (f.exists() && f.canRead()) {
System.err.println("Including properties from config.file=" + extraConfigFile);
locations.add(new FileSystemResource(extraConfigFile));
} else {
System.err.println("Cannot read properties from config.file=" + extraConfigFile);
}
}
propertyPlaceholderConfigurer.setLocations(locations.toArray(new Resource[] {}));
return propertyPlaceholderConfigurer;
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
......
......@@ -15,8 +15,6 @@
*/
package org.genesys.catalog.server.config;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
......@@ -27,17 +25,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import org.apache.commons.lang3.StringUtils;
import org.genesys.catalog.server.components.AddStuffInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.genesys.catalog.server.components.StartupInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.CacheControl;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
......@@ -67,9 +60,6 @@ import org.springframework.web.servlet.view.JstlView;
@ComponentScan({ "org.genesys.catalog.server" })
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Autowired
private AddStuffInterceptor addStuffInterceptor;
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/html/**").addResourceLocations("/html/").setCacheControl(CacheControl.maxAge(42, TimeUnit.DAYS).cachePrivate());
......@@ -112,34 +102,6 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
registry.viewResolver(jstlViewResolver());
}
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
propertyPlaceholderConfigurer.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
propertyPlaceholderConfigurer.setFileEncoding("utf-8");
List<Resource> locations = new ArrayList<>();
locations.add(new ClassPathResource("application.properties"));
locations.add(new ClassPathResource("genesys-catalog.properties"));
locations.add(new ClassPathResource("genesys-catalog-server.properties"));
String extraConfigFile = System.getenv("config.file");
if (StringUtils.isNotBlank(extraConfigFile)) {
File f = new File(extraConfigFile);
if (f.exists() && f.canRead()) {
System.err.println("Including properties from config.file=" + extraConfigFile);
locations.add(new FileSystemResource(extraConfigFile));
} else {
System.err.println("Cannot read properties from config.file=" + extraConfigFile);
}
}
propertyPlaceholderConfigurer.setLocations(locations.toArray(new Resource[] {}));
return propertyPlaceholderConfigurer;
}
@Override
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
......@@ -152,13 +114,23 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
cookieLocaleResolver.setCookieMaxAge(100000);
return cookieLocaleResolver;
}
@Bean
public AddStuffInterceptor addStuffInterceptor() {
return new AddStuffInterceptor();
}
@Bean
public StartupInitializer startupInitializer() {
return new StartupInitializer();
}
@Override
public void addInterceptors(final InterceptorRegistry registry) {
final LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
interceptor.setParamName("lang");
registry.addInterceptor(interceptor);
registry.addInterceptor(addStuffInterceptor);
registry.addInterceptor(addStuffInterceptor());
}
@Bean(name = "messageSource")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment