[Mapbender-commits] r5217 - in trunk/mapbender/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Dec 18 16:00:37 EST 2009


Author: armin11
Date: 2009-12-18 16:00:37 -0500 (Fri, 18 Dec 2009)
New Revision: 5217

Modified:
   trunk/mapbender/http/classes/class_connector.php
   trunk/mapbender/http/classes/class_cswrecord.php
   trunk/mapbender/http/javascripts/mod_searchCSW_ajax.php
   trunk/mapbender/http/php/mod_searchCatQueryBuilder_server.php
Log:
first bugfixing for csw search for getrecords by http_post to allow searching in geonetwork csw nodes. id an url for getrecords in table get_op_conf is available the geonetwork242 will answer now with records! choose post and filter in the client.

Modified: trunk/mapbender/http/classes/class_connector.php
===================================================================
--- trunk/mapbender/http/classes/class_connector.php	2009-12-18 10:51:00 UTC (rev 5216)
+++ trunk/mapbender/http/classes/class_connector.php	2009-12-18 21:00:37 UTC (rev 5217)
@@ -31,7 +31,7 @@
 	private $httpType = "get";
 	private $httpVersion = "1.0";
 	private $httpPostData;
-	private $httpContentType;
+	private $httpContentType = "text/html";
 		
 	/**
 	 * @constructor
@@ -143,7 +143,7 @@
 	}
 	
 	private function isValidHttpContentType ($value) {
-		$validHttpContentTypeArray = array("XML");
+		$validHttpContentTypeArray = array("XML","TEXT/XML");
 		if (in_array(mb_strtoupper($value), $validHttpContentTypeArray)) {
 			switch (mb_strtoupper($value)) {
 				case "XML":
@@ -171,7 +171,15 @@
 		curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
 		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 		//get hostname/ip out of url
-		$host = parse_url($url,PHP_URL_HOST);
+		//$host = parse_url($url,PHP_URL_HOST);
+		$arURL = parse_url($url);
+		$host = $arURL["host"];
+		$port = $arURL["port"]; 
+		if($port == ''){
+			$port = 80;	
+		}
+		$path = $arURL["path"];
+		
 		// fill array (HOSTs not for Proxy)
  	    $NOT_PROXY_HOSTS_array = explode(",", NOT_PROXY_HOSTS);
 		if(CONNECTION_PROXY != "" AND (in_array($host, $NOT_PROXY_HOSTS_array)!= true)){
@@ -191,22 +199,28 @@
 				curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
 			}
 		}
-		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 		
+		
 		//if httpType is POST, set CURLOPT_POST and CURLOPT_POSTFIELDS  
-		if($this->httpType == 'POST'){
-			curl_setopt ($ch, CURLOPT_POST, 1);
-			curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->httpPostData);
-			$this_header = array(
-   			 		"MIME-Version: 1.0",
-    				"Content-type: text/html; charset=" . CHARSET,
-    				"Content-transfer-encoding: text"
+		//and set a usefull http header
+		if(strtoupper($this->httpType) == 'POST'){
+			$headers = array(
+					 "POST ".$path." HTTP/1.1",
+            		 "Content-type: ".$this->httpContentType."; charset=".CHARSET,
+           			 "Cache-Control: no-cache",
+	           		 "Pragma: no-cache",
+	           		 "Content-length: ".strlen($this->httpPostData)
 			); 
-			curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
+			$e = new mb_notice("connector: CURL POST: ".$this->httpPostData); 
+			$e = new mb_notice("connector: CURL POST HEADER: ".print_r($headers));
+			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+			curl_setopt($ch, CURLOPT_POST, 1);
+			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->httpPostData);	
 		}
 		
 		$useragent=CONNECTION_USERAGENT;
-		$e = new mb_exception("connector: CURL connect to: ".$url); 
+		$e = new mb_notice("connector: CURL connect to: ".$url); 
 		curl_setopt ($ch,CURLOPT_USERAGENT,$useragent);
 		$file = curl_exec ($ch);
 		//handle http authentication

Modified: trunk/mapbender/http/classes/class_cswrecord.php
===================================================================
--- trunk/mapbender/http/classes/class_cswrecord.php	2009-12-18 10:51:00 UTC (rev 5216)
+++ trunk/mapbender/http/classes/class_cswrecord.php	2009-12-18 21:00:37 UTC (rev 5217)
@@ -61,14 +61,19 @@
 		if($xml != null){
 			$connection = new connector();
         	$connection->set("httpType", "post");
-        	$connection->set("httpContentType", "xml");
+        	$connection->set("httpContentType", "text/xml");
         	$connection->set("httpPostData", $xml);
         	$data = $connection->load($url);
+        	//$e = new mb_exception("class_cswrecord:url:".$url);
+	        //$e = new mb_exception("class_cswrecord:xml:".$xml);
+	        //$e = new mb_exception("class_cswrecord:data:".$data);
+	        $e = new mb_exception("class_cswrecord.php: responded data: ".$data);
 		}
 		else{
 			$x = new connector($url);
-			$e = new mb_exception("class_cswrecord.php: requested url: ".$url);
+			//$e = new mb_exception("class_cswrecord.php: requested url: ".$url);
 			$data = $x->file;
+			$e = new mb_exception("class_cswrecord.php: responded data: ".$data);
 		}
         
 		if(!$data){

Modified: trunk/mapbender/http/javascripts/mod_searchCSW_ajax.php
===================================================================
--- trunk/mapbender/http/javascripts/mod_searchCSW_ajax.php	2009-12-18 10:51:00 UTC (rev 5216)
+++ trunk/mapbender/http/javascripts/mod_searchCSW_ajax.php	2009-12-18 21:00:37 UTC (rev 5217)
@@ -162,7 +162,7 @@
 		html = html + "<select id='opt_getrecords_media' name='opt_getrecords_media'>";
 		html = html + "<option value='get'>GET</option>";
 		html = html + "<option value='post'>POST</option>";
-		html = html + "<option value='post-soap' disabled>SOAP</option>";
+		html = html + "<option value='post-soap' disabled>SOAP</option>";//must be enabled if soap should be used in future
 		html = html + "</select>";
 		html = html + "<br /><br />";
 

Modified: trunk/mapbender/http/php/mod_searchCatQueryBuilder_server.php
===================================================================
--- trunk/mapbender/http/php/mod_searchCatQueryBuilder_server.php	2009-12-18 10:51:00 UTC (rev 5216)
+++ trunk/mapbender/http/php/mod_searchCatQueryBuilder_server.php	2009-12-18 21:00:37 UTC (rev 5217)
@@ -61,6 +61,7 @@
 	$catalogIDs = array();
 	
 	switch(mb_strtolower($getrecords_type)){
+		
 		case 'get':
 			$guicats = get_catalogs_for_gui($guiId);
 			if($DEBUG_)
@@ -72,6 +73,7 @@
 				array_push($resultObj['cats'],array("id"=>'id35'.$guiId,"title"=>$guicats[0]));
 			break;
 		case 'post':
+			
 			$catalogIDs = get_catalogs_by_supported_type(get_catalogs_for_gui($guiId),'getrecords','post');
 			break;
 		case 'soap':
@@ -138,16 +140,19 @@
 				$aurl = urlencode($aurl);
 				$tmpurl = "csw:AnyText%20Like%20%27$aurl%27";
 				$url .= (isset($simplesearch) && $simplesearch!="")?'&constraintlanguage=CQLTEXT&constraint='.$tmpurl:'';
-				
+				$e = new mb_exception("mod_searchCatQueryBuilder_server:url:".$url);
+	            $e = new mb_exception("mod_searchCatQueryBuilder_server:xml:".$xml);
 			}
 			else {
 				//Advanced GetRecords via GET
 				$url = getrecords_advanced_get($getrecords_url);
+				$e = new mb_exception("mod_searchCatQueryBuilder_server:url:".$url);
 			}
 			break;
 		case 'post':
 			$url = $getrecords_url;
 			$xml = build_getrecords_xml();
+			$e = new mb_exception("mod_searchCatQueryBuilder_server:url:".$url);
 			break;
 		case 'soap':
 			break;
@@ -156,6 +161,7 @@
 	}
 	
 	return array($url,$xml);
+	
 }	
 
 function getrecords_advanced_get($url){
@@ -252,27 +258,31 @@
  * @todo: get values dynamically
  */
 function build_getrecords_xml() {
-	$xml = '<?xml version="1.0" encoding="UTF-8"?>';
-	$xml .= '<GetRecords';
-	$xml .= 'service="CSW"';
-	$xml .= 'version="2.0.2"';
-	$xml .= 'maxRecords="5"';
-	$xml .= 'startPosition="1"';
-	$xml .= 'resultType="results"';
-	$xml .= 'outputFormat="application/xml"';
-	$xml .= 'outputSchema="http://www.opengis.net/cat/csw/2.0.2"';
-	$xml .= 'xmlns="http://www.opengis.net/cat/csw/2.0.2"';
-  	$xml .= 'xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"';
-  	$xml .= 'xmlns:ogc="http://www.opengis.net/ogc"';
-  	$xml .= 'xmlns:ows="http://www.opengis.net/ows"';
-  	$xml .= 'xmlns:dc="http://purl.org/dc/elements/1.1/"';
-  	$xml .= 'xmlns:dct="http://purl.org/dc/terms/"';
-  	$xml .= 'xmlns:gml="http://www.opengis.net/gml"';
-  	$xml .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
-	$xml .= 'xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2/CSW-discovery.xsd">';
-	$xml .= '<Query typeNames="csw:Record">';
-	$xml .= '</Query>';
-	$xml .= '</GetRecords>';
+	$xml = '<?xml version="1.0" encoding="UTF-8"?> ';
+	$xml .= '<csw:GetRecords ';
+	$xml .= 'service="CSW" ';
+	$xml .= 'version="2.0.2" ';
+	$xml .= 'maxRecords="5" ';
+	$xml .= 'startPosition="1" ';
+	$xml .= 'resultType="results" ';
+	$xml .= 'outputFormat="application/xml" ';
+	$xml .= 'outputSchema="http://www.opengis.net/cat/csw/2.0.2" ';
+	$xml .= 'xmlns="http://www.opengis.net/cat/csw/2.0.2" ';
+  	$xml .= 'xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" ';
+  	$xml .= 'xmlns:ogc="http://www.opengis.net/ogc" ';
+  	$xml .= 'xmlns:ows="http://www.opengis.net/ows" ';
+  	$xml .= 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
+  	$xml .= 'xmlns:dct="http://purl.org/dc/terms/" ';
+  	$xml .= 'xmlns:gml="http://www.opengis.net/gml" ';
+  	$xml .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
+	$xml .= 'xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2/CSW-discovery.xsd"> ';
+	$xml .= '<csw:Query typeNames="csw:Record">';
+	$xml .= '</csw:Query>';
+	$xml .= '</csw:GetRecords>';
+	//parse xml for validating it before sending
+	$data = stripslashes($xml);
+	$dataXMLObject = new SimpleXMLElement($xml);
+	$xml = $dataXMLObject->asXML();
 	
 	return $xml;
 	
@@ -282,7 +292,7 @@
 function getrecords_post ($url, $postData) {
 	 	$connection = new connector();
         $connection->set("httpType", "post");
-        $connection->set("httpContentType", "xml");
+        $connection->set("httpContentType", "text/xml");
         $connection->set("httpPostData", $postData);
 
         $e = new mb_notice("CAT REQUEST: " . $url . "\n\n" . $postData);



More information about the Mapbender_commits mailing list