adding a format to parsing OGC service exceptions (WMS 1.1 WMS 1.3 WFS 1.0 and OWSCommon 1.0 and 1.1) and hooking it up into the GetCapabilities parsers, r=tschaub (closes #2234)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12074 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2011-06-08 14:39:12 +00:00
parent 9d5ab38fc0
commit 2b04fd6c34
15 changed files with 505 additions and 17 deletions
+100
View File
@@ -0,0 +1,100 @@
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
function test_read_exception(t) {
t.plan(21);
// OCG WMS 1.3.0 exceptions
var text = '<?xml version="1.0" encoding="UTF-8"?> ' +
'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xsi:schemaLocation="http://www.opengis.net/ogc' +
' http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">' +
' <ServiceException> Plain text message about an error. </ServiceException>' +
' <ServiceException code="InvalidUpdateSequence"> Another error message, this one with a service exception code supplied. </ServiceException>' +
' <ServiceException>' +
' <![CDATA[ Error in module <foo.c>, line 42' +
'A message that includes angle brackets in text must be enclosed in a Character Data Section as in this example. All XML-like markup is ignored except for this sequence of three closing characters:' +
']]>' +
' </ServiceException>' +
' <ServiceException>' +
' <![CDATA[ <Module>foo.c</Module> <Error>An error occurred</Error> <Explanation>Similarly, actual XML can be enclosed in a CDATA section. A generic parser will ignore that XML, but application-specific software may choose to process it.</Explanation> ]]>' +
' </ServiceException>' +
'</ServiceExceptionReport>';
var parser = new OpenLayers.Format.OGCExceptionReport();
var result = parser.read(text);
var exceptions = result.exceptionReport.exceptions;
var testWMS = function(exceptions) {
t.eq(exceptions.length, 4, "We expect 4 exception messages");
t.eq(exceptions[0].text, " Plain text message about an error. ", "First error message correctly parsed");
t.eq(exceptions[1].code, "InvalidUpdateSequence", "Code of second error message correctly parsed");
t.eq(exceptions[1].text, " Another error message, this one with a service exception code supplied. ", "Text of second error message correctly parsed");
t.eq(OpenLayers.String.trim(exceptions[2].text), "Error in module <foo.c>, line 42A message that includes angle brackets in text must be enclosed in a Character Data Section as in this example. All XML-like markup is ignored except for this sequence of three closing characters:", "Third message correctly parsed");
t.eq(OpenLayers.String.trim(exceptions[3].text), "<Module>foo.c</Module> <Error>An error occurred</Error> <Explanation>Similarly, actual XML can be enclosed in a CDATA section. A generic parser will ignore that XML, but application-specific software may choose to process it.</Explanation>", "Fourth message correctly parsed");
};
testWMS(exceptions);
// OGC WMS 1.1.1 exceptions
text = '<?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>' +
' <ServiceException code="InvalidUpdateSequence"> Another error message, this one with a service exception code supplied. </ServiceException>' +
' <ServiceException>' +
' <![CDATA[ Error in module <foo.c>, line 42' +
'A message that includes angle brackets in text must be enclosed in a Character Data Section as in this example. All XML-like markup is ignored except for this sequence of three closing characters:' +
']]>' +
' </ServiceException>' +
' <ServiceException>' +
' <![CDATA[ <Module>foo.c</Module> <Error>An error occurred</Error> <Explanation>Similarly, actual XML can be enclosed in a CDATA section. A generic parser will ignore that XML, but application-specific software may choose to process it.</Explanation> ]]>' +
' </ServiceException>' +
'</ServiceExceptionReport>';
result = parser.read(text);
exceptions = result.exceptionReport.exceptions;
testWMS(exceptions);
// OGC WFS 1.0.0 exceptions
text = '<?xml version="1.0" ?> ' +
'<ServiceExceptionReport version="1.2.0" xmlns="http://www.opengis.net/ogc"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">' +
' <ServiceException code="999" locator="INSERT STMT 01"> parse error: missing closing tag for element WKB_GEOM </ServiceException>' +
'</ServiceExceptionReport>';
result = parser.read(text);
t.eq(result.exceptionReport.exceptions[0].code, "999", "code parsed correctly");
t.eq(result.exceptionReport.exceptions[0].locator, "INSERT STMT 01", "locator parsed correctly");
t.eq(result.exceptionReport.exceptions[0].text, " parse error: missing closing tag for element WKB_GEOM ", "error text parsed correctly");
// OGC WFS 1.1.0 exceptions that use OWSCommon 1.0
text = '<?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 occured updating features</ows:ExceptionText>' +
' <ows:ExceptionText>Second exception line</ows:ExceptionText>' +
' </ows:Exception>' +
'</ows:ExceptionReport>';
var result = parser.read(text);
var report = result.exceptionReport;
t.eq(report.version, "1.0.0", "Version parsed correctly");
t.eq(report.language, "en", "Language parsed correctly");
var exception = report.exceptions[0];
t.eq(exception.code, "InvalidParameterValue", "exceptionCode properly parsed");
t.eq(exception.locator, "foo", "locator properly parsed");
t.eq(exception.texts[0], "Update error: Error occured updating features", "ExceptionText correctly parsed");
t.eq(exception.texts[1], "Second exception line", "Second ExceptionText correctly parsed");
}
</script>
</head>
<body>
</body>
</html>
+34
View File
@@ -0,0 +1,34 @@
<html>
<head>
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
function test_read_exception(t) {
t.plan(6);
var text = '<?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 occured updating features</ows:ExceptionText>' +
' <ows:ExceptionText>Second exception line</ows:ExceptionText>' +
' </ows:Exception>' +
'</ows:ExceptionReport>';
var format = new OpenLayers.Format.OWSCommon();
var result = format.read(text);
var report = result.exceptionReport;
t.eq(report.version, "1.0.0", "Version parsed correctly");
t.eq(report.language, "en", "Language parsed correctly");
var exception = report.exceptions[0];
t.eq(exception.code, "InvalidParameterValue", "exceptionCode properly parsed");
t.eq(exception.locator, "foo", "locator properly parsed");
t.eq(exception.texts[0], "Update error: Error occured updating features", "ExceptionText correctly parsed");
t.eq(exception.texts[1], "Second exception line", "Second ExceptionText correctly parsed");
}
</script>
</head>
<body>
</body>
</html>
+34
View File
@@ -0,0 +1,34 @@
<html>
<head>
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
function test_read_exception(t) {
t.plan(6);
var text = '<?xml version="1.0" encoding="UTF-8"?>' +
'<ows:ExceptionReport xml:lang="en" version="1.0.0"' +
' xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows/1.1">' +
' <ows:Exception locator="foo" exceptionCode="InvalidParameterValue">' +
' <ows:ExceptionText>Update error: Error occured updating features</ows:ExceptionText>' +
' <ows:ExceptionText>Second exception line</ows:ExceptionText>' +
' </ows:Exception>' +
'</ows:ExceptionReport>';
var format = new OpenLayers.Format.OWSCommon();
var result = format.read(text);
var report = result.exceptionReport;
t.eq(report.version, "1.0.0", "Version parsed correctly");
t.eq(report.language, "en", "Language parsed correctly");
var exception = report.exceptions[0];
t.eq(exception.code, "InvalidParameterValue", "exceptionCode properly parsed");
t.eq(exception.locator, "foo", "locator properly parsed");
t.eq(exception.texts[0], "Update error: Error occured updating features", "ExceptionText correctly parsed");
t.eq(exception.texts[1], "Second exception line", "Second ExceptionText correctly parsed");
}
</script>
</head>
<body>
</body>
</html>
+17
View File
@@ -2,6 +2,23 @@
<head>
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
function test_read_exception(t) {
t.plan(1);
var parser = new OpenLayers.Format.WFSCapabilities();
var text = '<?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 occured updating features</ows:ExceptionText>' +
' <ows:ExceptionText>Second exception line</ows:ExceptionText>' +
' </ows:Exception>' +
'</ows:ExceptionReport>';
var obj = parser.read(text);
t.ok(!!obj.error, "Error reported correctly");
}
function test_read(t) {
t.plan(33);
+15
View File
@@ -2,6 +2,15 @@
<head>
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
function test_read_exception(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) {
@@ -678,6 +687,12 @@ Changes:
</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
+29
View File
@@ -3,6 +3,15 @@
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
function test_read_exception(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_layers(t) {
t.plan(22);
@@ -280,6 +289,26 @@
</head>
<body>
<div id="exceptionsample"><!--
<?xml version='1.0' encoding="UTF-8"?>
<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/ogc
http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">
<ServiceException> Plain text message about an error. </ServiceException>
<ServiceException code="InvalidUpdateSequence"> Another error message, this one with a service
exception code supplied. </ServiceException>
<ServiceException>
<![CDATA[ Error in module <foo.c>, line 42
A message that includes angle brackets in text must be enclosed in a Character Data Section as in this example. All XML-like markup is ignored except for this sequence of three closing characters:
]]>
</ServiceException>
<ServiceException>
<![CDATA[ <Module>foo.c</Module> <Error>An error occurred</Error> <Explanation>Similarly, actual XML can be enclosed in a CDATA section. A generic parser will ignore that XML, but application-specific software may choose to process it.</Explanation> ]]>
</ServiceException>
</ServiceExceptionReport>
--></div>
<!--
OGC example below taken from
http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xml
+3
View File
@@ -104,6 +104,9 @@
<li>Format/SOSGetObservation.html</li>
<li>Format/SOSGetFeatureOfInterest.html</li>
<li>Format/OWSContext/v0_3_1.html</li>
<li>Format/OWSCommon/v1_0_0.html</li>
<li>Format/OWSCommon/v1_1_0.html</li>
<li>Format/OGCExceptionReport.html</li>
<li>Format/XLS/v1_1_0.html</li>
<li>Format/XML.html</li>
<li>Geometry.html</li>