[OpenLayers-Commits] r12065 - in sandbox/bartvde/exception/openlayers: lib/OpenLayers/Format/WMSCapabilities tests/Format/WMSCapabilities

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Jun 7 17:26:16 EDT 2011


Author: bartvde
Date: 2011-06-07 14:26:15 -0700 (Tue, 07 Jun 2011)
New Revision: 12065

Modified:
   sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/WMSCapabilities/v1.js
   sandbox/bartvde/exception/openlayers/tests/Format/WMSCapabilities/v1_1_1.html
Log:
hook error handling into WMS GetCapabilities 1.1 parser

Modified: sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/WMSCapabilities/v1.js
===================================================================
--- sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/WMSCapabilities/v1.js	2011-06-07 20:44:06 UTC (rev 12064)
+++ sandbox/bartvde/exception/openlayers/lib/OpenLayers/Format/WMSCapabilities/v1.js	2011-06-07 21:26:15 UTC (rev 12065)
@@ -5,6 +5,7 @@
 
 /**
  * @requires OpenLayers/Format/WMSCapabilities.js
+ * @requires OpenLayers/Format/OGCExceptionReport.js
  * @requires OpenLayers/Format/XML.js
  */
 
@@ -60,15 +61,20 @@
         if(typeof data == "string") {
             data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
         }
+        var raw = data;
         if(data && data.nodeType == 9) {
             data = data.documentElement;
         }
         var capabilities = {};
         this.readNode(data, capabilities);
-    
-        // postprocess the layer list
-        this.postProcessLayers(capabilities);
-    
+        if (capabilities.service === undefined) {
+            // an exception must have occurred, so parse it
+            var parser = new OpenLayers.Format.OGCExceptionReport();
+            capabilities.error = parser.read(raw);
+        } else {
+            // postprocess the layer list
+            this.postProcessLayers(capabilities);
+        }
         return capabilities;
     },
 

Modified: sandbox/bartvde/exception/openlayers/tests/Format/WMSCapabilities/v1_1_1.html
===================================================================
--- sandbox/bartvde/exception/openlayers/tests/Format/WMSCapabilities/v1_1_1.html	2011-06-07 20:44:06 UTC (rev 12064)
+++ sandbox/bartvde/exception/openlayers/tests/Format/WMSCapabilities/v1_1_1.html	2011-06-07 21:26:15 UTC (rev 12065)
@@ -2,6 +2,15 @@
 <head> 
     <script src="../../OLLoader.js"></script>
     <script type="text/javascript">
+
+    function test_read_exeption(t) {
+        t.plan(1);
+        var xml = document.getElementById("exceptionsample").firstChild.nodeValue;
+        var doc = new OpenLayers.Format.XML().read(xml);
+        var format = new OpenLayers.Format.WMSCapabilities();
+        var obj = format.read(doc);
+        t.ok(!!obj.error, "Error reported correctly");
+    }
     
     function test_read(t) {
         
@@ -644,6 +653,12 @@
 </Capability>
 </WMT_MS_Capabilities>
 --></div>
+<div id="exceptionsample"><!--
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/WMS_exception_1_1_1.dtd">
+<ServiceExceptionReport version="1.1.1"><ServiceException> Plain text message about an error. </ServiceException>
+</ServiceExceptionReport>
+--></div>
 <!--
 GeoServer example below taken from
 http://publicus.opengeo.org/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities



More information about the Commits mailing list