[Mapbender-commits] r8558 - in trunk/mapbender: http/php http_auth/http owsproxy/http

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Feb 7 04:40:39 PST 2013


Author: armin11
Date: 2013-02-07 04:40:39 -0800 (Thu, 07 Feb 2013)
New Revision: 8558

Modified:
   trunk/mapbender/http/php/wms.php
   trunk/mapbender/http_auth/http/index.php
   trunk/mapbender/owsproxy/http/index.php
Log:
Fix some problems with owsproxy/wms fascade and http auth proxy. Exchange global reg expr url rewriting in http_auth with xpath parsing.

Modified: trunk/mapbender/http/php/wms.php
===================================================================
--- trunk/mapbender/http/php/wms.php	2013-02-07 07:53:49 UTC (rev 8557)
+++ trunk/mapbender/http/php/wms.php	2013-02-07 12:40:39 UTC (rev 8558)
@@ -34,6 +34,10 @@
 $updateSequence = intval($_GET["UPDATESEQUENCE"]);
 $inspire = $_GET["INSPIRE"];
 $sessionId = $_GET[strtoupper(session_name())];
+//if session id not set, set a dummy id!
+if (!isset($sessionId) || $sessionId =="") {
+	$sessionId = "00000000000000000000000000000000";
+	}
 if (isset($inspire) && $inspire === 1 ) {
 	$inspire = true;
 }
@@ -1233,7 +1237,7 @@
     	$formatText = $doc->createTextNode('text/html');
    	$formatText = $format->appendChild($formatText); 
 
-	if($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL)
+	/*if($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL)
 	{
 		$onlineResource = $doc->createElement("OnlineResource");
 	   	$onlineResource = $dataUrl->appendChild($onlineResource);
@@ -1242,47 +1246,37 @@
 		$onlineResource->setAttribute("xlink:type", "simple");
 	}
 	else
-	{
-		if($sub_layer_row['layer_dataurl'] <> "" AND $sub_layer_row['layer_dataurl'] <> NULL)
-	    {
-	    	$onlineResource = $doc->createElement("OnlineResource");
-	    	$onlineResource = $dataUrl->appendChild($onlineResource);
+	{*/
+		if($sub_layer_row['layer_dataurl'] <> "" AND $sub_layer_row['layer_dataurl'] <> NULL) {
+	    		$onlineResource = $doc->createElement("OnlineResource");
+	    		$onlineResource = $dataUrl->appendChild($onlineResource);
 			$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
 			$onlineResource->setAttribute("xlink:href", $sub_layer_row['layer_dataurl']);
 			$onlineResource->setAttribute("xlink:type", "simple");
-	    }
-else
-{
- $onlineResource = $doc->createElement("OnlineResource");
-                $onlineResource = $dataUrl->appendChild($onlineResource);
+	    	}
+		else
+		{
+ 			$onlineResource = $doc->createElement("OnlineResource");
+                	$onlineResource = $dataUrl->appendChild($onlineResource);
                         $onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
                         $onlineResource->setAttribute("xlink:href", $mapbenderMetadataUrl.$sub_layer_row['layer_id']);
                         $onlineResource->setAttribute("xlink:type", "simple");
-
 }
-
-
-
-
-
-
-
-	}
+	//}	
 	
-	
-	#Creating Style Node
+	#Creating Style Node TODO: pull style and format from database!
 	$style = $doc->createElement("Style");
 	$style = $sub_layer->appendChild($style);
 	
 	$name = $doc->createElement("Name");
-    $name = $style->appendChild($name);
-    $nameText = $doc->createTextNode('default');
-    $nameText = $name->appendChild($nameText);
+    	$name = $style->appendChild($name);
+    	$nameText = $doc->createTextNode('default');
+    	$nameText = $name->appendChild($nameText);
 
 	$title = $doc->createElement("Title");
-    $title = $style->appendChild($title);
-    $titleText = $doc->createTextNode('default');
-    $titleText = $title->appendChild($titleText);
+    	$title = $style->appendChild($title);
+    	$titleText = $doc->createTextNode('default');
+    	$titleText = $title->appendChild($titleText);
 	
 
 
@@ -1293,16 +1287,16 @@
 	$legendUrl->setAttribute("height", "8" );
 
 	$format = $doc->createElement("Format");
