diff --git a/src/main/java/de/thm/arsnova/config/ExtraConfig.java b/src/main/java/de/thm/arsnova/config/ExtraConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..d33ce426f17f2a8d5d066861cb4f926e18c2cc56 --- /dev/null +++ b/src/main/java/de/thm/arsnova/config/ExtraConfig.java @@ -0,0 +1,41 @@ +package de.thm.arsnova.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.PropertySources; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.env.Environment; + +import de.thm.arsnova.connector.client.ConnectorClient; +import de.thm.arsnova.connector.client.ConnectorClientImpl; + +@Configuration +@PropertySources({ + @PropertySource("arsnova.properties.example"), + @PropertySource("file:///etc/arsnova/connector.properties"), +}) +public class ExtraConfig { + + @Autowired + private Environment env; + + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + + @Bean(name = "connectorClient") + public ConnectorClient connectorClient() { + if (! "true".equals(env.getProperty("connector.enable"))) { + return null; + } + + ConnectorClientImpl connectorClient = new ConnectorClientImpl(); + connectorClient.setServiceLocation(env.getProperty("connector.uri")); + connectorClient.setUsername(env.getProperty("connector.username")); + connectorClient.setPassword(env.getProperty("connector.password")); + return connectorClient; + } +} diff --git a/src/main/java/de/thm/arsnova/config/package-info.java b/src/main/java/de/thm/arsnova/config/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..87aa446414d10c887a085626b792f718940b9b29 --- /dev/null +++ b/src/main/java/de/thm/arsnova/config/package-info.java @@ -0,0 +1 @@ +package de.thm.arsnova.config; diff --git a/src/main/webapp/WEB-INF/spring/spring-main.xml b/src/main/webapp/WEB-INF/spring/spring-main.xml index 894bf271a1bbf55d713d1dd9c73eed886d2ea387..31686a7ec970729b40b5f2063b216bb598ef45a5 100644 --- a/src/main/webapp/WEB-INF/spring/spring-main.xml +++ b/src/main/webapp/WEB-INF/spring/spring-main.xml @@ -23,7 +23,7 @@ </bean> <context:component-scan - base-package="de.thm.arsnova.dao,de.thm.arsnova.services,de.thm.arsnova.events" /> + base-package="de.thm.arsnova.dao,de.thm.arsnova.services,de.thm.arsnova.events,de.thm.arsnova.config" /> <context:annotation-config /> <task:annotation-driven /> @@ -43,11 +43,4 @@ <bean id="userService" scope="singleton" class="de.thm.arsnova.services.UserService" /> <bean id="databaseDao" class="de.thm.arsnova.dao.CouchDBDao" /> - - <!-- Example of connector client configuration --> - <!-- Uncomment bean definition to activate connector --> - <!-- bean id="connectorClient" scope="singleton" class="de.thm.arsnova.connector.client.ConnectorClientImpl"> - <property name="serviceLocation" value="${connector.uri}"></property> <property - name="username" value="${connector.username}"></property> <property name="password" - value="${connector.password}"></property> </bean --> </beans> diff --git a/src/main/webapp/arsnova.properties.example b/src/main/webapp/arsnova.properties.example index 678e41714db1ab3a418171b325721564d19f0b19..e92e71bf6b7326eac6ad958b634304ee741472dc 100644 --- a/src/main/webapp/arsnova.properties.example +++ b/src/main/webapp/arsnova.properties.example @@ -29,6 +29,7 @@ couchdb.password= socketio.ip=0.0.0.0 socketio.port=10443 +connector.enable=false connector.uri=http://localhost:8080/connector-service connector.username=test connector.password=test diff --git a/src/test/java/de/thm/arsnova/config/ExtraConfigTest.java b/src/test/java/de/thm/arsnova/config/ExtraConfigTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ea65c72a73dd9c4c8bb469cc81e93429f4c936bb --- /dev/null +++ b/src/test/java/de/thm/arsnova/config/ExtraConfigTest.java @@ -0,0 +1,37 @@ +package de.thm.arsnova.config; + +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import de.thm.arsnova.connector.client.ConnectorClient; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration(locations = { + "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", + "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", + "file:src/test/resources/test-config.xml", + "file:src/test/resources/test-socketioconfig.xml" +}) +public class ExtraConfigTest { + + @Autowired + PropertySourcesPlaceholderConfigurer configurer; + + @Autowired(required = false) + private ConnectorClient connectorClient; + + @Test + public void testShouldNotLoadConnectorClientByDefault() { + assertNull(connectorClient); + } + +} diff --git a/src/test/resources/arsnova.properties.example b/src/test/resources/arsnova.properties.example index 00c73a8d1f13c8447711d48b080be7cd480e78bb..f5830dcb6d2a79fb1f5a9e5564e36a895a9ea5da 100644 --- a/src/test/resources/arsnova.properties.example +++ b/src/test/resources/arsnova.properties.example @@ -27,6 +27,7 @@ upload.filesize_b=1048576 socketio.ip=0.0.0.0 socketio.port=10443 +connector.enable=false connector.uri=http://localhost:8080/connector-service connector.username=test connector.password=test