Skip to content

Commit

Permalink
better error handling for the WFS Protocol, note this is currently on…
Browse files Browse the repository at this point in the history
…ly done for WFS 1.1.0 and not for WFS 1.0.0, thanks tschaub for the reviews this week, r=tschaub (closes #3354)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12080 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
  • Loading branch information
bartvde committed Jun 10, 2011
1 parent f9c0a1d commit 4d0f73e
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/OpenLayers/Format/OWSCommon/v1_0_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ OpenLayers.Format.OWSCommon.v1_0_0 = OpenLayers.Class(OpenLayers.Format.OWSCommo
readers: {
"ows": OpenLayers.Util.applyDefaults({
"ExceptionReport": function(node, obj) {
obj.success = false;
obj.exceptionReport = {
version: node.getAttribute('version'),
language: node.getAttribute('language'),
Expand Down
3 changes: 2 additions & 1 deletion lib/OpenLayers/Format/WFST/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
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"
},

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/OpenLayers/Format/WFST/v1_1_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -96,7 +97,8 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
}, 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"]
},

/**
Expand Down
6 changes: 6 additions & 0 deletions lib/OpenLayers/Protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ OpenLayers.Protocol.Response = OpenLayers.Class({
*/
priv: null,

/**
* Property: error
* {Object} The error object in case a service exception was encountered.
*/
error: null,

/**
* Constructor: OpenLayers.Protocol.Response
*
Expand Down
25 changes: 17 additions & 8 deletions lib/OpenLayers/Protocol/WFS/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,19 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
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;
Expand Down Expand Up @@ -346,9 +352,12 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
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);
}
},
Expand Down
62 changes: 62 additions & 0 deletions tests/Protocol/WFS.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 4d0f73e

Please sign in to comment.