[Mapbender-commits] r8368 - in trunk/mapbender: http/classes lib resources/db/pgsql/UTF-8/update tools

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jun 5 11:59:55 PDT 2012


Author: armin11
Date: 2012-06-05 11:59:54 -0700 (Tue, 05 Jun 2012)
New Revision: 8368

Modified:
   trunk/mapbender/http/classes/class_connector.php
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/lib/class_Monitor.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql
   trunk/mapbender/tools/mod_monitorCapabilities_defineGetMapBbox.php
   trunk/mapbender/tools/mod_monitorCapabilities_main.php
   trunk/mapbender/tools/mod_monitorCapabilities_write.php
Log:
Bugfixes for monitoring module - solve encoding problem when comparing local and remote capabilities docs and extent length of getmap url for monitoring wms to  varchar (there was a problem when the wms had many layers and/or long layer names).

Modified: trunk/mapbender/http/classes/class_connector.php
===================================================================
--- trunk/mapbender/http/classes/class_connector.php	2012-05-30 06:10:19 UTC (rev 8367)
+++ trunk/mapbender/http/classes/class_connector.php	2012-06-05 18:59:54 UTC (rev 8368)
@@ -286,7 +286,7 @@
 		if(strtoupper($this->httpType) == 'GET'){
 			$headers = array(
 					"GET ".$path." HTTP/1.1",
-					"User-Agent: ".$_SERVER['HTTP_USER_AGENT'],
+					"User-Agent: ".$useragent,
            				"Host: ".$host.":".$port,
 	           		 	"Accept: */*",
 					"Proxy-Connection: Keep-Alive"

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2012-05-30 06:10:19 UTC (rev 8367)
+++ trunk/mapbender/http/classes/class_wms.php	2012-06-05 18:59:54 UTC (rev 8368)
@@ -1548,7 +1548,7 @@
 			$this->wms_getmap,
 			$this->wms_getfeatureinfo,
 			$this->wms_getlegendurl,
-			$admin->char_encode($this->wms_getcapabilities_doc),
+			$admin->char_encode($this->wms_getcapabilities_doc), //convert xml to utf-8, if it was given in iso! 
 			$this->wms_upload_url,
 			$this->fees,
 			$this->accessconstraints,

Modified: trunk/mapbender/lib/class_Monitor.php
===================================================================
--- trunk/mapbender/lib/class_Monitor.php	2012-05-30 06:10:19 UTC (rev 8367)
+++ trunk/mapbender/lib/class_Monitor.php	2012-06-05 18:59:54 UTC (rev 8368)
@@ -18,6 +18,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 //require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+
 require_once(dirname(__FILE__)."/../http/classes/class_connector.php");
 require_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
 require_once(dirname(__FILE__)."/../http/extensions/DifferenceEngine.php");
@@ -32,28 +33,23 @@
 	 * 
 	 */
 	var $result = -1;
-
 	/**
 	 * 1  = the get map request DEFINITELY returns a valid map image
 	 * 0  = the WMS doesn't support XML error format. Who knows if the image is really a map?
 	 * -1 = the get map request doesn't return an image
 	 */
 	var $returnsImage;
-
 	var $comment = "";
 	var $updated = "0";
 	var $supportsXMLException = false;
-	
 	var $timestamp;
 	var $timestamp_cap_begin;
 	var $timestamp_cap_end;
 	var $capabilitiesURL;
 	var $mapURL;
-	
 	var $remoteXML;
 	var $localXML;
 	var $capabilitiesDiff;
-	
 	var $tmpDir = null;
 	
 	function __construct($reportFile, $autoUpdate, $tmpDir) {
@@ -68,9 +64,7 @@
 		$e=new mb_notice("WMS ID: ".$this->wmsId);
 		$this->capabilitiesURL = urldecode($this->getTagOutOfXML($this->reportFile,'getcapurl'));//read out from xml
 		$e=new mb_notice("GetCapURL: ".$this->capabilitiesURL);
-
 		set_time_limit(TIME_LIMIT);
-		
 		$this->timestamp = microtime(TRUE);
 		//get authentication info for service
 		$admin = new administration();
@@ -79,43 +73,30 @@
 			unset($auth);
 		}
 		if ($this->capabilitiesURL) {
-		
-			//$remoteWms = new wms(); #exchange by other handling
-			
-
 			$this->timestamp_cap_begin=microtime(TRUE);//ok
-			
-
-			//$remoteWms->createObjFromXML($this->capabilitiesURL);#exchange by other handling
-			
-
-			//$this->remoteXML = $remoteWms->wms_getcapabilities_doc;
 			if (isset($auth)) {
 				$capObject = new connector($this->capabilitiesURL,$auth);
 			} else {
 				$capObject = new connector($this->capabilitiesURL);
 			}
-			//decode and encode to have the same behavior as loading caps to database
-			$this->remoteXML = $admin->char_encode($capObject->file);
-
+			$this->remoteXML = $capObject->file;
+			//encode all into utf-8 to compare them - this is done in too when storing the caps into the database after parsing the caps
+			$this->remoteXML = $admin->char_encode($this->remoteXML);
 			$this->timestamp_cap_end=microtime(TRUE);
 			//read local copy out of xml
-			$this->localXML = $admin->char_encode(urldecode($this->getTagOutOfXML($this->reportFile,'getcapdoclocal')));
-//			$e=new mb_notice("Remote Caps: ".$this->remoteXML);
+			$this->localXML = urldecode($this->getTagOutOfXML($this->reportFile,'getcapdoclocal'));
 			// service unreachable
 			if (!$this->remoteXML) {
 				$this->result = -1;
 				$this->comment = "Connection failed.";
-				//$e=new mb_exception("Connection failed");
 			}
 			/*
-			 * service available;
+			 * result available;
 			 * no local copy of capabilities file,
 			 * so it has to be updated anyway
 			 */
 			elseif (!$this->localXML) {
 				$this->result = 0;
-				//$e=new mb_exception("No local Copy of Caps available");
 			}
 			/*
 			 * service available;
@@ -123,6 +104,7 @@
 			 * to remote capabilties document
 			 */
 			else {
+				//First do a simple check if <WMT_MS_Capabilities version="1.1 is part of the remote Cap Dokument
 				/*
 				 * compare to local capabilities document
 				 */
@@ -135,12 +117,20 @@
 				}
 				// capabilities files don't match
 				else {
-					$this->result = 0;
-					$this->comment = "WMS is not up to date.";
-					$localXMLArray = explode("\n", $this->localXML);
-					$remoteXMLArray = explode("\n", $this->remoteXML);
-					$this->capabilitiesDiff = $this->outputDiffHtml($localXMLArray,$remoteXMLArray);
-					//$e=new mb_exception("Problem Docs are out of sync");
+					//check i a capabilities document was send, if not give an error
+					$searchString  = 'WMT_MS_Capabilities';
+					$pos = strpos($this->remoteXML, $searchString);
+					if ($pos === false) {
+    						$this->result = -1;
+						$this->comment = "Invalid getCapabilities request/document or service exception.";
+					}
+					else {
+						$this->result = 0;
+						$this->comment = "WMS is not up to date.";
+						$localXMLArray = explode("\n", $this->localXML);
+						$remoteXMLArray = explode("\n", $this->remoteXML);
+						$this->capabilitiesDiff = $this->outputDiffHtml($localXMLArray,$remoteXMLArray);
+					}
 				}
 			}
 			/*
@@ -149,9 +139,7 @@
 			 * 2) update the local backup of the capabilities doc if necessary
 			 */
 			if ($this->result != -1) {
-				
 				$this->mapURL = urldecode($this->getTagOutOfXML($this->reportFile,'getmapurl'));
-				//$e=new mb_exception("mapurl:".$this->mapURL);
 			if (isset($auth)) {
 				if ($this->isImage($this->mapURL,$auth)) {
 					$this->returnsImage = 1;
@@ -163,16 +151,11 @@
 			} else {
 				if ($this->isImage($this->mapURL)) {
 					$this->returnsImage = 1;
-					//$e=new mb_exception("Returns image");
 				}
 				else {
 					$this->returnsImage = -1;
-					//$e=new mb_exception("Returns no image!");
 				}
 			}
-
-
-
 				//Check for valid XML - validate it again wms 1.1.1 -some problems occur?
 				#$dtd = "../schemas/capabilities_1_1_1.dtd";
 				#$dom = new domDocument;
@@ -185,16 +168,7 @@
 					#$this->comment = "WMS is not up to date but valid!";
 				#}
 
-				//Do a simple check if <WMT_MS_Capabilities version="1.1 is part of the remote Cap Dokument
-				
-				$searchString  = 'WMT_MS_Capabilities';
-				$pos = strpos($this->remoteXML, $searchString);
-				if ($pos === false) {
-    					$this->result = -1;
-					$this->comment = "Invalid getCapabilities request/document or service exception.";
-				}
 
-
 				/*
 				 * if the local backup of the capabilities document
 				 * is deprecated, update the local backup
@@ -310,8 +284,6 @@
 		#if (preg_match("/xml/", $headers["Content-Type"])) {
 		#	return false;
 		#}
-
-
 		if (func_num_args() == 2) { //new for HTTP Authentication
         	    	$auth = func_get_arg(1);
 			$imgObject = new connector($url, $auth);
@@ -325,7 +297,6 @@
 		$fileMapImg = fopen($imageName, 'w+');
 		$bytesWritten = fwrite($fileMapImg, $image);
 		fclose($fileMapImg);
-
 		//$e = new mb_notice("class_monitor: isImage: path: ".$imageName);
 		//$e = new mb_notice("class_monitor: isImage: Content-Type is " . mime_content_type($image));
 		//$e = new mb_notice("class_monitor: isImage: Content-Type (file) is " . mime_content_type($imageName));
@@ -339,16 +310,6 @@
 	 * Returns the objects out of the xml file
  	 */
        private function getTagOutOfXML($reportFile,$tagName) {
-		#$e = new mb_notice("class_monitor: getUploadURL: wms = " . $wmsId);
-		#$e = new mb_notice("class_monitor: getUploadURL: upload_id = " . $upload_id);
-		#$sql = "SELECT upload_url FROM mb_monitor WHERE fkey_wms_id = $1 AND upload_id = $2";
-		#$v = array($wmsId, $upload_id);
-		#$t = array('i', 'i');
-		#$res = db_prep_query($sql,$v,$t);
-		#$someArray = db_fetch_array($res);
-		#$e = new mb_notice("class_monitor: getUploadURL: url = " . $someArray["upload_url"]);
-		#$xmlobj = new DOMDocument('1.0');
-  		#$xmlobj->load($reportFile);
 		$xml=simplexml_load_file($reportFile);
 		$result=(string)$xml->wms->$tagName;
 		return $result;
@@ -360,64 +321,5 @@
 		$diffObj = new Diff($localXMLArray,$remoteXMLArray);
 		$dft = new TableDiffFormatter();
 		return $dft->format($diffObj);
-	}		
-	//TODO get this things out of administration - but without database connection	
-	function is_utf8_string($string) {
-		return preg_match('%(?:
-		[\xC2-\xDF][\x80-\xBF]        # non-overlong 2-byte
-		|\xE0[\xA0-\xBF][\x80-\xBF]               # excluding overlongs
-		|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}      # straight 3-byte
-		|\xED[\x80-\x9F][\x80-\xBF]               # excluding surrogates
-		|\xF0[\x90-\xBF][\x80-\xBF]{2}    # planes 1-3
-		|[\xF1-\xF3][\x80-\xBF]{3}                  # planes 4-15
-		|\xF4[\x80-\x8F][\x80-\xBF]{2}    # plane 16
-		)+%xs', $string);
-	}
-//function to get documents with authentication
-	function getDocumentContent($url){
-		if (func_num_args() == 2) { //new for HTTP Authentication
-        	    	$auth = func_get_arg(1);
-			$d = new connector($url, $auth);
-		}
-		else {
-			$d = new connector($url);
-		}
-		return $d->file;
-	}
-
-	function is_utf8_xml($xml) {
-		return preg_match('/<\?xml[^>]+encoding="utf-8"[^>]*\?>/is', $xml);
-	}
-	
-	function is_utf8 ($data) {
-		return ($this->is_utf8_xml($data) || $this->is_utf8_string($data));
-	}
-	
-	function char_encode($data) {
-		if (CHARSET == "UTF-8") {
-			if (!$this->is_utf8($data)) {
-				$e = new mb_notice("Conversion: ISO-8859-1 to UTF-8");
-				return utf8_encode($data);
-			}
-		}
-		else {
-			if ($this->is_utf8($data)) {
-				$e = new mb_notice("Conversion: UTF-8 to ISO-8859-1");
-				return utf8_decode($data);
-			}
-		}
-		$e = new mb_notice("No conversion: is " . CHARSET);
-		return $data;
-	}
-
-	function char_decode($data) {
-		if (CHARSET == "UTF-8") {
-			if ($this->is_utf8($data)) {
-				$e = new mb_notice("Conversion: UTF-8 to ISO-8859-1");
-				return utf8_decode($data);
-			}
-		}
-		$e = new mb_notice("no conversion: is " . CHARSET);
-		return $data;
-	}
+	}			
 }

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql	2012-05-30 06:10:19 UTC (rev 8367)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql	2012-06-05 18:59:54 UTC (rev 8368)
@@ -435,3 +435,7 @@
 ALTER TABLE layer ADD COLUMN inspire_download integer;
 UPDATE layer SET inspire_download = 0 WHERE inspire_download IS NULL;
 
+ALTER TABLE mb_monitor ALTER COLUMN map_url TYPE varchar;
+ALTER TABLE mb_monitor ALTER COLUMN cap_diff TYPE text; 
+
+

Modified: trunk/mapbender/tools/mod_monitorCapabilities_defineGetMapBbox.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_defineGetMapBbox.php	2012-05-30 06:10:19 UTC (rev 8367)
+++ trunk/mapbender/tools/mod_monitorCapabilities_defineGetMapBbox.php	2012-06-05 18:59:54 UTC (rev 8368)
@@ -94,7 +94,7 @@
 		//echo "Scale: ".$scale."\n";
 		//var_dump($bbox);
 		//echo "\n";
-		$e = new mb_exception("monitorDefineGetMapBBOX: BBOX berechnen fuer wms " . $wmsId);
+		$e = new mb_notice("monitorDefineGetMapBBOX: BBOX berechnen fuer wms " . $wmsId);
 		if (($bbox!=NULL) and ($bbox->min!=NULL) and ($bbox->max!=NULL)) {
 			$bbox = getBBoxInScale($bbox, $scale);
 			return concatenateMapRequest($getmap, $version, $mapFormat, $layerList, $styleList,$bbox, MONITOR_IMG_WIDTH, MONITOR_IMG_HEIGHT, $exceptionFormat);
@@ -116,7 +116,7 @@
 		#$e = new mb_notice("class_monitor: getMapRequest: old bbox = " . $bbox->min->x . "," . $bbox->min->y . "," . $bbox->max->x . "," . $bbox->max->y);
 		#$e = new mb_notice("class_monitor: getMapRequest: scale = " . $scale);
 		if ($scale) {
-			$e = new mb_exception("monitorDefineGetMapBBOX: minmaxwerte? " . $bbox->max." ".$bbox->min);
+			$e = new mb_notice("monitorDefineGetMapBBOX: minmaxwerte? " . $bbox->max." ".$bbox->min);
 			$center = $bbox->min->plus($bbox->max)->times(0.5);
 		#	$e = new mb_notice("class_monitor: getMapRequest: center = " . $center);
 			
@@ -139,7 +139,7 @@
 	/**
 	 * Returns an online resource representing a get map request
 	 */
-	 function concatenateMapRequest(	$getmap, $wmsVersion, $mapFormat, $layerList, $sytleList,
+	 function concatenateMapRequest(	$getmap, $wmsVersion, $mapFormat, $layerList, $styleList,
 							$bbox, $width, $height, $exceptionFormat) {
 		/*
 		 * getMap URL

Modified: trunk/mapbender/tools/mod_monitorCapabilities_main.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_main.php	2012-05-30 06:10:19 UTC (rev 8367)
+++ trunk/mapbender/tools/mod_monitorCapabilities_main.php	2012-06-05 18:59:54 UTC (rev 8368)
@@ -17,7 +17,7 @@
 require_once dirname(__FILE__) ."/../http/classes/class_administration.php";
 require_once dirname(__FILE__) ."/../tools/mod_monitorCapabilities_defineGetMapBbox.php";
 require_once dirname(__FILE__) ."/../http/classes/class_bbox.php";
-require_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
+//require_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
 
 #do db close at the most reasonable point 
 $admin = new administration();
@@ -210,7 +210,7 @@
 
 		// Decode orig capabilities out of db cause they are converted before 
 		// saving them while upload
-		$capDoc=$admin->char_decode($capDoc);
+		//$capDoc=$admin->char_decode($capDoc);
 
 		// do the next to exchange the update before by another behavior! - 
 		// look in class_monitor.php !

Modified: trunk/mapbender/tools/mod_monitorCapabilities_write.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_write.php	2012-05-30 06:10:19 UTC (rev 8367)
+++ trunk/mapbender/tools/mod_monitorCapabilities_write.php	2012-06-05 18:59:54 UTC (rev 8368)
@@ -16,6 +16,5 @@
 
 $monitor = new Monitor($reportFile, $autoUpdate, dirname(__FILE__)."/tmp/");
 
-
 $monitor->updateInXMLReport();
 ?>



More information about the Mapbender_commits mailing list