Skip to content

Commit 7c4acb2

Browse files
author
jef
committed
show wms get capabilities error
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14003 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 41780e9 commit 7c4acb2

File tree

6 files changed

+96
-49
lines changed

6 files changed

+96
-49
lines changed

python/core/qgsrasterdataprovider.sip

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
* QgsVectorDataProvider, and does not yet make
66
* sense for Raster layers.
77
*/
8-
8+
99
class QgsRasterDataProvider : QgsDataProvider
1010
{
11-
%TypeHeaderCode
11+
% TypeHeaderCode
1212
#include <qgsrasterdataprovider.h>
13-
%End
13+
% End
1414

15-
public:
15+
public:
1616

1717
//! If you add to this, please also add to capabilitiesString()
1818
enum Capability
@@ -32,8 +32,8 @@ public:
3232
/**
3333
* Add the list of WMS layer names to be rendered by this server
3434
*/
35-
virtual void addLayers(const QStringList & layers,
36-
const QStringList & styles = QStringList()) = 0;
35+
virtual void addLayers( const QStringList & layers,
36+
const QStringList & styles = QStringList() ) = 0;
3737

3838
//! get raster image encodings supported by (e.g.) the WMS Server, expressed as MIME types
3939
virtual QStringList supportedImageEncodings() = 0;
@@ -46,18 +46,18 @@ public:
4646
/**
4747
* Set the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server
4848
*/
49-
virtual void setImageEncoding(const QString & mimeType) = 0;
50-
49+
virtual void setImageEncoding( const QString & mimeType ) = 0;
50+
5151
/**
5252
* Set the image projection (in WMS CRS format) used in the transfer from (e.g.) the WMS server
5353
*/
54-
virtual void setImageCrs(const QString & crs) = 0;
54+
virtual void setImageCrs( const QString & crs ) = 0;
5555

5656

5757
// TODO: Document this better.
5858
/** \brief Renders the layer as an image
5959
*/
60-
virtual QImage* draw(const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight) = 0;
60+
virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0;
6161

6262
/** Returns a bitmask containing the supported capabilities
6363
Note, some capabilities may change depending on whether
@@ -73,9 +73,9 @@ public:
7373

7474

7575
// TODO: Get the supported formats by this provider
76-
76+
7777
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
78-
78+
7979

8080
/**
8181
* Get metadata in a format suitable for feeding directly
@@ -96,7 +96,7 @@ public:
9696
* \note The arbitraryness of the returned document is enforced by WMS standards
9797
* up to at least v1.3.0
9898
*/
99-
virtual QString identifyAsText(const QgsPoint& point) = 0;
99+
virtual QString identifyAsText( const QgsPoint& point ) = 0;
100100

101101
/**
102102
* \brief Identify details from a server (e.g. WMS) from the last screen update
@@ -113,7 +113,7 @@ public:
113113
*
114114
* \note added in 1.5
115115
*/
116-
virtual QString identifyAsHtml(const QgsPoint& point) = 0;
116+
virtual QString identifyAsHtml( const QgsPoint& point ) = 0;
117117

118118
/**
119119
* \brief Returns the caption error text for the last error in this provider
@@ -137,16 +137,19 @@ public:
137137
*/
138138
virtual QString lastError() = 0;
139139

140-
/**Returns the dpi of the output device.
140+
/**
141+
* \brief Returns the format of the error text for the last error in this provider
142+
*
143+
* \note added in 1.6
144+
*/
145+
virtual QString lastErrorFormat();
146+
147+
/**Returns the dpi of the output device.
141148
@note: this method was added in version 1.2*/
142149
int dpi();
143150

144151
/**Sets the output device resolution.
145152
@note: this method was added in version 1.2*/
146-
void setDpi(int dpi);
147-
148-
149-
protected:
150-
153+
void setDpi( int dpi );
151154
};
152155

src/app/qgswmssourceselect.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,29 +1021,25 @@ void QgsWMSSourceSelect::showStatusMessage( QString const &theMessage )
10211021

10221022
void QgsWMSSourceSelect::showError( QgsWmsProvider * wms )
10231023
{
1024-
#if 0
1025-
QMessageBox::warning(
1026-
this,
1027-
wms->lastErrorTitle(),
1028-
tr( "Could not understand the response. The %1 provider said:\n%2", "COMMENTED OUT" )
1029-
.arg( wms->name() ).arg( wms->lastError() )
1030-
);
1031-
#endif
1032-
10331024
QgsMessageViewer * mv = new QgsMessageViewer( this );
10341025
mv->setWindowTitle( wms->lastErrorTitle() );
1035-
mv->setMessageAsPlainText( tr( "Could not understand the response. The %1 provider said:\n%2" )
1036-
.arg( wms->name() ).arg( wms->lastError() )
1037-
);
1026+
1027+
if ( wms->lastErrorFormat() == "text/html" )
1028+
{
1029+
mv->setMessageAsHtml( wms->lastError() );
1030+
}
1031+
else
1032+
{
1033+
mv->setMessageAsPlainText( tr( "Could not understand the response. The %1 provider said:\n%2" ).arg( wms->name() ).arg( wms->lastError() ) );
1034+
}
10381035
mv->showMessage( true ); // Is deleted when closed
10391036
}
10401037

