Added c3p0 datasource configuration to Spring default-config-xml.

Change-Id: Iab9038233b8f74a4645e920ae2e009882a08ccf5
diff --git a/full/Changes b/full/Changes
index e458ca3..bc22985 100644
--- a/full/Changes
+++ b/full/Changes
@@ -33,6 +33,12 @@
 27/08/2018
     - Added statistic with VC reference tests (margaretha)
     - Fixed OAuth2 SQL files (margaretha) 
+28/08/2018
+    - Added c3p0 datasource configuration to Spring default-config-xml (margaretha)
+    - Added running Kustvakt server with custom spring config in the readme (margaretha)
+    - Removed old OAuth2 codes (margaretha)    
+    - Moved non-config test codes to misc (margaretha)
+    
 
 # version 0.60.5
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/AuthCodeInfo.java b/full/src/main/java/de/ids_mannheim/korap/config/AuthCodeInfo.java
deleted file mode 100644
index 03c22d5..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/config/AuthCodeInfo.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package de.ids_mannheim.korap.config;
-
-import lombok.Data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author hanl
- * @date 13/05/2015
- */
-@Data
-public class AuthCodeInfo {
-    private String clientId;
-    private String scopes;
-    private Integer userId;
-    private Boolean status;
-    private String code;
-    private List<String> tokens;
-
-
-    public AuthCodeInfo () {
-        this.setStatus(true);
-        this.tokens = new ArrayList<>();
-    }
-
-
-    public AuthCodeInfo (String clientid, String authcode) {
-        this();
-        this.clientId = clientid;
-        this.code = authcode;
-    }
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/OAuth2Handler.java b/full/src/main/java/de/ids_mannheim/korap/handlers/OAuth2Handler.java
deleted file mode 100644
index 28e848b..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/OAuth2Handler.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package de.ids_mannheim.korap.handlers;
-
-import de.ids_mannheim.korap.config.AuthCodeInfo;
-import de.ids_mannheim.korap.config.ClientInfo;
-import de.ids_mannheim.korap.config.KustvaktCacheable;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.user.User;
-
-/**
- * extends OAuthDb to allow temporary caching of tokens
- * and authorization codes.
- * Authorization codes are not persisted in db,
- * but stored in file of ehcache
- * 
- * @author hanl
- * @date 04/05/2015
- */
-public class OAuth2Handler extends KustvaktCacheable {
-
-    private OAuthDb oauthdb;
-
-    public OAuth2Handler (PersistenceClient client) {
-        super("auth_codes", "key:auth_codes");
-        this.oauthdb = new OAuthDb(client);
-    }
-
-
-    // fixme: caching should not be obligatory here. alternative to caching if not available?
-    public AuthCodeInfo getAuthorization (String code) {
-        Object value = this.getCacheValue(code);
-        if (value != null)
-            return (AuthCodeInfo) value;
-        return null;
-    }
-
-
-    public void authorize (AuthCodeInfo info, User user)  throws KustvaktException {
-    	
-        info.setUserId(user.getId());
-        this.storeInCache(info.getCode(), info);
-    }
-
-
-    public boolean addToken (String code, String token, String refresh, int ttl)
-            throws KustvaktException {
-        Object o = this.getCacheValue(code);
-        if (o != null) {
-            AuthCodeInfo info = (AuthCodeInfo) o;
-            this.removeCacheEntry(code);
-            return oauthdb.addToken(token, refresh, info.getUserId(),
-                    info.getClientId(), info.getScopes(), ttl);
-        }
-        return false;
-    }
-
-
-    public void exchangeToken (String refresh) {
-        // todo:
-    }
-
-    public OAuthDb getPersistenceHandler(){
-        return this.oauthdb;
-    }
-
-}
diff --git a/full/src/main/resources/default-config.xml b/full/src/main/resources/default-config.xml
index ac243e3..8a30f95 100644
--- a/full/src/main/resources/default-config.xml
+++ b/full/src/main/resources/default-config.xml
@@ -18,9 +18,6 @@
 	<context:component-scan base-package="de.ids_mannheim.korap" />
 	<context:annotation-config />
 
-	<!-- <bean id="test" class="de.ids_mannheim.korap.web.Test"> <property name="config" 
-		ref="kustvakt_config" /> </bean> -->
-
 	<bean id="props"
 		class="org.springframework.beans.factory.config.PropertiesFactoryBean">
 		<property name="ignoreResourceNotFound" value="true" />
@@ -70,9 +67,23 @@
 		<property name="maxTotal" value="4" />
 		<property name="maxIdle" value="2" />
 		<property name="minIdle" value="1" />
-		<property name="maxWaitMillis" value="15000" />
+		<property name="maxWaitMillis" value="-1" />
 		<!--<property name="poolPreparedStatements" value="true"/> -->
 	</bean>
+	
+	<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
+		destroy-method="close" lazy-init="true">
+		<property name="driverClass" value="${jdbc.driverClassName}" />
+		<property name="jdbcUrl" value="${jdbc.url}" />
+		<property name="user" value="${jdbc.username}" />
+		<property name="password" value="${jdbc.password}" />
+		<property name="maxPoolSize" value="4" />
+		<property name="minPoolSize" value="1" />
+		<property name="maxStatements" value="100" />
+		<!-- <property name="testConnectionOnCheckOut" value="true" /> -->
+		<property name="idleConnectionTestPeriod" value="60" />
+		<property name="testConnectionOnCheckin" value="true" />
+	</bean>
 
 	<bean id="sqliteDataSource"
 		class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
@@ -102,7 +113,9 @@
 		<!-- <property name="cleanOnValidationError" value="true" /> -->
 		<property name="locations" value="${jdbc.schemaPath}" />
 		<!-- <property name="dataSource" ref="dataSource" /> -->
-		<property name="dataSource" ref="sqliteDataSource" />
+		<!-- <property name="dataSource" ref="sqliteDataSource" /> -->
+		<property name="dataSource" ref="c3p0DataSource" />
+		
 	</bean>
 
 
@@ -115,7 +128,8 @@
 	<bean id="entityManagerFactory"
 		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
 		<!-- <property name="dataSource" ref="dataSource" /> -->
-		<property name="dataSource" ref="sqliteDataSource" />
+		<!-- <property name="dataSource" ref="sqliteDataSource" /> -->
+		<property name="dataSource" ref="c3p0DataSource" />
 
 		<property name="packagesToScan">
 			<array>
@@ -140,11 +154,6 @@
 				<prop key="hibernate.cache.provider_class">${hibernate.cache.provider}</prop>
 				<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory}</prop>
 				<prop key="hibernate.jdbc.time_zone">${hibernate.jdbc.time_zone}</prop>
