Skip to content

Commit 838367e

Browse files
committedJul 14, 2013
improve wfs error reporting in server and client
1 parent 89ffc54 commit 838367e

File tree

4 files changed

+67
-38
lines changed

4 files changed

+67
-38
lines changed
 

‎src/core/qgsogcutils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ QgsGeometry* QgsOgcUtils::geometryFromGML( const QDomNode& geometryNode )
2020
QDomElement geometryTypeElement = geometryNode.toElement();
2121
QString geomType = geometryTypeElement.tagName();
2222

23-
if ( !( geomType == "Point" || geomType == "LineString" || geomType == "Polygon" || geomType == "MultiPoint" || geomType == "MultiLineString" || geomType == "MultiPolygon" || geomType == "Box" || geomType == "Envelope" ) )
23+
if ( !( geomType == "Point" || geomType == "LineString" || geomType == "Polygon" ||
24+
geomType == "MultiPoint" || geomType == "MultiLineString" || geomType == "MultiPolygon" ||
25+
geomType == "Box" || geomType == "Envelope" ) )
2426
{
2527
QDomNode geometryChild = geometryNode.firstChild();
2628
if ( geometryChild.isNull() )
@@ -31,7 +33,9 @@ QgsGeometry* QgsOgcUtils::geometryFromGML( const QDomNode& geometryNode )
3133
geomType = geometryTypeElement.tagName();
3234
}
3335

34-
if ( !( geomType == "Point" || geomType == "LineString" || geomType == "Polygon" || geomType == "MultiPoint" || geomType == "MultiLineString" || geomType == "MultiPolygon" || geomType == "Box" || geomType == "Envelope" ) )
36+
if ( !( geomType == "Point" || geomType == "LineString" || geomType == "Polygon" ||
37+
geomType == "MultiPoint" || geomType == "MultiLineString" || geomType == "MultiPolygon" ||
38+
geomType == "Box" || geomType == "Envelope" ) )
3539
return 0;
3640

