Index: src/webservice/config/config.php.in
===================================================================
--- src/webservice/config/config.php.in	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ src/webservice/config/config.php.in	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -24,31 +24,6 @@
 	"mode" => "@WEBSERVICE_MODE@",
 	"webserviceBaseUrl" => "http://localhost@WEBSERVICE_BASE_URL@/",
+	"spatialiteExtension" => "mod_spatialite.so",
 ];
 
-///////////////////////////
-//
-// DO NOT MODIFY THIS FILE BELOW THIS LINE
-//
-///////////////////////////
-
-$config["dataDirectory"] = "data";
-
-
-function getConfig($key){
-	global $config;
-
-	if(!arraY_key_exists($key, $config)){
-		error_log("Expected config value ". $key ." does not exists");
-		return FALSE;
-	}
-	return $config[$key];
-}
-
-if(getConfig("mode") == "development"){
-	error_reporting(E_ALL);
-}
-
-set_include_path(get_include_path() . PATH_SEPARATOR . "../vendor/");
-require("../vendor/autoload.php");
-
 ?>
Index: src/webservice/htaccess.in
===================================================================
--- src/webservice/htaccess.in	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ src/webservice/htaccess.in	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -24,3 +24,3 @@
 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
 RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
-RewriteRule ^@WEBSERVICE_BASE_URL@/v@WEBSERVICE_API_VERSION@ @WEBSERVICE_BASE_URL@/index.php [QSA,L]
+RewriteRule ^@WEBSERVICE_API_VERSION@ @WEBSERVICE_BASE_URL@/index.php [QSA,L]
Index: src/webservice/htdocs/SiWeather/Webservice/DataDirectoryChecks.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/DataDirectoryChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/DataDirectoryChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,34 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+
+namespace SiWeather\Webservice;
+
+abstract class DataDirectoryChecks
+{
+	const Success = 0;
+	const Error = 1;
+	const NoConfiguration = 2;
+	const NoDirectoryPath = 3;
+    const NotExist = 4;
+    const DirectoryNotWritable = 5;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/DatabaseChecks.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/DatabaseChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/DatabaseChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,35 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+
+namespace SiWeather\Webservice;
+
+abstract class DatabaseChecks
+{
+	const Success = 0;
+	const Error = 1;
+    const NoDatabaseFile = 2;
+    const NoDirectoryPath = 3;
+    const DirectoryDoesNotExist = 4;
+    const DirectoryNotWritable = 5;
+    const DatabaseFileNotWritable = 6;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,163 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace SiWeather\Webservice;
+
+/**
+	* @brief Manages the database connection for SiWeather webservice
+	* @note This class needs to load the SpatialLite SQLite extension.
+	*       Therefore the sqlite3.extension_dir in php.ini must be set
+  *       to a path, where this extension could be found!
+	*/
+class DatabaseHandler {
+	function __construct()
+	{
+		$this->_config = new WebserviceConfig();
+	
+		$this->_lastErrorMessage = "";
+		$this->_database = null;
+		if(!$this->_config->dataDirectory()){
+			$this->_lastErrorMessage = "No data directory set!";
+			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
+			$this->databaseFile = null;
+		}
+		else{
+			$this->_databaseFile = $this->_config->dataDirectory() ."/siweather.sqlite";
+		}
+	}
+
+	function __destruct()
+	{
+		if(!is_null($this->_database)){
+			$this->close();
+		}
+	}
+
+	public function databaseFile()
+	{
+		return $this->_databaseFile;
+	}
+
+	public function lastErrorMessage()
+	{
+		return $this->_lastErrorMessage;
+	}
+
+	public function connect()
+	{
+		if(!is_null($this->_database)){
+			return true;
+		}
+		if(is_null($this->_databaseFile)){
+			$this->_lastErrorMessage = "No database file given";
+			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
+			return false;
+		}
+		try {
+			$db = new \SQLite3($this->_databaseFile);
+		}
+		catch(PDOException $exception){
+			$this->_lastErrorMessage = $exception->getMessage();
+			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
+			return false;
+		}
+		# loading SpatiaLite as an extension
+		$extension = $this->_config->getConfig("spatialiteExtension");
+		if(empty($extension)){
+			$this->_lastErrorMessage("No spatialiteExtension set!");
+			error_log($this->lastErrorMessage());
+			return false;
+		}
+		if(!$db->loadExtension($extension)){
+			$this->_lastErrorMessage = "Could not load SpatialLite extension: ". $db->lastErrorMsg();
+			error_log($this->lastErrorMessage());
+			return false;
+		}
+		$this->_database = $db;
+		return true;
+	}
+
+	public function close()
+	{
+		if(is_null($this->_database)){
+			return true;
+		}
+		if($this->_database->close()){
+			$this->_database = null;
+			return true;
+		}
+		$this->_lastErrorMessage = $this->_database->lastErrorMsg();
+		error_log("Failed to close the database: "+ $this->lastErrorMessage());
+		return false;
+	}
+	
+	public function exec($query)
+	{
+		if(!$this->connect()){
+			return false;
+		}
+		return $this->_database->exec($query);
+	}
+	
+	public function prepare($query)
+	{
+		if(!$this->connect()){
+			return false;
+		}
+		return $this->_database->prepare($query);
+	}
+	
+	public function versionSpatialite(){
+		if(is_null($this->_database)){
+			$this->_lastErrorMessage("Unknown (No database connection)");
+			return 0;
+		}
+		if(!$this->connect()){
+			return 0;
+		}
+		$result = $this->_database->query("SELECT spatialite_version()");
+		while($row = $result->fetchArray()){
+			return $row[0];
+		}
+		return 0;
+	}
+	
+	public function versionSqlite(){
+		if(is_null($this->_database)){
+			$this->_lastErrorMessage("Unknown (No database connection)");
+			return 0;
+		}
+		if(!$this->connect()){
+			return 0;
+		}
+		$result = $this->_database->query("SELECT sqlite_version()");
+ 		while($row = $result->fetchArray()){
+			return $row[0];
+		}
+		return 0;
+	}
+	
+	private $_database;
+	private $_databaseFile;
+	private $_lastErrorMessage;
+	private $_config;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/Setup.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/Setup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/Setup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,290 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace SiWeather\Webservice;
+
+/**
+  * @brief Configures the Webservice and creates all needed files and directories (e.g. Databases)
+  *
+  * @note Requires php-posix!
+  */
+class Setup {
+
+	public function __construct(){
+		$this->_webserviceConfig = new WebserviceConfig();
+		$this->_dataDirectory = $this->_webserviceConfig->getConfig("dataDirectory");
+		$this->_databaseHandler = new DatabaseHandler();
+		$this->_databaseFile = $this->_databaseHandler->databaseFile();
+		$this->_databaseDirectory = pathinfo($this->_databaseFile, PATHINFO_DIRNAME);
+	}
+	
+	/**
+	  * @brief Checks if data directory is present and writable  and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DataDirectoryChecks
+	  * @see dataDirectoryCreate()
+	  */
+	public function dataDirectoryCheck(&$errorMessage){
+		if(!is_object($this->_webserviceConfig)){
+			$errorMessage = "Could not load the webservice configuration";
+			return DataDirectoryChecks::NoConfiguration;
+		}
+		if(!$this->_dataDirectory || empty($this->_dataDirectory)){
+			$errorMessage = "Could not determine dataDirectory setting";
+			return DataDirectoryChecks::NoDirectoryPath;
+		}
+		if(!is_dir($this->_dataDirectory)){
+			$errorMessage = "Data directory does not exists";
+			return DataDirectoryChecks::NotExist;
+		}
+		if(!is_writable($this->_dataDirectory)){
+			$errorMessage = "Data directory is not writable for ". $this->getProcessUser() .":". $this->getProcessGroup() ." (". $this->_dataDirectory .")";
+			return DataDirectoryChecks::NotWritable;
+		}
+		return DataDirectoryChecks::Success;
+	}
+	
+	/**
+	  * @brief Creates the data directory and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DataDirectoryChecks
+	  * @see dataDirectoryCreate()
+	  */
+	public function dataDirectoryCreate(&$errorMessage){
+		$result = $this->dataDirectoryCheck($errorMessage);
+		if($result == DataDirectoryChecks::Success){
+			return DataDirectoryChecks::Success;
+		}
+		if($result == DataDirectoryChecks::NoConfiguration || $result == DataDirectoryChecks::NoDirectoryPath || $result == DataDirectoryChecks::DirectoryNotWritable){
+			return $result;
+		}
+		if(!mkdir($this->_dataDirectory)){
+			$errorMessage = "Could not create data directory (". $this->_dataDirectory .")";
+			return DataDirectoryChecks::Error;
+		}
+		return DataDirectoryChecks::Success;
+	}
+	
+	/**
+	  * @brief Checks everything related to the database path and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DatabaseDirectoryChecks
+	  * @see databaseDirectoryCreate()
+	  */
+	public function databaseDirectoryCheck(&$errorMessage){
+		if(is_null($this->_databaseDirectory) || empty($this->_databaseDirectory)){
+			$errorMessage = "Failed to extract directory from database file path ("+ $this->_databaseFile +")";
+			return DatabaseChecks::NoDirectoryPath;
+		}
+		if(!is_dir($this->_databaseDirectory)){
+			$errorMessage = "Database directory does not exists (". $this->_databaseDirectory .")";
+			return DatabaseChecks::DirectoryDoesNotExist;
+		}
+		if(!is_writable($this->_databaseDirectory)){
+			$errorMessage = "Database directory is not writable  for ". $this->getProcessUser() .":". $this->getProcessGroup() ." (". $this->_databaseDirectory .")";
+			return DatabaseChecks::DirectoryNotWritable;
+		}
+		return DatabaseChecks::Success;
+	}
+	
+	/**
+	  * @brief Creates the database directory  and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DatabaseDirectoryChecks
+	  * @see databaseDirectoryCheck()
+	  */
+	public function databaseDirectoryCreate(&$errorMessage){
+		$result = $this->databaseDirectoryChecks($errorMessage);
+		if($result == DatabaseChecks::Success){
+			return DatabaseChecks::Success;
+		}
+		if($result == DatabaseChecks::NoDatabaseFile || $result == DatabaseChecks::NoDirectoryPath || $result == DatabaseChecks::DirectoryNotWritable){
+			return $result;
+		}
+		if(!mkdir($this->_databaseDirectory)){
+			$errorMessage = "Could not create database directory (". $this->_databaseDirectory .")";
+			return DatabaseChecks::Error;
+		}
+		return DatabaseChecks::Success;
+	}
+	
+	/**
+	  * @brief Checks, if the database file is given and is in a writable path
+	  *
+	  * The database file itself is created by the DatabaseHandler. Therefore
+	  * this function only checks, if the database directory exists, and it must be
+	  * writable.
+	  *
+	  * @see DatabaseChecks
+	  * @see databaseDirectoryCheck()
+	  */
+	public function databaseFileCheck(&$errorMessage){
+		if(is_null($this->_databaseFile) || empty($this->_databaseFile)){
+			$errorMessage = "No database file given (". $this->_databaseHandler->lastErrorMessage() .")";
+			return DatabaseChecks::NoDatabaseFile;
+		}
+		if(file_exists($this->_databaseFile)){
+			if(!is_writable($this->_databaseFile)){
+				$errorMessage = "Database file is not writable for ". $this->getProcessUser() .":". $this->getProcessGroup() ." (". $this->_databaseFile .")";
+				return DatabaseChecks::DatabaseFileNotWritable;
+			}
+			return DatabaseChecks::Success;
+		}
+		// if the databaseDirectoryCheck function return something other than success,
+		// we probably have a problem (like no write permission, ...)
+		if($this->databaseDirectoryCheck($errorMessage) != DatabaseChecks::Success){
+			return DatabaseChecks::Error;
+		}
+		return DatabaseChecks::Success;
+	}
+
+	public function databaseConnection(&$errorMessage){
+		if(!is_object($this->_databaseHandler)){
+			$errorMessage = "No database handler";
+			return false;
+		}
+		if(!$this->_databaseHandler->connect()){
+			$errorMessage = "Could not connect to the database (". $db->lastErrorMessage() .")";
+			return false;
+		}
+		
+		// prepare Spatalite
+		if(!$this->_databaseHandler->exec("BEGIN")){
+			$errorMessage = "Could not start transaction to init Spatialite";
+			return false;
+		}
+		if(!$this->_databaseHandler->exec("SELECT InitSpatialMetadata()")){
+			$errorMessage = "Could not initiate Spatialite metadata";
+			return false;
+		}
+		if(!$this->_databaseHandler->exec("COMMIT")){
+			$errorMessage = "Could not commit transaction to init Spatialite";
+			return false;
+		}
+		
+		return true;
+	}
+	
+	public function databaseVersionSqlite(&$errorMessage){
+		if(!is_object($this->_databaseHandler)){
+			return 0;
+		}
+		$result =  $this->_databaseHandler->versionSqlite();
+		if($result == 0){
+			$errorMessage = $this->_databaseHandler->lastErrorMessage();
+		}
+		return $result;
+	}
+	
+	public function databaseVersionSpatalite(&$errorMessage){
+		if(!is_object($this->_databaseHandler)){
+			return 0;
+		}
+		$result = $this->_databaseHandler->versionSpatialite();
+		if($result == 0){
+			$errorMessage = $this->_databaseHandler->lastErrorMessage();
+		}
+		return $result;
+	}
+	
+	public function apiCheckWithoutRewrite(&$errorMessage){
+		return $this->apiCheck("index.php/stations", $errorMessage);
+	}
+	
+	public function apiCheckWithRewrite(&$errorMessage){
+		$apiVersion = $this->_webserviceConfig->getConfig("webserviceApiVersion");
+		if(!$apiVersion || empty($apiVersion)){
+			$errorMessage = "Could not determine API version";
+			return false;
+		}
+		
+		return $this->apiCheck($apiVersion ."/stations", $errorMessage);
+	}
+
+	private function getProcessUser(){
+		$processUser = posix_getpwuid(posix_getuid());
+		return $processUser["name"];
+	}
+	
+	private function getProcessGroup(){
+		$processGroup = posix_getgrgid(posix_getgid());
+		return $processGroup["name"];
+	}
+	
+	private function apiCheck($url, &$errorMessage){
+		$baseUrl = $this->_webserviceConfig->getConfig("webserviceBaseUrl");
+		if(!$baseUrl || empty($baseUrl)){
+			$errorMessage = "No webservice base url given!";
+			return false;
+		}
+
+		$client = new \GuzzleHttp\Client
+		(
+			[
+				"base_uri" => $baseUrl,
+				"timeout" => 2.0,
+				"http_errors" => false,
+			]
+		);
+		$response = $client->get($url);
+		if(is_null($response)){
+			$errorMessage = "Webservice has not answered at url ". $baseUrl ."!";
+			return false;
+		}
+		$result = $response->getStatusCode();
+		if($result != 200){
+			$errorMessage = "Got http error ". $result ." (". $response->getReasonPhrase() .")";
+			return false;
+		}
+		$result = $response->getReasonPhrase();
+		if($result != "OK"){
+			$errorMessage = "Got a http error reason with http code 200: ". $result;
+			return false;
+		}
+
+		$body = $response->getBody();
+		if(empty($body)){
+			$errorMessage = "Got empty return value";
+			return false;
+		}
+		
+		$json = json_decode($body);
+		if(is_null($json)){
+			$errorMessage = "Could not decode json message body";
+			return false;
+		}
+		return true;
+	}
+
+	private $_webserviceConfig;
+	private $_dataDirectory;
+	private $_databaseHandler;
+	private $_databaseFile;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,60 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace SiWeather\Webservice;
+
+class WebserviceConfig {
+
+	function __construct(){
+		require(__DIR__ ."/../../config/config.php");
+		$this->_config = $config;
+		$this->loadAdditionalConfiguration();
+
+		if($this->getConfig("mode") == "development"){
+			error_reporting(E_ALL);
+		}
+	}
+	
+	private function loadAdditionalConfiguration(){
+		$this->_config["dataDirectory"] = "data";
+	}
+
+	public function getConfig($key){
+		if(!array_key_exists($key, $this->_config)){
+			error_log("Expected config value ". $key ." does not exists");
+			return FALSE;
+		}
+		
+		if($key == "dataDirectory"){
+// 			error_log("Use dataDirectory() function to access this value");
+			return $this->dataDirectory();
+		}
+		
+		return $this->_config[$key];
+	}
+
+	public function dataDirectory(){
+		return __DIR__ ."/../../". $this->_config["dataDirectory"];
+	}
+
+	private $_config;
+}
+
+?>
Index: src/webservice/htdocs/inc/DatabaseHandler.php
===================================================================
--- src/webservice/htdocs/inc/DatabaseHandler.php	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ 	(revision )
@@ -1,109 +1,0 @@
-<?php
-/*
-    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-    MA 02110-1301  USA.
-*/
-
-require_once("config/config.php");
-
-/**
-	* @brief Manages the database connection for SiWeather webservice
-	* @note This class needs to load the SpatialLite SQLite extension.
-	*       Therefore the sqlite3.extension_dir in php.ini must be set
-  *       to a path, where this extension could be found!
-	*/
-class DatabaseHandler {
-	private $_database;
-	private $_databaseFile;
-	private $_lastErrorMessage;
-
-	function __construct()
-	{
-		$this->_lastErrorMessage = "";
-		$this->_database = null;
-		if(!getConfig("dataDirectory")){
-			$this->_lastErrorMessage = "No data directory set!";
-			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
-			$this->databaseFile = null;
-		}
-		else{
-			$this->_databaseFile = getConfig("dataDirectory") ."/siweather.sqlite";
-		}
-	}
-
-	function __destruct()
-	{
-		if(!is_null($this->_database)){
-			$this->close();
-		}
-	}
-
-	public function databaseFile()
-	{
-		return $this->_databaseFile;
-	}
-
-	public function lastErrorMessage()
-	{
-		return $this->_lastErrorMessage;
-	}
-
-	public function connect()
-	{
-		if(!is_null($this->_database)){
-			echo "database is not null";
-			return true;
-		}
-		if(is_null($this->_databaseFile)){
-			$this->_lastErrorMessage = "No database file given";
-			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
-			return false;
-		}
-		try {
-			$db = new SQLite3($this->_databaseFile);
-		}
-		catch(PDOException $exception){
-			$this->_lastErrorMessage = $exception->getMessage();
-			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
-			return false;
-		}
-		# loading SpatiaLite as an extension
-		if(!$db->loadExtension("libspatialite.so.7")){
-			$this->_lastErrorMessage = "Could not load SpatialLite extension: ". $db->lastErrorMsg();
-			error_log($this->lastErrorMessage());
-			return false;
-		}
-		$this->_database = $db;
-		return true;
-	}
-
-	public function close()
-	{
-		if(is_null($this->_database)){
-			return true;
-		}
-		if($this->_database->close()){
-			$this->_database = null;
-			return true;
-		}
-		$this->_lastErrorMessage = $this->_database->lastErrorMsg();
-		error_log("Failed to close the database: "+ $this->lastErrorMessage());
-		return false;
-	}
-}
-
-?>
Index: src/webservice/htdocs/inc/envsetup.php
===================================================================
--- src/webservice/htdocs/inc/envsetup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/inc/envsetup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,30 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+// set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ ."/../../vendor/");
+$composerAutoloader = require(__DIR__ ."/../../vendor/autoload.php");
+if(is_object($composerAutoloader)){
+	$composerAutoloader->add("SiWeather\\Webservice\\", __DIR__ ."/../");
+	$composerAutoloader->register();
+}
+
+require_once(__DIR__ ."/translate.php");
+
+?>
Index: src/webservice/htdocs/inc/translate.php
===================================================================
--- src/webservice/htdocs/inc/translate.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/inc/translate.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,89 @@
+<?php
+######################
+#
+#    Copyright (C) 2015 EngSaS - Engineering Soluations and Services Langenbach. All rights reserved.
+#
+#    This library is free software; you can redistribute it and/or
+#    modify it under the terms of the GNU Lesser General Public
+#    License as published by the Free Software Foundation; either
+#    version 2.1 of the License, or (at your option) any later version.
+#
+#    This library is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#    Lesser General Public License for more details.
+#
+#    You should have received a copy of the GNU Lesser General Public
+#    License along with this library; if not, write to the Free Software
+#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+#    MA 02110-1301  USA.
+#
+######################
+
+define("LOCALE_SESSION_KEY", "gyl_locale");
+define("LOCALE_DEFAULT", "en_US");
+define("LOCALE_REQUEST_PARAN", "lang");
+define("LOCALE_DOMAIN", "messages"); // Must be the same name, as the po and mo files and the directory they are in
+
+require_once("HTTP2.php");
+
+$config = new SiWeather\Webservice\WebserviceConfig();
+
+$numberDelimiterDecimal = array();
+$numberDelimiterDecimal["en_US"] = ".";
+$numberDelimiterDecimal["de_DE"] = ",";
+
+$_localeCurrent = LOCALE_DEFAULT;
+if(isset($_SESSION)){
+	if(array_key_exists(LOCALE_REQUEST_PARAN, $_REQUEST)){
+		$_localeCurrent = $_REQUEST[LOCALE_REQUEST_PARAN];
+		$_SESSION[LOCALE_SESSION_KEY] = $_localeCurrent;
+	}
+	elseif(array_key_exists(LOCALE_SESSION_KEY, $_SESSION)){
+		$_localeCurrent = $_SESSION[LOCALE_SESSION_KEY];
+	}
+	else{
+		$supportedLanguages = Array(LOCALE_DEFAULT);
+		$transDirHandle = opendir($config->getConfig("translationdirectory"));
+		if($transDirHandle){
+			while(false !== ($entry = readdir($transDirHandle))){
+				if($entry != "." && $entry != ".."){
+					$supportedLanguages[str_replace("_", "-", $entry)] = true;
+				}
+			}
+			
+			closedir($transDirHandle);
+		}
+		$http = new HTTP2();
+		$_localeCurrent = str_replace("-", "_", $http->negotiateLanguage($supportedLanguages, LOCALE_DEFAULT));
+		$_SESSION[LOCALE_SESSION_KEY] = $_localeCurrent;
+	}
+}
+
+$results = putenv("LC_ALL0=". $_localeCurrent);
+if(!$results){
+	error_log("putenv failed (". $result .")");
+}
+$result = setlocale(LC_ALL, $_localeCurrent);
+if(!$results){
+	error_log("setlocale failed (". $result .")");
+}
+$results = bindtextdomain(LOCALE_DOMAIN, $config->getConfig("translationdirectory"));
+if(!$results){
+	error_log("bindtextdomain failed (". $result .")");
+}
+$results = bind_textdomain_codeset(LOCALE_DOMAIN, "UTF-8");
+if(!$results){
+	error_log("bind_textdomain_codeset failed (". $result .")");
+}
+$results = textdomain(LOCALE_DOMAIN);
+if(!$results){
+	error_log("textdomain failed (". $result .")");
+}
+
+class Translator {
+	public static function swGettext($id)
+	{
+		return vsprintf(gettext($id), array_slice(func_get_args(), 1));
+	}
+}
Index: src/webservice/htdocs/index.php
===================================================================
--- src/webservice/htdocs/index.php	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ src/webservice/htdocs/index.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -19,5 +19,7 @@
 */
 
-include("config/config.php");
+require(__DIR__ ."/inc/envsetup.php");
+
+$settings = new SiWeather\Webservice\WebserviceConfig();
 
 /**
@@ -76,3 +78,2 @@
 
 ?>
-
Index: src/webservice/htdocs/resources/css/webservice.css
===================================================================
--- src/webservice/htdocs/resources/css/webservice.css	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ src/webservice/htdocs/resources/css/webservice.css	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -8,2 +8,23 @@
 	font-weight: bold;
 }
+
+.footer {
+	margin-top: 1em;
+	padding-top: 0.5em;
+	color: #C6C6C6;
+	text-align: center;
+	font-size: 9pt;
+	border-width: 0;
+	border-top-width: 2px;
+	border-color: #E6E6E6;
+	border-style: solid;
+}
+
+.footnotes {
+	font-size: 8pt;
+	margin-top: 0.5em;
+}
+
+.footnotes a {
+	color: #C6C6C6;
+}
Index: src/webservice/htdocs/setup.php
===================================================================
--- src/webservice/htdocs/setup.php	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ src/webservice/htdocs/setup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -19,6 +19,5 @@
 */
 
-require_once("config/config.php");
-require_once("inc/DatabaseHandler.php");
+require(__DIR__ ."/inc/envsetup.php");
 
 function printError($message)
@@ -46,5 +45,5 @@
 	<head>
 		<title>SiWeather Webservice Configuration</title>
-		<link rel="stylesheet" type="text/css" link="resources/css/webservice.css"/>
+		<link rel="stylesheet" type="text/css" href="resources/css/webservice.css"/>
 	</head>
 	<body>
@@ -53,40 +52,82 @@
 <?php
 
-$db = new DatabaseHandler();
-$dbFile = $db->databaseFile();
-if(is_null($dbFile)){
-	printResult(false, "No database file given (". $db->lastErrorMessage() .")");
+$setup = new SiWeather\Webservice\Setup();
+
+$errorMessage = "";
+$result = $setup->dataDirectoryCheck($errorMessage);
+if($result == SiWeather\Webservice\DataDirectoryChecks::NotExist && $result != SiWeather\Webservice\DataDirectoryChecks::Success){
+	$result = $setup->dataDirectoryCreate($errorMessage);
 }
 
-$dbDirectory = pathinfo($dbFile, PATHINFO_DIRNAME);
-if(empty($dbDirectory)){
-	printResult(false, "Failed to extract directory from database file path ("+ $dbFile +")");
+if($result != SiWeather\Webservice\DataDirectoryChecks::Success){
+	printResult(false, myGettext("Data directory not accessible (%s)", $errorMessage));
 }
 else{
-	if(is_dir($dbDirectory)){
-		printResult(true, "Database directory exists (". $dbDirectory .")!");
+	printResult(true, _("Data directory checked"));
+	$result = $setup->databaseDirectoryCheck($errorMessage);
+	if($result != SiWeather\Webservice\DatabaseChecks::Success){
+		printResult(false, $errorMessage);
 	}
 	else{
-		if(!mkdir($dbDirectory)){
-			printResult(false, "Failed to create database directory (". $dbDirectory .")!");
+		printResult(true, _("Database directory checked"));
+		$result = $setup->databaseFileCheck($errorMessage);
+		if($result != SiWeather\Webservice\DatabaseChecks::Success){
+			printResult(false, $errorMessage);
 		}
 		else{
-			printResult(true, "Created directory ". $dbDirectory ." as database directory");
+			printResult(true, _("Database file checked"));
+			if(!$setup->databaseConnection($errorMessage)){
+				printResult(false, $errorMessage);
+			}
+			else{
+				$prefix = "Database up and running";
+				$versionSqlite = $setup->databaseVersionSqlite($errorMessage);
+				if($versionSqlite <= 0){
+					printResult(false,  Translator::swGettext("%s (Could not determine SQLite version: %s)", $prefix, $errorMessage));
+				}
+				else{
+					$versionSpatalite = $setup->databaseVersionSpatalite($errorMessage);
+					if($versionSpatalite <= 0){
+						printResult(false, Translator::swGettext("%s (Could not determine Spatalite version: %s)", $prefix, $errorMessage));
+					}
+					else{
+						printResult(true, Translator::swGettext("%s (SQLite: %s, Spatalite: %s)", $prefix, $versionSqlite, $versionSpatalite));
+					}
+				}
+			}
 		}
 	}
+}
 
-	if(!is_writable($dbDirectory)){
-		printResult(false, "Database directory is not writable (". $dbDirectory .")!");
-	}
-	if($db->connect()){
-		printResult(true, "Connection to database established!");
-	}
-	else{
-		printResult(false, "Could not connect to the database (". $db->lastErrorMessage() .")");
-	}
+$webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
+if(!$setup->apiCheckWithoutRewrite($errorMessage)){
+	printResult(false, Translator::swGettext("Could not connect to webservice without rewrite (%s)", $errorMessage));
+}
+else{
+	$url = $webserviceConfig->getConfig("webserviceBaseUrl") ."/index.php/";
+	printResult(true, Translator::swGettext("Webservice withpout rewrite accessible at %s", "<a href=\"". $url ."\">". $url ."</a>"));
+}
+if(!$setup->apiCheckWithRewrite($errorMessage)){
+	printResult(false, Translator::swGettext("Could not connect to webservice with rewrite (%s)", $errorMessage));
+}
+else{
+	$url = $webserviceConfig->getConfig("webserviceBaseUrl") ."/". $webserviceConfig->getConfig("webserviceApiVersion");
+	printResult(true, Translator::swGettext("Webservice withp rewrite accessible at %s", "<a href=\"". $url ."\">". $url ."</a>"));
 }
 
 ?>
 		</ul>
+<?php
+// 	$webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
+	$apiVersion = $webserviceConfig->getConfig("webserviceApiVersion");
+	echo "		<div class=\"footer\">\n";
+	echo "			". Translator::swGettext("SiWeather webservice %s with API version %s), ", $webserviceConfig->getConfig("version"), $apiVersion) ."<br/>\n";
+	echo "			". Translator::swGettext("Webservice accessible at %s/%s/ or", $webserviceConfig->getConfig("webserviceBaseUrl"), $apiVersion) ."<br/>\n";
+	echo "			". $webserviceConfig->getConfig("webserviceBaseUrl") ."/index.php/\n";
+	echo "			<div class=\"footnotes\">\n";
+	echo "				". _("This site uses icons from Oxygen icon theme &#40;License: LGPLv3,") ."<a href=\"http://www.kde.org/\">http://www.kde.org</a>&#41;\n";
+	echo "			</div>\n";
+	echo "		</div>\n";
+?>
 	</body>
 </html>
Index: src/webservice/testconfig/testconfig.php.in
===================================================================
--- src/webservice/testconfig/testconfig.php.in	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ src/webservice/testconfig/testconfig.php.in	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -20,11 +20,9 @@
 
 $testconfig = [
-	"webserviceUrl" => "http://localhost@WEBSERVICE_BASE_URL@/index.php",
-	"webserviceUrlRewrite" => "http://localhost@WEBSERVICE_BASE_URL@",
-	"webserviceApiVersion" => "@WEBSERVICE_API_VERSION@",
+	"webserviceDirectory" => "@WEBSERVICE_OUTPUT_DIRECTORY@",
 ];
 
-set_include_path(get_include_path() . PATH_SEPARATOR . "@WEB_TEST_OUTPUT_DIRECTORY@");
-require 'vendor/autoload.php';
+// set_include_path(get_include_path() . PATH_SEPARATOR . "@WEB_TEST_OUTPUT_DIRECTORY@");
+// require 'vendor/autoload.php';
 
 ?>
Index: src/webservice/tests/SetupTest.php
===================================================================
--- src/webservice/tests/SetupTest.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/tests/SetupTest.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,90 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+class SetupTest extends PHPUnit_Framework_TestCase
+{
+	public static function setUpBeforeClass()
+	{
+		global $testconfig;
+
+		$file = __DIR__ ."/testconfig/testconfig.php";
+		self::assertFileExists($file);
+		require($file);
+		self::$_testconfig = $testconfig;
+		
+		require_once($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
+		
+		self::$_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
+		self::assertNotNull(self::$_webserviceConfig);
+		
+		self::$_dataDirectory = self::$_webserviceConfig->getConfig("dataDirectory");
+		self::assertInternaltype("string", self::$_dataDirectory);
+		self::assertTrue(!empty(self::$_dataDirectory));
+		self::assertTrue(!file_exists(self::$_dataDirectory));
+	}
+	
+	public static function tearDownAfterClass()
+	{
+		if(!file_exists(self::$_dataDirectory)){
+			return;
+		}
+		// clear data directory (not recursive, because there should be only a database file in it
+		$content = scandir(self::$_dataDirectory);
+		self::assertInternalType("array", $content);
+		foreach($content as $file){
+			if(!in_array($file, array(".",".."))){
+				self::assertTrue(unlink(self::$_dataDirectory ."/". $file));
+			}
+		}
+		
+		// remove datadirectory
+		self::assertTrue(rmdir(self::$_dataDirectory));
+	}
+
+	public function testSetupBeginning() {
+		require_once(self::$_testconfig["webserviceDirectory"] ."/SiWeather/Webservice/Setup.php");
+		$setup = new SiWeather\Webservice\Setup();
+
+		$errorMessage = "";
+		$result = $setup->dataDirectoryCheck($errorMessage);
+		$this->assertEquals($result, SiWeather\Webservice\DataDirectoryChecks::NotExist, $errorMessage);
+
+		// create data directory
+		$result = $setup->dataDirectoryCreate($errorMessage);
+		$this->assertEquals($result, SiWeather\Webservice\DataDirectoryChecks::Success, $errorMessage);
+
+		$result = $setup->databaseDirectoryCheck($errorMessage);
+		$this->assertNotEquals($result, SiWeather\Webservice\DatabaseChecks::Success, $errorMessage);
+		$result = $setup->databaseFileCheck($errorMessage);
+		$this->assertNotEquals($result, SiWeather\Webservice\DatabaseChecks::Success, $errorMessage);
+		$this->assertTrue(!$setup->databaseConnection($errorMessage), $errorMessage);
+
+		$prefix = "Database up and running";
+		$versionSqlite = $setup->databaseVersionSqlite($errorMessage);
+		$this->assertLessThan($versionSqlite, 0, $prefix ." (Could not determine SQLite version: ". $errorMessage .")");
+		$versionSpatalite = $setup->databaseVersionSpatalite($errorMessage);
+		$this->assertLessThan($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")");
+   }
+   
+   protected static $_webserviceConfig;
+   protected static $_dataDirectory;
+   protected static $_testconfig;
+}
+?>
Index: src/webservice/tests/SpatialiteTest.php
===================================================================
--- src/webservice/tests/SpatialiteTest.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/tests/SpatialiteTest.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,209 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+class SpatialiteTest extends PHPUnit_Framework_TestCase
+{
+	public static function setUpBeforeClass()
+	{
+		global $testconfig;
+
+		self::$_databaseFile = tempnam(sys_get_temp_dir(), "siw");
+		# PDO SQlite is not able to load extensions (caused by the sqlite pdo driver)
+		# therefore we use PHP SQlite module
+		self::$_database = new SQLite3(self::$_databaseFile);
+		
+		$file = __DIR__ ."/testconfig/testconfig.php";
+		self::assertFileExists($file);
+		require($file);
+		require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
+		
+		self::$_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
+		self::assertNotNull(self::$_webserviceConfig);
+	}
+	
+	public static function tearDownAfterClass()
+	{
+		self::assertTrue(self::$_database->close());
+		self::assertTrue(unlink(self::$_databaseFile));
+		self::$_database = null;
+		self::$_databaseFile = null;
+	}
+
+	public function testLoadSpatialite()
+	{
+		$this->assertInstanceOf("SQLite3", self::$_database);
+
+		# loading SpatiaLite as an extension
+		if(!self::$_database->loadExtension(self::$_webserviceConfig->getConfig("spatialiteExtension"))){
+			echo "Could not load SpatialLite extension: ". self::$_database->lastErrorMsg();
+			return;
+		}
+		
+		$this->assertTrue(self::$_database->exec("BEGIN"));
+		$this->assertTrue(self::$_database->exec("SELECT InitSpatialMetadata()"));
+		$this->assertTrue(self::$_database->exec("COMMIT"));
+		
+		# reporting some version info
+		$rs = self::$_database->query("SELECT spatialite_version()");
+		$this->assertInstanceOf('SQLite3Result', $rs);
+		$row = $rs->fetchArray();
+		$this->assertInternalType("array", $row);
+		$this->assertGreaterThan(1, count($row));
+		$this->assertTrue(!empty($row[0]));
+		$row = $rs->fetchArray();
+		$this->assertTrue(!$row);
+	}
+	
+	public function testDistance()
+	{
+		$this->assertInstanceOf("SQLite3", self::$_database);
+
+		$table = "cities";
+		
+		# creating a POINT table
+		$sql  = "CREATE TABLE ". $table ." (";
+		$sql .= "id INTEGER NOT NULL PRIMARY KEY,";
+		$sql .= "name TEXT NOT NULL)";
+		$this->assertTrue(self::$_database->exec($sql));
+
+		# creating a POINT Geometry column named center,
+		# taking two coordinates in SRID 4326 (WGS84) format
+		$sql  = "SELECT AddGeometryColumn(\"". $table ."\", ";
+		$sql .= "\"center\", 4326, \"POINT\", \"XY\")";
+		$this->assertTrue(self::$_database->exec($sql));
+		
+		# insert some cities
+		# the center must be described in WKT (s. http://giswiki.org/wiki/WKT) format for a point.
+		# Since we use WGS84 with SRID 4326 as a coordinate system, it expects POINT(LONGITUDE LATITUDE)
+		# as values.
+		# CITY, LATITUDE, LONGITUDE
+		# example Berlin:
+		#   52°31′7″N, 13°24′30″E
+		#   --> 52.518611° Latitude and 13.408333° Longitude
+		#   --> $values[] = array("name" => "Berlin", "latitude" => 52.518611, "longitude" => 13.408333);
+		#   --> POINT("13.408333 52.518611")
+		$values = array();
+		$values[] = array("name" => "Berlin", 			"latitude" => 52.518611, 	"longitude" => 13.408333);
+		$values[] = array("name" => "Potsdam", 			"latitude" => 52.395833, 	"longitude" => 13.061389);
+		$values[] = array("name" => "Hamburg", 			"latitude" => 53.550556, 	"longitude" => 9.993333);
+		$values[] = array("name" => "Dresden", 			"latitude" => 51.049259, 	"longitude" => 13.73836);
+		$values[] = array("name" => "Cape Town",		"latitude" => -33.922667, 	"longitude" => 18.416689);
+		$values[] = array("name" => "New York City", 	"latitude" => 40.712778, 	"longitude" => -74.005833);
+		$values[] = array("name" => "Sydney", 			"latitude" => -33.85, 		"longitude" => 151.2);
+		
+		# distances in meter
+		$distances = array();
+		$distances["Berlin"] = array();
+		$distances["Berlin"]["Potsdam"] = 27185;
+		$distances["Berlin"]["Hamburg"] = 255518;
+		$distances["Berlin"]["Dresden"] = 164954;
+		$distances["Berlin"]["Cape Town"] = 9624137;
+		$distances["Berlin"]["New York City"] = 6385266;
+		$distances["Berlin"]["Sydney"] = 16092238;
+		
+		$distances["Potsdam"] = array();
+		$distances["Potsdam"]["Hamburg"] = 242231;
+		$distances["Potsdam"]["Dresden"] = 156823;
+		$distances["Potsdam"]["Cape Town"] =9612288;
+		$distances["Potsdam"]["New York City"] = 6370104;
+		$distances["Potsdam"]["Sydney"] = 16118486;
+		
+		$distances["Hamburg"] = array();
+		$distances["Hamburg"]["Dresden"] = 377003;
+		$distances["Hamburg"]["Cape Town"] = 9760489;
+		$distances["Hamburg"]["New York City"] = 6129909;
+		$distances["Hamburg"]["Sydney"] = 16275543;
+		
+		$distances["Dresden"] = array();
+		$distances["Dresden"]["Cape Town"] = 9459562;
+		$distances["Dresden"]["New York City"] = 6478589;
+		$distances["Dresden"]["Sydney"] = 16109156;
+		
+		$distances["Cape Town"] = array();
+		$distances["Cape Town"]["New York City"] = 12564111;
+		$distances["Cape Town"]["Sydney"] = 11013398;
+		
+		$distances["New York City"] = array();
+		$distances["New York City"]["Sydney"] = 15988687;
+		
+		$this->assertTrue(self::$_database->exec("BEGIN"));
+		$sql  = "INSERT INTO ". $table ." (name, center) VALUES(:name, GeomFromText(:center, 4326))";
+		$sqlStatement = self::$_database->prepare($sql);
+		foreach ($values as $value){
+			$sqlStatement->clear();
+			$this->assertEquals(3, count($value));
+			$this->assertTrue($sqlStatement->bindValue(":name", $value["name"]));
+			$this->assertTrue($sqlStatement->bindValue(":center", "POINT(". $value["longitude"] ." ". $value["latitude"] .")"));
+			$this->assertInstanceOf("SQLite3Result", $sqlStatement->execute());
+			$sqlStatement->reset();
+		}
+		$this->assertTrue(self::$_database->exec("COMMIT"));
+		
+		# check the inserts
+		$sql  = "SELECT id, name, X(center) as longitude, Y(center) as latitude FROM ". $table ." WHERE name=:name";
+		$sqlStatement = self::$_database->prepare($sql);
+		foreach ($values as $value){
+			$sqlStatement->clear();
+			$this->assertEquals(3, count($value));
+			$this->assertTrue($sqlStatement->bindValue(":name", $value["name"]));
+			$result = $sqlStatement->execute();
+			$this->assertInstanceOf("SQLite3Result", $result);
+			while($row = $result->fetchArray()){
+				$this->assertGreaterThan(4, count($row));
+				$this->assertGreaterThan(-1, $row[0]);
+				$this->assertEquals($value["name"], $row[1]);
+				$this->assertEquals($value["longitude"], $row[2]);
+				$this->assertEquals($value["latitude"], $row[3]);
+			}
+			$sqlStatement->reset();
+		}
+
+		# calculate the distances
+		# Calling Distance() with three parameters, which returns distance in Meter
+		$sql  = "SELECT t1.name, t2.name, Round(Distance(t1.center, t2.center, 1), 0) As distance";
+		$sql .= "  FROM ". $table ." AS t1, ". $table ." AS t2";
+		$sql .= "  WHERE t1.name=:from AND t2.name=:to";
+		$sqlStatement = self::$_database->prepare($sql);
+		foreach(array_keys($distances) as $start){
+			foreach(array_keys($distances[$start]) as $end){
+				$sqlStatement->clear();
+				# Calculate distance from start --> end
+				$this->assertTrue($sqlStatement->bindValue(":from", $start));
+				$this->assertTrue($sqlStatement->bindValue(":to", $end));
+				$result = $sqlStatement->execute();
+				$this->assertInstanceOf("SQLite3Result", $result);
+				while($row = $result->fetchArray()){
+					$this->assertGreaterThan(3, count($row));
+					$this->assertEquals($start, $row[0]);
+					$this->assertEquals($end, $row[1]);
+					# 0.5% difference of the distance is accepted
+					$delta = abs($distances[$start][$end] - $row[2])/$distances[$start][$end];
+					$this->assertLessThan(0.005, $delta, $start ." --> ". $end .":\n  Expected: ". $distances[$start][$end] ."\n  Is: ". $row[2]);
+				}
+				$sqlStatement->reset();
+			}
+		}
+	}
+
+	protected static $_databaseFile;
+	protected static $_database;
+	protected static $_webserviceConfig;
+}
+?>
Index: src/webservice/tests/StationsTest.php
===================================================================
--- src/webservice/tests/StationsTest.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/tests/StationsTest.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,86 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+class StationsTest extends PHPUnit_Framework_TestCase
+{
+    protected function setUp()
+    {
+		$file = __DIR__ ."/testconfig/testconfig.php";
+		$this->assertFileExists($file);
+		require($file);
+		$this->_testconfig = $testconfig; 
+		$this->assertNotNull($this->_testconfig);
+		
+		require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
+		
+		$this->_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
+		$this->assertNotNull($this->_webserviceConfig);
+    }
+
+	public function testEmptyStations()
+	{
+		$stations = $this->query("index.php/stations");
+
+		$this->assertInternalType("array", $stations);
+		$this->assertEquals(count($stations), 0);
+	}
+	
+	public function testStationRewrite()
+	{
+		$apiVersion = $this->_webserviceConfig->getConfig("webserviceApiVersion");
+		$this->assertInternalType('string', $apiVersion);
+		$this->assertTrue(!empty($apiVersion));
+
+		$stations = $this->query($apiVersion ."/stations");
+
+		$this->assertInternalType("array", $stations);
+		$this->assertEquals(count($stations), 0);
+	}
+	
+	protected function query($url){
+		require(__DIR__ ."/../vendor/autoload.php");
+
+		$baseUrl = $this->_webserviceConfig->getConfig("webserviceBaseUrl");
+		$this->assertInternalType('string', $baseUrl);
+		$this->assertTrue(!empty($baseUrl));
+		$client = new GuzzleHttp\Client
+		(
+			[
+				"base_uri" => $baseUrl,
+				"timeout" => 2.0,
+				"http_errors" => false,
+			]
+		);
+		$response = $client->get($url);
+		$this->assertNotNull($response);
+		$this->assertEquals($response->getStatusCode(), 200);
+		$this->assertEquals($response->getReasonPhrase(), "OK");
+
+		$body = $response->getBody();
+		$this->assertTrue(!empty($body));
+		$json = json_decode($body);
+		$this->assertNotNull($json);
+		return $json;
+	}
+	
+	protected $_testconfig;
+	protected $_webserviceConfig;
+}
+?>
Index: src/webservice/tests/TestSpatiallite.php
===================================================================
--- src/webservice/tests/TestSpatiallite.php	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ 	(revision )
@@ -1,187 +1,0 @@
-<?php
-/*
-    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-    MA 02110-1301  USA.
-*/
-
-class TestSpatialiteExtension extends PHPUnit_Framework_TestCase
-{
-	public static function setUpBeforeClass()
-	{
-		self::$_databaseFile = tempnam(sys_get_temp_dir(), "siw");
-		# PDO SQlite is not able to load extensions (caused by the sqlite pdo driver)
-		# therefore we use PHP SQlite module
-		self::$_database = new SQLite3(self::$_databaseFile);
-	}
-	
-	public static function tearDownAfterClass()
-	{
-		self::$_database->close();
-		unlink(self::$_databaseFile);
-		self::$_database = null;
-		self::$_databaseFile = null;
-	}
-
-	public function testLoadSpatialite()
-	{
-		$this->assertInstanceOf("SQLite3", self::$_database);
-
-		# loading SpatiaLite as an extension
-		if(!self::$_database->loadExtension("mod_spatialite.so")){
-			echo "Could not load SpatialLite extension: ". self::$_database->lastErrorMsg();
-			return;
-		}
-		
-		$this->assertTrue(self::$_database->exec("BEGIN"));
-		$this->assertTrue(self::$_database->exec("SELECT InitSpatialMetadata()"));
-		$this->assertTrue(self::$_database->exec("COMMIT"));
-		
-		# reporting some version info
-		$rs = self::$_database->query("SELECT spatialite_version()");
-		$this->assertInstanceOf('SQLite3Result', $rs);
-		$row = $rs->fetchArray();
-		$this->assertInternalType("array", $row);
-		$this->assertGreaterThan(1, count($row));
-		$this->assertTrue(!empty($row[0]));
-		$row = $rs->fetchArray();
-		$this->assertTrue(!$row);
-	}
-	
-	public function testDistance()
-	{
-		$this->assertInstanceOf("SQLite3", self::$_database);
-
-		$table = "cities";
-		
-		# creating a POINT table
-		$sql  = "CREATE TABLE ". $table ." (";
-		$sql .= "id INTEGER NOT NULL PRIMARY KEY,";
-		$sql .= "name TEXT NOT NULL)";
-		$this->assertTrue(self::$_database->exec($sql));
-
-		# creating a POINT Geometry column named center,
-		# taking two coordinates in SRID 4326 (WGS84) format
-		$sql  = "SELECT AddGeometryColumn(\"". $table ."\", ";
-		$sql .= "\"center\", 32632, \"POINT\", \"XY\")";
-		$this->assertTrue(self::$_database->exec($sql));
-		
-		# insert some cities
-		# the center must be described in WKT (s. http://giswiki.org/wiki/WKT) format for a point.
-		# since we use WGS84 as a coordinate system, 
-		# CITY, LATITUDE, LONGITUDE
-		$values = array();
-		$values[] = array("Berlin", 52.518611, 13.408333);
-		$values[] = array("Potsdam", 52.395833, 13.061389);
-		$values[] = array("Hamburg", 53.550556, 9.993333);
-		$values[] = array("Dresden", 51.049259, 13.73836);
-		$values[] = array("Cape Town", -33.922667, 18.416689);
-		$values[] = array("New York City", 40.712778, -74.005833);
-		$values[] = array("Sydney", -33.85, 151.2);
-		
-		# distances in meter
-		$distances = array();
-		$distances["Berlin"] = array();
-		$distances["Berlin"]["Potsdam"] = 27185;
-		$distances["Berlin"]["Hamburg"] = 255518;
-		$distances["Berlin"]["Dresden"] = 164954;
-		$distances["Berlin"]["Cape Town"] = 9624137;
-		$distances["Berlin"]["New York City"] = 6385266;
-		$distances["Berlin"]["Sydney"] = 16092238;
-		
-		$distances["Potsdam"] = array();
-		$distances["Potsdam"]["Hamburg"] = 242231;
-		$distances["Potsdam"]["Dresden"] = 156823;
-		$distances["Potsdam"]["Cape Town"] =9612288;
-		$distances["Potsdam"]["New York City"] = 6370104;
-		$distances["Potsdam"]["Sydney"] = 16118486;
-		
-		$distances["Hamburg"] = array();
-		$distances["Hamburg"]["Dresden"] = 377003;
-		$distances["Hamburg"]["Cape Town"] = 9760489;
-		$distances["Hamburg"]["New York City"] = 6129909;
-		$distances["Hamburg"]["Sydney"] = 16275543;
-		
-		$distances["Dresden"] = array();
-		$distances["Dresden"]["Cape Town"] = 9459562;
-		$distances["Dresden"]["New York City"] = 6478589;
-		$distances["Dresden"]["Sydney"] = 16109156;
-		
-		$distances["Cape Town"] = array();
-		$distances["Cape Town"]["New York City"] = 12564111;
-		$distances["Cape Town"]["Sydney"] = 11013398;
-		
-		$distances["New York City"] = array();
-		$distances["New York City"]["Sydney"] = 15988687;
-		
-		$this->assertTrue(self::$_database->exec("BEGIN"));
-		$sql  = "INSERT INTO ". $table ." (name, center) VALUES(:name, GeomFromText(:center, 32632))";
-		$sqlStatement = self::$_database->prepare($sql);
-		foreach ($values as $value){
-			$sqlStatement->clear();
-			$this->assertEquals(3, count($value));
-			$this->assertTrue($sqlStatement->bindValue(":name", $value[0]));
-			$this->assertTrue($sqlStatement->bindValue(":center", "POINT(". $value[1] ." ". $value[2] .")"));
-			$this->assertInstanceOf("SQLite3Result", $sqlStatement->execute());
-		}
-		$this->assertTrue(self::$_database->exec("COMMIT"));
-		
-		# check the inserts
-		$sql  = "SELECT id, name, X(center), Y(center) FROM ". $table ." WHERE name=:name";
-		$sqlStatement = self::$_database->prepare($sql);
-		foreach ($values as $value){
-			$sqlStatement->clear();
-			$this->assertEquals(3, count($value));
-			$this->assertTrue($sqlStatement->bindValue(":name", $value[0]));
-			$result = $sqlStatement->execute();
-			$this->assertInstanceOf("SQLite3Result", $result);
-			while($row = $result->fetchArray()){
-				$this->assertGreaterThan(4, count($row));
-				$this->assertGreaterThan(-1, $row[0]);
-				$this->assertEquals($value[0], $row[1]);
-				$this->assertEquals($value[1], $row[2]);
-				$this->assertEquals($value[2], $row[3]);
-			}
-		}
-
-		# calculate the distances
-		# Calling Distance() with three parameters, which returns distance in Meter
-		$sql  = "SELECT t1.name, t2.name, Distance(t1.center, t2.center) As distance";
-		$sql .= "  FROM ". $table ." AS t1, ". $table ." AS t2";
-		$sql .= "  WHERE t1.name=:from AND t2.name=:to";
-		$sqlStatement = self::$_database->prepare($sql);
-		foreach(array_keys($distances) as $start){
-			foreach(array_keys($distances[$start]) as $end){
-				$sqlStatement->clear();
-				# Calculate distance from start --> end
-				$this->assertTrue($sqlStatement->bindValue(":from", $start));
-				$this->assertTrue($sqlStatement->bindValue(":to", $end));
-				$result = $sqlStatement->execute();
-				$this->assertInstanceOf("SQLite3Result", $result);
-				while($row = $result->fetchArray()){
-					$this->assertGreaterThan(3, count($row));
-					$this->assertEquals($start, $row[0]);
-					$this->assertEquals($end, $row[1]);
-					$this->assertEquals($distances[$start][$end], $row[2], $start ." --> ". $end);
-				}
-			}
-		}
-	}
-
-	protected static $_databaseFile;
-	protected static $_database;
-}
-?>
Index: src/webservice/tests/TestStations.php
===================================================================
--- src/webservice/tests/TestStations.php	(revision 8f38d1eb0d2e82eb85c37617864c60c37bfebf83)
+++ 	(revision )
@@ -1,66 +1,0 @@
-<?php
-/*
-    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-    MA 02110-1301  USA.
-*/
-
-class TestStations extends PHPUnit_Framework_TestCase
-{
-	protected $config;
-
-    protected function setUp()
-    {
-		$file = "webtests/webservice/testconfig/testconfig.php";
-		$this->assertFileExists($file);
-		require($file);
-		$this->config = $testconfig; 
-		$this->assertNotNull($this->config);
-    }
-
-	public function testEmptyStations()
-	{
-		$this->queryEmptyStationList($this->config["webserviceUrl"]);
-	}
-	
-	public function testStationRewrite()
-	{
-		$this->queryEmptyStationList($this->config["webserviceUrlRewrite"]);
-	}
-	
-	protected function queryEmptyStationList($url){
-		$this->assertInternalType('string', $url ."/");
-		$client = new GuzzleHttp\Client
-		(
-			[
-				"base_uri" => $url,
-				"timeout" => 2.0,
-			]
-		);
-		$response = $client->get("index.php/stations");
-		$this->assertNotNull($response);
-		$this->assertEquals($response->getStatusCode(), 200);
-		$this->assertEquals($response->getReasonPhrase(), "OK");
-
-		$body = $response->getBody();
-		$this->assertTrue(!empty($body));
-		$stations = json_decode($body);
-		$this->assertNotNull($stations);
-		$this->assertInternalType("array", $stations);
-		$this->assertEquals(count($stations), 0);
-	}
-}
-?>
