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)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@12080 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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_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"]
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user