3741
if ( geomType == "Point" )
@@ -525,7 +529,6 @@ QgsGeometry* QgsOgcUtils::geometryFromGMLMultiLineString( const QDomElement& geo
525529
if ( nLines < 1 )
526530
return 0;
527531

528-
529532
//calculate the required wkb size
530533
int size = ( lineCoordinates.size() + 1 ) * ( 1 + 2 * sizeof( int ) );
531534
for ( std::list<std::list<QgsPoint> >::const_iterator it = lineCoordinates.begin(); it != lineCoordinates.end(); ++it )
@@ -560,9 +563,8 @@ QgsGeometry* QgsOgcUtils::geometryFromGMLMultiLineString( const QDomElement& geo
560563
for ( std::list<QgsPoint>::const_iterator iter = it->begin(); iter != it->end(); ++iter )
561564
{
562565
x = iter->x();
563-
//qWarning("x is: " + QString::number(x));
564566
y = iter->y();
565-
//qWarning("y is: " + QString::number(y));
567+
// QgsDebugMsg( QString( "x, y is %1,%2" ).arg( x, 'f' ).arg( y, 'f' ) );
566568
memcpy( &( wkb )[wkbPosition], &x, sizeof( double ) );
567569
wkbPosition += sizeof( double );
568570
memcpy( &( wkb )[wkbPosition], &y, sizeof( double ) );

‎src/mapserver/qgswfsserver.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
13481348
// Commit the changes of the update elements
13491349
if ( !layer->commitChanges() )
13501350
{
1351+
QgsDebugMsg( QString( "update errors:\n %1" ).arg( layer->commitErrors().join( "\n " ) ) );
13511352
QDomElement trElem = doc.createElement( "TransactionResult" );
13521353
QDomElement stElem = doc.createElement( "Status" );
13531354
QDomElement successElem = doc.createElement( "PARTIAL" );
@@ -1384,6 +1385,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
13841385
// Commit the changes of the delete elements
13851386
if ( !layer->commitChanges() )
13861387
{
1388+
QgsDebugMsg( QString( "delete errors:\n %1" ).arg( layer->commitErrors().join( "\n " ) ) );
13871389
QDomElement trElem = doc.createElement( "TransactionResult" );
13881390
QDomElement stElem = doc.createElement( "Status" );
13891391
QDomElement successElem = doc.createElement( "PARTIAL" );
@@ -1401,8 +1403,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
14011403

14021404
return resp;
14031405
}
1404-
// Start the insert transaction
1405-
layer->startEditing();
1406+
14061407
// Store the inserted features
14071408
QgsFeatureList inFeatList;
14081409
if ( cap & QgsVectorDataProvider::AddFeatures )
@@ -1466,7 +1467,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
14661467
}
14671468
}
14681469
}
1469-
// Commit the changes of the insert elements
1470+
// add the features
14701471
if ( !provider->addFeatures( inFeatList ) )
14711472
{
14721473
QDomElement trElem = doc.createElement( "TransactionResult" );
@@ -1488,7 +1489,12 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
14881489
mesErrors << "\n Provider errors:" << provider->errors();
14891490
provider->clearErrors();
14901491
}
1491-
mesElem.appendChild( doc.createTextNode( layer->commitErrors().join( "\n " ) ) );
1492+
else
1493+
{
1494+
mesErrors << "\n Provider didn't report any errors:";
1495+
}
1496+
QgsDebugMsg( QString( "add errors:\n %1" ).arg( mesErrors.join( "\n " ) ) );
1497+
mesElem.appendChild( doc.createTextNode( mesErrors.join( "\n " ) ) );
14921498
trElem.appendChild( mesElem );
14931499

14941500
return resp;

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ static const QString TEXT_PROVIDER_DESCRIPTION = "WFS data provider";
4949

5050
static const QString WFS_NAMESPACE = "http://www.opengis.net/wfs";
5151
static const QString GML_NAMESPACE = "http://www.opengis.net/gml";
52+
static const QString OGC_NAMESPACE = "http://www.opengis.net/ogc";
53+
static const QString OWS_NAMESPACE = "http://www.opengis.net/ows";
5254

5355
QgsWFSProvider::QgsWFSProvider( const QString& uri )
5456
: QgsVectorDataProvider( uri )
@@ -332,7 +334,7 @@ bool QgsWFSProvider::addFeatures( QgsFeatureList &flist )
332334
for ( ; featureIt != flist.end(); ++featureIt )
333335
{
334336
//Insert element
335-
QDomElement insertElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Insert" );
337+
QDomElement insertElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Insert" );
336338
transactionElem.appendChild( insertElem );
337339

338340
QDomElement featureElem = transactionDoc.createElementNS( mWfsNamespace, tname );
@@ -424,9 +426,9 @@ bool QgsWFSProvider::deleteFeatures( const QgsFeatureIds &id )
424426
QDomElement transactionElem = createTransactionElement( transactionDoc );
425427
transactionDoc.appendChild( transactionElem );
426428
//delete element
427-
QDomElement deleteElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Delete" );
429+
QDomElement deleteElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Delete" );
428430
deleteElem.setAttribute( "typeName", tname );
429-
QDomElement filterElem = transactionDoc.createElementNS( "http://www.opengis.net/ogc", "Filter" );
431+
QDomElement filterElem = transactionDoc.createElementNS( OGC_NAMESPACE, "Filter" );
430432

431433

432434
QgsFeatureIds::const_iterator idIt = id.constBegin();
@@ -438,7 +440,7 @@ bool QgsWFSProvider::deleteFeatures( const QgsFeatureIds &id )
438440
{
439441
continue;
440442
}
441-
QDomElement featureIdElem = transactionDoc.createElementNS( "http://www.opengis.net/ogc", "FeatureId" );
443+
QDomElement featureIdElem = transactionDoc.createElementNS( OGC_NAMESPACE, "FeatureId" );
442444
featureIdElem.setAttribute( "fid", fidIt.value() );
443445
filterElem.appendChild( featureIdElem );
444446
}
@@ -502,23 +504,23 @@ bool QgsWFSProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
502504
continue;
503505
}
504506

505-
QDomElement updateElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Update" );
507+
QDomElement updateElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Update" );
506508
updateElem.setAttribute( "typeName", tname );
507509
//Property
508-
QDomElement propertyElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Property" );
509-
QDomElement nameElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Name" );
510+
QDomElement propertyElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Property" );
511+
QDomElement nameElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Name" );
510512
QDomText nameText = transactionDoc.createTextNode( mGeometryAttribute );
511513
nameElem.appendChild( nameText );
512514
propertyElem.appendChild( nameElem );
513-
QDomElement valueElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Value" );
515+
QDomElement valueElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Value" );
514516
QDomElement gmlElem = QgsOgcUtils::geometryToGML( &geomIt.value(), transactionDoc );
515517
valueElem.appendChild( gmlElem );
516518
propertyElem.appendChild( valueElem );
517519
updateElem.appendChild( propertyElem );
518520

