-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bugfix][Server] Add WMS SLD parameter support #7859
Conversation
Hi @rldhont, There's currently a unit test for the SLD parameter ( Moreover, I saw you added a Thanks :). |
Hi @pblottiere,
|
2329f5d
to
f090730
Compare
Thanks for the explanation 👍 |
@pblottiere it's green! |
@@ -200,6 +205,107 @@ QgsRectangle QgsServerParameterDefinition::toRectangle( bool &ok ) const | |||
return extent; | |||
} | |||
|
|||
QByteArray QgsServerParameterDefinition::loadUrl( bool &ok ) const | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nyalldawson,
I'm not very familiar with the QgsNetworkAccessManager
class. Can you take a look on this method in particular to give me your opinion please?
Thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the design of server, but calling QCoreApplication::processEvents on the main thread is dangerous in app. I don't think that's an issue here as my understanding is that server does everything on the main thread?
There is a class QgsNetworkContentFetcher which handles the redirections etc for you, so it would be good to see that used to avoid duplicated code handling this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't use QgsNetworkContentFetcher
because I can't use connect
because QgsServerParameterDefinition
does not derived QObject.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nyall is right, it would avoid a lot of duplicated code.
Why is it not possible to just use QgsNetworkContentFetcher
in the same way as QgsLayoutItemHtml
(for example in the fetchHtml
method)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has explain, QgsServerParameterDefinition
is not derived from QObject
so it's not possible to use connect
in this context. So I can't do like QgsLayoutItemHtml
connect( mFetcher, &QgsNetworkContentFetcher::finished, &loop, [&loaded, &loop ] { loaded = true; loop.quit(); } );
If you have an idea, how I can use QgsNetworkContentFetcher
I'm interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you call QObject:: connect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nyalldawson it's done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pblottiere done ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, it's much better this way. Thanks @rldhont :)
QByteArray ba = mWmsParameters[ QgsWmsParameter::SLD ].loadUrl(); | ||
if ( !ba.isEmpty() ) | ||
{ | ||
const QString sldBody = QString::fromStdString( ba.toStdString() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rldhont Do you think that the string conversion could be hidden in the loadUrl()
method?
@@ -364,7 +381,7 @@ namespace QgsWms | |||
* Returns SLD if defined or an empty string. | |||
* \returns sld | |||
*/ | |||
QString sld() const; | |||
QString sldBody() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the documentation accordingly?
Hi @rldhont, Apart from some minor comments, I just would like an opinion on the use of Otherwise, the code looks good! Thanks :) |
Thanks @pblottiere for the review |
@pblottiere done |
dc60cd7
to
e3352eb
Compare
src/server/qgsserverparameters.cpp
Outdated
|
||
// Do the request | ||
QNetworkReply *reply = nullptr; | ||
// The following code blocks until the file is downloaded... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some kind of timeout mechanism in this case (to avoid an infinite loop)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which duration ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pblottiere I have added a timeout mecahnism.
5e9fed0
to
e9d4442
Compare
src/server/qgsserverparameters.cpp
Outdated
QEventLoop loop; | ||
QObject::connect( &fetcher, &QgsNetworkContentFetcher::finished, &loop, &QEventLoop::quit ); | ||
|
||
QgsMessageLog::logMessage( QStringLiteral( "Request started [url: %1]" ).arg( url.toString() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering what happens here if the connection requires authentication ... unfortunately the current implementation of authmanager cannot automatically inject the authentication configuration based on a domain (and we probably don't want to do that without user confirmation or authentication configuration).
Not a blocker, but something that needs to be considered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pblottiere which class in the server is provided tr(...) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found ad done
src/server/qgsserverparameters.cpp
Outdated
if ( !reply ) | ||
{ | ||
ok = false; | ||
QgsMessageLog::logMessage( QStringLiteral( "Request failed [error: no reply - url: %1]" ).arg( url.toString() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(...)
src/server/qgsserverparameters.cpp
Outdated
ok = false; | ||
if ( reply->error() != QNetworkReply::NoError ) | ||
{ | ||
QgsMessageLog::logMessage( QStringLiteral( "Request failed [error: %1 - url: %2]" ).arg( reply->errorString(), reply->url().toString() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(...)
src/server/qgsserverparameters.cpp
Outdated
QgsMessageLog::logMessage( QStringLiteral( "Request failed [error: %1 - url: %2]" ).arg( reply->errorString(), reply->url().toString() ) ); | ||
} | ||
QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ); | ||
QgsMessageLog::logMessage( QStringLiteral( "Request error [status: %1 - reason phrase: %2] for %3" ).arg( status.toInt() ).arg( phrase.toString(), reply->url().toString() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(...)
src/server/qgsserverparameters.cpp
Outdated
if ( reply->error() != QNetworkReply::NoError ) | ||
{ | ||
ok = false; | ||
QgsMessageLog::logMessage( QStringLiteral( "Request failed [error: %1 - url: %2]" ).arg( reply->errorString(), reply->url().toString() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(...)
if ( !ok ) | ||
{ | ||
const QString msg = QString( "%1 request error for %2" ).arg( name( mName ), url.toString() ); | ||
QgsMessageLog::logMessage( msg ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message is also raised and be displayed in an OGC Exceptions. You wrote in #8006 discussion that messages in OGC Exceptions does not have to be localized.
I can removed the logMessage because QgsServerParameterDefinition already logs messages.
What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message is also raised and be displayed in an OGC Exceptions. You wrote in #8006 discussion that messages in OGC Exceptions does not have to be localized.
Indeed.
I can removed the logMessage because QgsServerParameterDefinition already logs messages.
What do you think ?
Indeed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done @pblottiere thanks!
Fixed qgis#19795 QGIS Server 3 / WMS: the SLD parameter support has been removed To reactivate SLD parameter support, we add a new conversion capability in server parameter `toUrl`. And the capabilty to load the content associted to an URL. Then if the SLD parameter is defined, the content is loaded and the SLD_BODY is set.
4ec5ee9
to
907c1a9
Compare
Description
Fixed #19795 QGIS Server 3 / WMS: the SLD parameter support has been removed https://issues.qgis.org/issues/19795
To reactivate SLD parameter support, we add a new conversion capability in server parameter
toUrl
. And the capabilty to load the content associted to an URL.Then if the SLD parameter is defined, the content is loaded and the SLD_BODY is set.
Checklist
fixes #11111
in the commit message next to the descriptionscripts/prepare-commit.sh
script before each commit