-				<!-- <prop key="net.sf.ehcache.configurationResourceName">classpath:ehcache.xml</prop> -->
-				
-				<prop key="connection.autoReconnect">true</prop>
-				<prop key="connection.autoReconnectForPools">true</prop>
-				<prop key="connection.is-connection-validation-required">true</prop>
 			</props>
 		</property>
 	</bean>
@@ -328,7 +337,8 @@
 	<bean id="txManager"
 		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
 		<!-- <property name="dataSource" ref="dataSource" /> -->
-		<property name="dataSource" ref="sqliteDataSource" />
+		<!-- <property name="dataSource" ref="sqliteDataSource" /> -->
+		<property name="dataSource" ref="c3p0DataSource" />
 	</bean>
 
 	<!-- mail -->
diff --git a/full/src/main/resources/properties/jdbc.properties b/full/src/main/resources/properties/jdbc.properties
index 1f5e8ab..aea7ab9 100644
--- a/full/src/main/resources/properties/jdbc.properties
+++ b/full/src/main/resources/properties/jdbc.properties
@@ -4,7 +4,7 @@
 
 #jdbc.database=mysql
 #jdbc.driverClassName=com.mysql.jdbc.Driver
-#jdbc.url=jdbc:mysql://localhost:3306/kustvakt?autoReconnect=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
+#jdbc.url=jdbc:mysql://localhost:3306/kustvakt?useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
 #jdbc.username=korap
 #jdbc.password=password
 
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/BeanInjectTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/BeanInjectTest.java
similarity index 94%
rename from full/src/test/java/de/ids_mannheim/korap/config/BeanInjectTest.java
rename to full/src/test/java/de/ids_mannheim/korap/misc/BeanInjectTest.java
index 29a5e29..155e8be 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/BeanInjectTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/BeanInjectTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.config;
+package de.ids_mannheim.korap.misc;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -8,6 +8,7 @@
 import org.junit.Test;
 import org.springframework.aop.support.AopUtils;
 
+import de.ids_mannheim.korap.config.BeansFactory;
 import de.ids_mannheim.korap.handlers.DocumentDao;
 import de.ids_mannheim.korap.handlers.UserDetailsDao;
 import de.ids_mannheim.korap.handlers.UserSettingsDao;
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/ClassLoaderTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/ClassLoaderTest.java
similarity index 86%
rename from full/src/test/java/de/ids_mannheim/korap/config/ClassLoaderTest.java
rename to full/src/test/java/de/ids_mannheim/korap/misc/ClassLoaderTest.java
index fe2e35d..cae64f1 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/ClassLoaderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/ClassLoaderTest.java
@@ -1,10 +1,13 @@
-package de.ids_mannheim.korap.config;
+package de.ids_mannheim.korap.misc;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 
+import de.ids_mannheim.korap.config.BeanConfigTest;
+import de.ids_mannheim.korap.config.ContextHolder;
+import de.ids_mannheim.korap.config.DefaultHandler;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.handlers.JDBCAuditing;
 import de.ids_mannheim.korap.interfaces.db.AuditingIface;
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/ConfigTest.java
similarity index 93%
rename from full/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
rename to full/src/test/java/de/ids_mannheim/korap/misc/ConfigTest.java
index 380d5fb..734f78c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/ConfigTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.config;
+package de.ids_mannheim.korap.misc;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
@@ -13,6 +13,8 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
+import de.ids_mannheim.korap.config.BeanConfigTest;
+import de.ids_mannheim.korap.config.ConfigLoader;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.interfaces.EncryptionIface;
 import de.ids_mannheim.korap.utils.ServiceInfo;
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/ServiceSuite.java b/full/src/test/java/de/ids_mannheim/korap/misc/ServiceSuite.java
index 5ebf48e..662b96a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/ServiceSuite.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/ServiceSuite.java
@@ -1,5 +1,4 @@
 package de.ids_mannheim.korap.misc;
-import de.ids_mannheim.korap.config.ConfigTest;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/StringUtilsTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/StringUtilsTest.java
similarity index 97%
rename from full/src/test/java/de/ids_mannheim/korap/config/StringUtilsTest.java
rename to full/src/test/java/de/ids_mannheim/korap/misc/StringUtilsTest.java
index 80a3a87..b6859bb 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/StringUtilsTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/StringUtilsTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.config;
+package de.ids_mannheim.korap.misc;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceRemoteApiTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceRemoteApiTest.java
deleted file mode 100644
index 4fc436f..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceRemoteApiTest.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package de.ids_mannheim.korap.web.controller;
-
-import org.junit.Test;
-
-/**
- * @author hanl
- * @date 08/02/2016
- */
-public class ResourceRemoteApiTest {
-
-
-
-    @Test
-    public void testResourceGetFromDemo () {
-
-    }
-}