519521
//filter
520-
QDomElement filterElem = transactionDoc.createElementNS( "http://www.opengis.net/ogc", "Filter" );
521-
QDomElement featureIdElem = transactionDoc.createElementNS( "http://www.opengis.net/ogc", "FeatureId" );
522+
QDomElement filterElem = transactionDoc.createElementNS( OGC_NAMESPACE, "Filter" );
523+
QDomElement featureIdElem = transactionDoc.createElementNS( OGC_NAMESPACE, "FeatureId" );
522524
featureIdElem.setAttribute( "fid", fidIt.value() );
523525
filterElem.appendChild( featureIdElem );
524526
updateElem.appendChild( filterElem );
@@ -589,21 +591,21 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
589591
continue;
590592
}
591593

592-
QDomElement updateElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Update" );
594+
QDomElement updateElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Update" );
593595
updateElem.setAttribute( "typeName", tname );
594596

595597
QgsAttributeMap::const_iterator attMapIt = attIt.value().constBegin();
596598
for ( ; attMapIt != attIt.value().constEnd(); ++attMapIt )
597599
{
598600
QString fieldName = mFields.at( attMapIt.key() ).name();
599-
QDomElement propertyElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Property" );
601+
QDomElement propertyElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Property" );
600602

601-
QDomElement nameElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Name" );
603+
QDomElement nameElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Name" );
602604
QDomText nameText = transactionDoc.createTextNode( fieldName );
603605
nameElem.appendChild( nameText );
604606
propertyElem.appendChild( nameElem );
605607

606-
QDomElement valueElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Value" );
608+
QDomElement valueElem = transactionDoc.createElementNS( WFS_NAMESPACE, "Value" );
607609
QDomText valueText = transactionDoc.createTextNode( attMapIt.value().toString() );
608610
valueElem.appendChild( valueText );
609611
propertyElem.appendChild( valueElem );
@@ -612,8 +614,8 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
612614
}
613615

614616
//Filter
615-
QDomElement filterElem = transactionDoc.createElementNS( "http://www.opengis.net/ogc", "Filter" );
616-
QDomElement featureIdElem = transactionDoc.createElementNS( "http://www.opengis.net/ogc", "FeatureId" );
617+
QDomElement filterElem = transactionDoc.createElementNS( OGC_NAMESPACE, "Filter" );
618+
QDomElement featureIdElem = transactionDoc.createElementNS( OGC_NAMESPACE, "FeatureId" );
617619
featureIdElem.setAttribute( "fid", fidIt.value() );
618620
filterElem.appendChild( featureIdElem );
619621
updateElem.appendChild( filterElem );
@@ -1407,7 +1409,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
14071409

14081410
QDomElement QgsWFSProvider::createTransactionElement( QDomDocument& doc ) const
14091411
{
1410-
QDomElement transactionElem = doc.createElementNS( "http://www.opengis.net/wfs", "Transaction" );
1412+
QDomElement transactionElem = doc.createElementNS( WFS_NAMESPACE, "Transaction" );
14111413
transactionElem.setAttribute( "version", "1.0.0" );
14121414
transactionElem.setAttribute( "service", "WFS" );
14131415
transactionElem.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
@@ -1437,13 +1439,13 @@ bool QgsWFSProvider::transactionSuccess( const QDomDocument& serverResponse ) co
14371439
return false;
14381440
}
14391441

1440-
QDomNodeList transactionResultList = documentElem.elementsByTagNameNS( "http://www.opengis.net/wfs", "TransactionResult" );
1442+
QDomNodeList transactionResultList = documentElem.elementsByTagNameNS( WFS_NAMESPACE, "TransactionResult" );
14411443
if ( transactionResultList.size() < 1 )
14421444
{
14431445
return false;
14441446
}
14451447

