[Mapbender-commits] r9376 - trunk/mapbender/owsproxy/http

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 19 03:11:22 PST 2016


Author: armin11
Date: 2016-01-19 03:11:22 -0800 (Tue, 19 Jan 2016)
New Revision: 9376

Modified:
   trunk/mapbender/owsproxy/http/index.php
Log:
Possibility to log owsproxy secured wfs getfeature requests

Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php	2016-01-19 11:06:05 UTC (rev 9375)
+++ trunk/mapbender/owsproxy/http/index.php	2016-01-19 11:11:22 UTC (rev 9376)
@@ -278,7 +278,7 @@
         }
         //$request = $query->getRequest();
         // Ergaenzungen secured UMN Requests
-        #log proxy requests
+        //log proxy requests
         if ($n->getWmsLogTag($arrayOnlineresources['wms_id']) == 1) {#do log to db
             #get price out of db
             $price = intval($n->getWmsPrice($arrayOnlineresources['wms_id']));
@@ -327,10 +327,18 @@
         $query->setOnlineResource($arrayOnlineresources['wfs_getfeature']);
         $request = $query->getRequest();
         $request = stripslashes($request);
+	if ($n->getWfsLogTag($arrayOnlineresources['wfs_id']) == 1) {
+            //get price out of db
+            $price = intval($n->getWfsPrice($arrayOnlineresources['wfs_id']));
+            $log_id = $n->logWfsProxyRequest($arrayOnlineresources['wfs_id'], $_SESSION['mb_user_id'], $request,
+                $price, 0, $reqParams['typename']);
+        } else {
+		$log_id = false;
+	}
         if (isset($auth)) {
-            getFeature($request, $auth);
+            getFeature($log_id, $request, $auth);
         } else {
-            getFeature($request);
+            getFeature($log_id, $request);
         }
         break;
     case 'describefeaturetype':
@@ -492,10 +500,10 @@
  * @param string the url of the GetFeature request
  * @return echo the content of the GetFeature document
  */
-function getFeature($url, $auth = false)
+function getFeature($log_id, $url, $auth = false)
 {
     global $reqParams;
-    $content = getDocumentContent(false, $url, "Content-Type: application/xml", $auth);
+    $content = getDocumentContent($log_id, $url, "Content-Type: application/xml", $auth);
 }
 
 /**
@@ -930,6 +938,8 @@
 function getDocumentContent($log_id, $url, $header = false)
 {
     global $reqParams, $n;
+    //debug
+    $startTime = microtime();
     if (func_num_args() == 4) { //new for HTTP Authentication
         $auth = func_get_arg(3);
         $d = new connector($url, $auth);
@@ -937,6 +947,8 @@
         $d = new connector($url);
     }
     $content = $d->file;
+    $endTime = microtime();
+    $e = new mb_exception("owsproxy/http/index.php: Time for getting remote resource: ".(string)($endTime - $startTime));
     if (strtoupper($reqParams["request"]) == "GETMAP") { // getmap
         $pattern_exc = '~EXCEPTION~i';
         preg_match($pattern_exc, $content, $exception);
@@ -991,16 +1003,17 @@
         }
         return true;
     } elseif (strtoupper($reqParams["request"]) == "GETFEATURE") {
-	$e = new mb_exception("getfeature invoked");
+	$e = new mb_notice("owsproxy/http/index.php: GetFeature invoked");
+	$startTime = microtime();
 	//parse featureCollection and get number of objects
 	libxml_use_internal_errors(true);
 	try {
 		$featureCollectionXml = simplexml_load_string($content);
 		if ($featureCollectionXml === false) {
 			foreach(libxml_get_errors() as $error) {
-        			$err = new mb_exception("owsproxy/index.php:".$error->message);
+        			$err = new mb_exception("owsproxy/http/index.php:".$error->message);
     			}
-			throw new Exception("owsproxy/index.php:".'Cannot parse featureCollection XML!');
+			throw new Exception("owsproxy/http/index.php:".'Cannot parse featureCollection XML!');
 			//TODO give error message
 		}
 	}
@@ -1009,15 +1022,40 @@
 		//TODO give error message
 	}
 	if ($featureCollectionXml !== false) {
-		$featureCollectionXml->registerXPathNamespace("gmd", "http://www.isotc211.org/2005/gmd");
+		//$featureCollectionXml->registerXPathNamespace("gmd", "http://www.isotc211.org/2005/gmd");
+		$featureCollectionXml->registerXPathNamespace("ogc", "http://www.opengis.net/ogc");
+		$featureCollectionXml->registerXPathNamespace("wfs", "http://www.opengis.net/wfs");
 		$featureCollectionXml->registerXPathNamespace("gco", "http://www.isotc211.org/2005/gco");
 		$featureCollectionXml->registerXPathNamespace("gml", "http://www.opengis.net/gml");
 		$featureCollectionXml->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
 		$featureCollectionXml->registerXPathNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
 		$featureCollectionXml->registerXPathNamespace("default", "");
-		$numberOfFeatures = $featureCollectionXml->xpath('//wfs:FeatureCollection/@numberOfFeatures');
-		$numberOfFeatures = $numberOfFeatures[0];
-		$e = new mb_exception("owsproxy/index.php: ".$numberOfFeatures." delivered features from wfs ");
+        	preg_match('@version=(?P<version>\d\.\d\.\d)&@i', strtolower($url), $version);
+       		if (!$version['version']) {
+			$e = new mb_notice("owsproxy/http/index.php: No version for wfs request given in url!");
+		}
+		switch ($version['version']) {
+			case "1.0.0":
+				//get # of features from counting features
+				$numberOfFeatures = $featureCollectionXml->xpath('//wfs:FeatureCollection/gml:featureMember');
+				$numberOfFeatures = count($numberOfFeatures);
+				$e = new mb_notice("owsproxy/index.php: wfs version ".$version[1]." used");
+			break;
+			case "1.1.0":
+				//get # of features from attribut
+				$numberOfFeatures = $featureCollectionXml->xpath('//wfs:FeatureCollection/@numberOfFeatures');
+				$numberOfFeatures = $numberOfFeatures[0];
+				$e = new mb_notice("owsproxy/index.php: wfs version ".$version[1]." used");
+			break;
+		}
+		$endTime = microtime();
+		$e = new mb_notice("owsproxy/http/index.php: ".$numberOfFeatures." delivered features from wfs.");
+		//TODO: enhance error management
+		if ($log_id !== false) {
+                	$n->updateWfsLog(1, '', '', $numberOfFeatures, $log_id);
+            	}
+		$e = new mb_notice("owsproxy/http/index.php: Time for counting: ". (string)($endTime - $startTime));
+		$e = new mb_notice("owsproxy/http/index.php: Memory used for XML String: ".getVariableUsage($content)/1000000 ."MB");
 		if (header !== false) { 
 			header($header);
 		}
@@ -1050,4 +1088,9 @@
     return $foundUserId;
 }
 
+function getVariableUsage($var) {
+  $total_memory = memory_get_usage();
+  $tmp = unserialize(serialize($var));
+  return memory_get_usage() - $total_memory; 
+}
 ?>



More information about the Mapbender_commits mailing list