-    $format = $legendUrl->appendChild($format);
-    $formatText = $doc->createTextNode('image/png');
-    $formatText = $format->appendChild($formatText); 
+    	$format = $legendUrl->appendChild($format);
+    	$formatText = $doc->createTextNode('image/png');
+    	$formatText = $format->appendChild($formatText); 
 
 	if($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL)
 	{
 		$onlineResource = $doc->createElement("OnlineResource");
 	   	$onlineResource = $legendUrl->appendChild($onlineResource);
 	   	$onlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-		$onlineResource->setAttribute("xlink:href", OWSPROXY."/".$sessionId."/".$wms_row["wms_owsproxy"]."?version=1.1.1&service=WMS&request=GetLegendGraphic&layer=".$sub_layer_row['layer_name']."&format=image/png");
+		$onlineResource->setAttribute("xlink:href", str_replace(":80","",OWSPROXY)."/".$sessionId."/".$wms_row["wms_owsproxy"]."?version=1.1.1&service=WMS&request=GetLegendGraphic&layer=".$sub_layer_row['layer_name']."&format=image/png&style=default");
 		$onlineResource->setAttribute("xlink:type", "simple");
 	}
 	else
@@ -1316,8 +1310,6 @@
 			$onlineResource->setAttribute("xlink:type", "simple");
 	    }
 	}
-
-
 }
 	#Creating "ScaleHint" node
     if ($sub_layer_row['layer_minscale'] <> "" AND $sub_layer_row['layer_minscale'] <> NULL) {

Modified: trunk/mapbender/http_auth/http/index.php
===================================================================
--- trunk/mapbender/http_auth/http/index.php	2013-02-07 07:53:49 UTC (rev 8557)
+++ trunk/mapbender/http_auth/http/index.php	2013-02-07 12:40:39 UTC (rev 8558)
@@ -104,7 +104,11 @@
 		} else {
 			$urlPrefix = "http://";
 		}
-		$request = $urlPrefix.$_SERVER['HTTP_HOST']."/mapbender/php/wms.php?layer_id=".$layerId;
+		if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') {
+			$request = MAPBENDER_PATH."/php/wms.php?layer_id=".$layerId;
+		} else {
+			$request = $urlPrefix.$_SERVER['HTTP_HOST']."/mapbender/php/wms.php?layer_id=".$layerId;
+		}
 		$requestFull .= $request.'&REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS';
 		if(isset($auth)){
 			getCapabilities($request,$requestFull,$auth);
@@ -401,18 +405,54 @@
 	{
 		$content = getDocumentContent($requestFull);
 	}
+	//show temporal content fo capabilities
+	$e = new mb_notice("content from wms.php fascade after going thru curl: ".$content);
+	//loading as xml
+	libxml_use_internal_errors(true);
+	try {
+		$capFromFascadeXmlObject = simplexml_load_string($content);
+		if ( $capFromFascadeXmlObject === false) {
+			foreach(libxml_get_errors() as $error) {
+        			$err = new mb_exception("http_auth/index.php: ".$error->message);
+    			}
+			throw new Exception("http_auth/index.php: ".'Cannot parse Metadata XML!');
+			echo "<error>http_auth/index.php: Cannot parse Capabilities XML!</error>";
+			die();
+		}
+	}
+	catch (Exception $e) {
+    		$err = new mb_exception("http_auth/index.php: ".$e->getMessage());
+		echo "<error>http_auth/index.php: ".$e->getMessage()."</error>";
+		die();
+	}
+	//exchanging urls in some special fields
+	//
+	//GetCapabilities, GetMap, GetFeatureInfo, GetLegendGraphics, ...
+	$capFromFascadeXmlObject->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
+	//Mapping of urls for wms 1.1.1 which should be exchanged 
+	$urlsToChange = array(
+		'/WMT_MS_Capabilities/Capability/Request/GetCapabilities/DCPType/HTTP/Get/OnlineResource/@xlink:href',
+		'/WMT_MS_Capabilities/Capability/Request/GetCapabilities/DCPType/HTTP/Post/OnlineResource/@xlink:href',
+		'/WMT_MS_Capabilities/Capability/Request/GetMap/DCPType/HTTP/Get/OnlineResource/@xlink:href',
+		'/WMT_MS_Capabilities/Capability/Request/GetMap/DCPType/HTTP/Post/OnlineResource/@xlink:href',
+		'/WMT_MS_Capabilities/Capability/Request/GetFeatureInfo/DCPType/HTTP/Get/OnlineResource/@xlink:href',
+		'/WMT_MS_Capabilities/Capability/Request/GetFeatureInfo/DCPType/HTTP/Post/OnlineResource/@xlink:href',
+		'/WMT_MS_Capabilities/Capability/Layer/Layer/Style/LegendURL/OnlineResource/@xlink:href'
+	);
+	foreach($urlsToChange as $xpath) {
+		$href = $capFromFascadeXmlObject->xpath($xpath);
+		$e = new mb_notice("old href: ".$href[0]);
+		$e = new mb_notice("href replaced: ".replaceOwsUrls($href[0], $layerId));
+		$href[0][0] = replaceOwsUrls($href[0], $layerId);
+	}
+	echo $capFromFascadeXmlObject->asXML();
+}
 