1446-
QDomNodeList statusList = transactionResultList.at( 0 ).toElement().elementsByTagNameNS( "http://www.opengis.net/wfs", "Status" );
1448+
QDomNodeList statusList = transactionResultList.at( 0 ).toElement().elementsByTagNameNS( WFS_NAMESPACE, "Status" );
14471449
if ( statusList.size() < 1 )
14481450
{
14491451
return false;
@@ -1473,10 +1475,10 @@ QStringList QgsWFSProvider::insertedFeatureIds( const QDomDocument& serverRespon
14731475
return ids;
14741476
}
14751477

1476-
QDomNodeList insertResultList = rootElem.elementsByTagNameNS( "http://www.opengis.net/wfs", "InsertResult" );
1478+
QDomNodeList insertResultList = rootElem.elementsByTagNameNS( WFS_NAMESPACE, "InsertResult" );
14771479
for ( int i = 0; i < insertResultList.size(); ++i )
14781480
{
1479-
QDomNodeList featureIdList = insertResultList.at( i ).toElement().elementsByTagNameNS( "http://www.opengis.net/ogc", "FeatureId" );
1481+
QDomNodeList featureIdList = insertResultList.at( i ).toElement().elementsByTagNameNS( OGC_NAMESPACE, "FeatureId" );
14801482
for ( int j = 0; j < featureIdList.size(); ++j )
14811483
{
14821484
QString fidString = featureIdList.at( j ).toElement().attribute( "fid" );
@@ -1640,21 +1642,40 @@ QGis::WkbType QgsWFSProvider::geomTypeFromPropertyType( QString attName, QString
16401642
return ( QGis::WkbType ) i;
16411643
}
16421644

1643-
void QgsWFSProvider::handleException( const QDomDocument& serverResponse ) const
1645+
void QgsWFSProvider::handleException( const QDomDocument& serverResponse )
16441646
{
1647+
QgsDebugMsg( QString( "server response: %1" ).arg( serverResponse.toString() ) );
1648+
16451649
QDomElement exceptionElem = serverResponse.documentElement();
1646-
if ( exceptionElem.isNull() || exceptionElem.tagName() != "ServiceExceptionReport" )
1650+
if ( exceptionElem.isNull() )
1651+
{
1652+
pushError( QObject::tr( "empty response" ).arg( exceptionElem.tagName() ) );
1653+
return;
1654+
}
1655+
1656+
if ( exceptionElem.tagName() == "ServiceExceptionReport" )
16471657
{
1658+
pushError( QObject::tr( "WFS service exception:%1" ).arg( exceptionElem.firstChildElement( "ServiceException" ).text() ) );
16481659
return;
16491660
}
16501661

1651-
//possibly this class is used not in a gui application
1652-
if ( QApplication::topLevelWidgets().size() < 1 )
1662+
if ( exceptionElem.tagName() == "WFS_TransactionResponse" )
16531663
{
1664+
pushError( QObject::tr( "unsuccessful service response: %1" ).arg( exceptionElem.firstChildElement( "TransactionResult" ).firstChildElement( "Message" ).text() ) );
16541665
return;
16551666
}
1656-
QString message = exceptionElem.firstChildElement( "ServiceException" ).text();
1657-
QMessageBox::critical( 0, tr( "Error" ), message );
1667+
1668+
if ( exceptionElem.tagName() == "ExceptionReport" )
1669+
{
1670+
QDomElement exception = exceptionElem.firstChildElement( "Exception" );
1671+
pushError( QObject::tr( "WFS exception report (code=%1 text=%2)" )
1672+
.arg( exception.attribute( "exceptionCode", QObject::tr( "missing" ) ) )
1673+
.arg( exception.firstChildElement( "ExceptionText" ).text() )
1674+
);
1675+
return;
1676+
}
1677+
1678+
pushError( QObject::tr( "unhandled response: %1" ).arg( exceptionElem.tagName() ) );
16581679
}
16591680

16601681
QGISEXTERN QgsWFSProvider* classFactory( const QString *uri )

‎src/providers/wfs/qgswfsprovider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ class QgsWFSProvider: public QgsVectorDataProvider
232232
void getLayerCapabilities();
233233
/**Takes <Operations> element and updates the capabilities*/
234234
void appendSupportedOperations( const QDomElement& operationsElem, int& capabilities ) const;
235-
/**Shows a message box with the exception string (or does nothing if the xml document is not an exception)*/
236-
void handleException( const QDomDocument& serverResponse ) const;
235+
/**records provider error*/
236+
void handleException( const QDomDocument& serverResponse );
237237
/**Initializes "Cache Features" inactive processing*/
238238
bool initGetRenderedOnly( QgsRectangle );
239239
/**Converts DescribeFeatureType schema geometry property type to WKBType*/

0 commit comments

Comments
 (0)
Please sign in to comment.