[OpenLayers-Commits] r12080 - in trunk/openlayers: lib/OpenLayers lib/OpenLayers/Format/OWSCommon lib/OpenLayers/Format/WFST lib/OpenLayers/Protocol/WFS tests/Protocol

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Jun 10 13:12:23 EDT 2011


Author: bartvde
Date: 2011-06-10 10:12:22 -0700 (Fri, 10 Jun 2011)
New Revision: 12080

Modified:
   trunk/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js
   trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js
   trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js
   trunk/openlayers/lib/OpenLayers/Protocol.js
   trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
   trunk/openlayers/tests/Protocol/WFS.html
Log:
better error handling for the WFS Protocol, note this is currently only done for WFS 1.1.0 and not for WFS 1.0.0, thanks tschaub for the reviews this week, r=tschaub (closes #3354)

Modified: trunk/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js	2011-06-10 16:32:58 UTC (rev 12079)
+++ trunk/openlayers/lib/OpenLayers/Format/OWSCommon/v1_0_0.js	2011-06-10 17:12:22 UTC (rev 12080)
@@ -33,6 +33,7 @@
     readers: {
         "ows": OpenLayers.Util.applyDefaults({
             "ExceptionReport": function(node, obj) {
+                obj.success = false;
                 obj.exceptionReport = {
                     version: node.getAttribute('version'),
                     language: node.getAttribute('language'),

Modified: trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js	2011-06-10 16:32:58 UTC (rev 12079)
+++ trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js	2011-06-10 17:12:22 UTC (rev 12080)
@@ -26,7 +26,8 @@
         xsi: "http://www.w3.org/2001/XMLSchema-instance",
         wfs: "http://www.opengis.net/wfs",
         gml: "http://www.opengis.net/gml",
-        ogc: "http://www.opengis.net/ogc"
+        ogc: "http://www.opengis.net/ogc",
+        ows: "http://www.opengis.net/ows"
     },
     
     /**

Modified: trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js	2011-06-10 16:32:58 UTC (rev 12079)
+++ trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js	2011-06-10 17:12:22 UTC (rev 12080)
@@ -6,6 +6,7 @@
 /**
  * @requires OpenLayers/Format/WFST/v1.js
  * @requires OpenLayers/Format/Filter/v1_1_0.js
+ * @requires OpenLayers/Format/OWSCommon/v1_0_0.js
  */
 
 /**
@@ -96,7 +97,8 @@
         }, OpenLayers.Format.WFST.v1.prototype.readers["wfs"]),
         "gml": OpenLayers.Format.GML.v3.prototype.readers["gml"],
         "feature": OpenLayers.Format.GML.v3.prototype.readers["feature"],
-        "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"]
+        "ogc": OpenLayers.Format.Filter.v1_1_0.prototype.readers["ogc"],
+        "ows": OpenLayers.Format.OWSCommon.v1_0_0.prototype.readers["ows"]
     },
 
     /**

Modified: trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2011-06-10 16:32:58 UTC (rev 12079)
+++ trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2011-06-10 17:12:22 UTC (rev 12080)
@@ -249,13 +249,19 @@
             var request = response.priv;
             if(request.status >= 200 && request.status < 300) {
                 // success
-                if (options.readOptions && options.readOptions.output == "object") {
-                    OpenLayers.Util.extend(response, 
-                        this.parseResponse(request, options.readOptions));
+                var result = this.parseResponse(request, options.readOptions);
+                if (result && result.success !== false) { 
+                    if (options.readOptions && options.readOptions.output == "object") {
+                        OpenLayers.Util.extend(response, result);
+                    } else {
+                        response.features = result;
+                    }
+                    response.code = OpenLayers.Protocol.Response.SUCCESS;
                 } else {
-                    response.features = this.parseResponse(request, options.readOptions);
+                    // failure (service exception)
+                    response.code = OpenLayers.Protocol.Response.FAILURE;
+                    response.error = result;
                 }
-                response.code = OpenLayers.Protocol.Response.SUCCESS;
             } else {
                 // failure
                 response.code = OpenLayers.Protocol.Response.FAILURE;
@@ -346,9 +352,12 @@
             var obj = this.format.read(data) || {};
             
             response.insertIds = obj.insertIds || [];
-            response.code = (obj.success) ?
-                OpenLayers.Protocol.Response.SUCCESS :
-                OpenLayers.Protocol.Response.FAILURE;
+            if (obj.success) {
+                response.code = OpenLayers.Protocol.Response.SUCCESS;
+            } else {
+                response.code = OpenLayers.Protocol.Response.FAILURE;
+                response.error = obj;
+            }
             options.callback.call(options.scope, response);
         }
     },

Modified: trunk/openlayers/lib/OpenLayers/Protocol.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol.js	2011-06-10 16:32:58 UTC (rev 12079)
+++ trunk/openlayers/lib/OpenLayers/Protocol.js	2011-06-10 17:12:22 UTC (rev 12080)
@@ -249,6 +249,12 @@
     priv: null,
 
     /**
+     * Property: error
+     * {Object} The error object in case a service exception was encountered.
+     */
+    error: null,
+
+    /**
      * Constructor: OpenLayers.Protocol.Response
      *
      * Parameters:

Modified: trunk/openlayers/tests/Protocol/WFS.html
===================================================================
--- trunk/openlayers/tests/Protocol/WFS.html	2011-06-10 16:32:58 UTC (rev 12079)
+++ trunk/openlayers/tests/Protocol/WFS.html	2011-06-10 17:12:22 UTC (rev 12080)
@@ -105,6 +105,68 @@
         OpenLayers.Request.POST = _POST;
     }
 
+    function test_exception(t) {
+        t.plan(8);
+        var url = "http://some.url.org";
+        var protocol = new OpenLayers.Protocol.WFS({
+            url: url,
+            version: "1.1.0",
+            featureNS: "http://namespace.org",
+            featureType: "type"
+        });
+        // mock up a response
+        var response = {
+            priv: {
+                status: 200,
+                responseText: '<?xml version="1.0" encoding="UTF-8"?><ows:ExceptionReport language="en" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows"><ows:Exception locator="foo" exceptionCode="InvalidParameterValue"><ows:ExceptionText>Update error: Error occurred updating features</ows:ExceptionText><ows:ExceptionText>Second exception line</ows:ExceptionText></ows:Exception></ows:ExceptionReport>'
+            }
+        };
+        var log, entry, expected;
+        
+        // test GetFeature
+        log = [];
+        protocol.handleRead(OpenLayers.Util.extend({}, response), {
+            callback: function(resp) {
+                log.push(resp);
+            }
+        });
+        expected = {
+            exceptionReport: {
+                version: "1.0.0",
+                language: "en",
+                exceptions: [{
+                    code: "InvalidParameterValue",
+                    locator: "foo",
+                    texts: [
+                        "Update error: Error occurred updating features",
+                        "Second exception line"
+                    ]
+                }]
+            },
+            success: false
+        };
+
+        t.eq(log.length, 1, "GetFeature handled");
+        entry = log[0];
+        t.eq(entry.code, OpenLayers.Protocol.Response.FAILURE, "GetFeature failure reported");
+        t.ok(!!entry.error, "GetFeature got error");
+        t.eq(entry.error, expected, "GetFeature error matches expected");
+
+        // test a commit
+        log = [];
+        protocol.handleCommit(response, {
+            callback: function(resp) {
+                log.push(resp);
+            }
+        });
+        t.eq(log.length, 1, "commit handled");
+        entry = log[0];
+        t.eq(entry.code, OpenLayers.Protocol.Response.FAILURE, "commit failure reported");
+        t.ok(!!entry.error, "commit got error");
+        t.eq(entry.error, expected, "GetFeature error matches expected");
+
+    }
+
     function test_commit(t){
         t.plan(5);
 



More information about the Commits mailing list