-	$new = "href=\"".HTTP_AUTH_PROXY ."/". $layerId."?";
-        $pattern = "#href=\"".OWSPROXY."/[a-z0-9]{32}\/[a-z0-9]{32}\?#m";
-	$content = preg_replace($pattern,$new,$content);
-
-	#TODO: maybe do this by parsing xml rather then regexpr cause they are hungry ;-) - but fast 
-
-	$new = "href=\"".HTTP_AUTH_PROXY ."/". $layerId."?$1\"";
-	$pattern = "#href=\"".str_replace('?','\?',str_replace('/','\/',$request))."\"#";
-	$content = preg_replace($pattern,$new,$content);
-
-	echo $content;
+function replaceOwsUrls($owsUrl, $layerId) {
+	$new = "http_auth/". $layerId."?";
+        $pattern = "#owsproxy/[a-z0-9]{32}\/[a-z0-9]{32}\?#m";
+	$httpAuthUrl = preg_replace($pattern,$new,$owsUrl);
+	return $httpAuthUrl;
 }
 
 /**
@@ -429,19 +469,17 @@
 	$sql .= "ON layer_style.fkey_layer_id = layer.layer_id ";
 	$sql .= "WHERE layer.layer_name = $2 AND layer.fkey_wms_id = $1 ";
 	$sql .= "AND layer_style.name = $3 AND layer_style.legendurlformat = $4";
-	if ($reqParams['style']==''){
-		$style='default';
+	if ($reqParams['style'] == ''){
+		$style = 'default';
+	} else {
+		$style = $reqParams['style'];
 	}
-	else {
-		$style='';
-	}
 	$v = array($wmsId, $reqParams['layer'], $style, $reqParams['format']);
 	$t = array("i", "s", "s", "s");
-	
 	$res = db_prep_query($sql, $v, $t);
-	if($row = db_fetch_array($res))
-		return $row["legendurl"];
-	else{
+	if($row = db_fetch_array($res)) {	
+		return $row["legendurl"];	
+	} else {
 		throwE(array("No legendurl available."));
 		die();
 	}

Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php	2013-02-07 07:53:49 UTC (rev 8557)
+++ trunk/mapbender/owsproxy/http/index.php	2013-02-07 12:40:39 UTC (rev 8558)
@@ -574,29 +574,25 @@
  */
 function getLegendUrl($wms){
 	global $reqParams;
-	
 	//get wms id
 	$sql = "SELECT * FROM wms WHERE wms_owsproxy = $1";
 	$v = array($wms);
 	$t = array("s");
 	$res = db_prep_query($sql, $v, $t);	
-	if($row = db_fetch_array($res))
+	if($row = db_fetch_array($res)) {
 		$wmsid = $row["wms_id"];
-	else{
+	} else {
 		throwE(array("No wms data available."));
 		die();	
 	}
-	
 	//get the url
 	$sql = "SELECT layer_style.legendurl ";
 	$sql .= "FROM layer_style JOIN layer ";
 	$sql .= "ON layer_style.fkey_layer_id = layer.layer_id ";
 	$sql .= "WHERE layer.layer_name = $2 AND layer.fkey_wms_id = $1 ";
 	$sql .= "AND layer_style.name = $3 AND layer_style.legendurlformat = $4";
-	
 	$v = array($wmsid, $reqParams['layer'], $reqParams['style'], $reqParams['format']);
 	$t = array("i", "s", "s", "s");
-	
 	$res = db_prep_query($sql, $v, $t);
 	if($row = db_fetch_array($res))
 		return $row["legendurl"];



More information about the Mapbender_commits mailing list