10411038
void QgsWMSSourceSelect::on_cmbConnections_activated( int )
10421039
{
10431040
// Remember which server was selected.
10441041
QSettings settings;
1045-
settings.setValue( "/Qgis/connections-wms/selected",
1046-
cmbConnections->currentText() );
1042+
settings.setValue( "/Qgis/connections-wms/selected", cmbConnections->currentText() );
10471043
}
10481044

10491045
void QgsWMSSourceSelect::on_btnAddDefault_clicked()

src/core/qgsrasterdataprovider.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ QgsRasterDataProvider::QgsRasterDataProvider(): mDpi( -1 )
2525
{
2626
}
2727

28-
2928
QgsRasterDataProvider::QgsRasterDataProvider( QString const & uri )
30-
: QgsDataProvider( uri ), mDpi( -1 )
29+
: QgsDataProvider( uri )
30+
, mDpi( -1 )
3131
{
3232
}
3333

34-
3534
QString QgsRasterDataProvider::capabilitiesString() const
3635
{
3736
QStringList abilitiesList;
@@ -53,4 +52,9 @@ bool QgsRasterDataProvider::identify( const QgsPoint& thePoint, QMap<QString, QS
5352
return false;
5453
}
5554

55+
QString QgsRasterDataProvider::lastErrorFormat()
56+
{
57+
return "text/plain";
58+
}
59+
5660
// ENDS

src/core/qgsrasterdataprovider.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
172172
*/
173173
virtual QString lastError() = 0;
174174

175+
/**
176+
* \brief Returns the format of the error text for the last error in this provider
177+
*
178+
* \note added in 1.6
179+
*/
180+
virtual QString lastErrorFormat();
181+
182+
175183
/**Returns the dpi of the output device.
176184
@note: this method was added in version 1.2*/
177185
int dpi() const {return mDpi;}

src/providers/wms/qgswmsprovider.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ void QgsWmsProvider::tileReplyFinished()
727727
if ( !status.isNull() && status.toInt() >= 400 )
728728
{
729729
QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
730+
mErrorFormat = "text/plain";
730731
mError = tr( "tile request err %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
731732
emit statusChanged( mError );
732733

@@ -808,6 +809,7 @@ void QgsWmsProvider::cacheReplyFinished()
808809
if ( !status.isNull() && status.toInt() >= 400 )
809810
{
810811
QVariant phrase = cacheReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
812+
mErrorFormat = "text/plain";
811813
mError = tr( "map request error %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
812814
emit statusChanged( mError );
813815

@@ -865,7 +867,16 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
865867

866868
if ( httpcapabilitiesresponse.isEmpty() )
867869
{
868-
QgsDebugMsg( "empty capabilities: " + mError );
870+
mErrorFormat = "text/plain";
871+
mError = tr( "empty capabilities document" );
872+
return false;
873+
}
874+
875+
if ( httpcapabilitiesresponse.startsWith( "<html>" ) ||
876+
httpcapabilitiesresponse.startsWith( "<HTML>" ) )
877+
{
878+
mErrorFormat = "text/html";
879+
mError = httpcapabilitiesresponse;
869880
return false;
870881
}
871882

@@ -919,11 +930,13 @@ void QgsWmsProvider::capabilitiesReplyFinished()
919930

920931
if ( httpcapabilitiesresponse.isEmpty() )
921932
{
933+
mErrorFormat = "text/plain";
922934
mError = tr( "empty of capabilities: %1" ).arg( mCapabilitiesReply->errorString() );
923935
}
924936
}
925937
else
926938
{
939+
mErrorFormat = "text/plain";
927940
mError = tr( "Download of capabilities failed: %1" ).arg( mCapabilitiesReply->errorString() );
928941
QgsDebugMsg( "error: " + mError );
929942
httpcapabilitiesresponse.clear();
@@ -966,9 +979,12 @@ bool QgsWmsProvider::parseCapabilitiesDom( QByteArray const &xml, QgsWmsCapabili
966979
if ( !contentSuccess )
967980
{
968981
mErrorCaption = tr( "Dom Exception" );
969-
mError = tr( "Could not get WMS capabilities: %1 at line %2 column %3\n" )
970-
.arg( errorMsg ).arg( errorLine ).arg( errorColumn )
971-
+ tr( "This is probably due to an incorrect WMS Server URL." );
982+
mErrorFormat = "text/plain";
983+
mError = tr( "Could not get WMS capabilities: %1 at line %2 column %3\nThis is probably due to an incorrect WMS Server URL.\nResponse was:\n\n%4" )
984+
.arg( errorMsg )
985+
.arg( errorLine )
986+
.arg( errorColumn )
987+
.arg( QString( xml ) );
972988

973989
QgsLogger::debug( "Dom Exception: " + mError );
974990

@@ -986,10 +1002,12 @@ bool QgsWmsProvider::parseCapabilitiesDom( QByteArray const &xml, QgsWmsCapabili
9861002
)
9871003
{
9881004
mErrorCaption = tr( "Dom Exception" );
989-
mError = tr( "Could not get WMS capabilities in the "
990-
"expected format (DTD): no %1 or %2 found\n" )
991-
.arg( "WMS_Capabilities" ).arg( "WMT_MS_Capabilities" )
992-
+ tr( "This is probably due to an incorrect WMS Server URL." );
1005+
mErrorFormat = "text/plain";
1006+
mError = tr( "Could not get WMS capabilities in the expected format (DTD): no %1 or %2 found.\nThis might be due to an incorrect WMS Server URL.\nTag:%3\nResponse was:\n%4" )
1007+
.arg( "WMS_Capabilities" )
1008+
.arg( "WMT_MS_Capabilities" )
1009+
.arg( docElem.tagName() )
1010+
.arg( QString( xml ) );
9931011

9941012
QgsLogger::debug( "Dom Exception: " + mError );
9951013

@@ -1825,11 +1843,13 @@ bool QgsWmsProvider::parseServiceExceptionReportDom( QByteArray const & xml )
18251843
if ( !contentSuccess )
18261844
{
18271845
mErrorCaption = tr( "Dom Exception" );
1828-
mError = tr( "Could not get WMS Service Exception at %1: %2 at line %3 column %4" )
1846+
mErrorFormat = "text/plain";
1847+
mError = tr( "Could not get WMS Service Exception at %1: %2 at line %3 column %4\n\nResponse was:\n\n%4" )
18291848
.arg( mBaseUrl )
18301849
.arg( errorMsg )
18311850
.arg( errorLine )
1832-
.arg( errorColumn );
1851+
.arg( errorColumn )
1852+
.arg( QString( xml ) );
18331853

18341854
QgsLogger::debug( "Dom Exception: " + mError );
18351855

@@ -1875,10 +1895,12 @@ void QgsWmsProvider::parseServiceException( QDomElement const & e )
18751895
QString seCode = e.attribute( "code" );
18761896
QString seText = e.text();
18771897

1898+
mErrorFormat = "text/plain";
1899+
18781900
// set up friendly descriptions for the service exception
18791901
if ( seCode == "InvalidFormat" )
18801902
{
1881-
mError = tr( "Request contains a Format not offered by the server." );
1903+
mError = tr( "Request contains a format not offered by the server." );
18821904
}
18831905
else if ( seCode == "InvalidCRS" )
18841906
{
@@ -2744,6 +2766,7 @@ void QgsWmsProvider::identifyReplyFinished()
27442766
if ( !status.isNull() && status.toInt() >= 400 )
27452767
{
27462768
QVariant phrase = mIdentifyReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
2769+
mErrorFormat = "text/plain";
27472770
mError = tr( "map request error %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
27482771
emit statusChanged( mError );
27492772

@@ -2781,6 +2804,10 @@ QString QgsWmsProvider::lastError()
27812804
return mError;
27822805
}
27832806

2807+
QString QgsWmsProvider::lastErrorFormat()
2808+
{
2809+
return mErrorFormat;
2810+
}
27842811

27852812
QString QgsWmsProvider::name() const
27862813
{

src/providers/wms/qgswmsprovider.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,13 @@ class QgsWmsProvider : public QgsRasterDataProvider
579579
* Interactive users of this provider can then, for example,
580580
* call a QMessageBox to display the contents.
581581
*/
582-
583582
QString lastError();
584583

584+
/**
585+
* \brief Returns the format of the error message (text or html)
586+
*/
587+
QString lastErrorFormat();
588+
585589
/** return a provider name
586590
587591
Essentially just returns the provider key. Should be used to build file
@@ -884,6 +888,11 @@ class QgsWmsProvider : public QgsRasterDataProvider
884888
*/
885889
QString mError;
886890

891+
892+
/** The mime type of the message
893+
*/
894+
QString mErrorFormat;
895+
887896
//! A QgsCoordinateTransform is used for transformation of WMS layer extents
888897
QgsCoordinateTransform *mCoordinateTransform;
889898

0 commit comments

Comments
 (0)