[Geoserver-devel] Accessing all query parameters in SLD - env function

Hi List,

I am currently trying to specify an external graphic in my SLD using variables - making it dynamic.

<OnlineResource xlink:type=“simple” xlink:href=“https://mydomain.com/get/${grid_id}/${env(time)}/2007-12-31T23:00:00.000Z/10.svg” />

The idea is to make use of URL parameters. I have a time enabled WMS, thus the “TIME” parameter is contained in the URL.

I want to access the time parameter and add it to my URL. Problem is, that only 5 predefined query parameters / calculations can be used in SLD as described in the variable substitution documentation via the env function (e.g. “wms_bbox”). Besides, using the env function in the “xlink:href” attribute of the external graphic seems to be unsupported or broken, as GeoServer tries to find the given env attribute on the layer, which obviously does not exist, and fails with:

"The requested Style can not be used with this layer.  The style specifies an attribute named 'time', not found in the topp:test layer".

So i would like to accomplish two things and ask for your opinions:

  * Allow adding all query params to the RenderingVariables class (src/main/java/org/geoserver/wms/RenderingVariables.java) or at least some obviously missing ones like time
  * Get the env function working in this specific place

Any opinions / objections on this? Maybe security is an issue when simply adding all query parameters to the rendering variables.

Greetings,
Johannes

Hi,

By searching through the users mailinglist i found the solution to the problem described below, where the env-function behaves strange.

I enhanced the documentation to help others having the same issue via this PR: https://github.com/geoserver/geoserver/pull/5277

I am still interested in your opinions regarding acces to any query parameter through the env function.

Possible addition in RenderingVariables.class:

Map<String, String> kvp = mapContent.getRequest().getRawKvp();
kvp.keySet()
        .forEach(
                k -> {
                    EnvFunction.setLocalValue(k, kvp.get(k));
                });

Greets,

Johannes

···

Am 07.09.21 um 13:29 schrieb Johannes Weskamm:

Hi List,

I am currently trying to specify an external graphic in my SLD using variables - making it dynamic.

<OnlineResource xlink:type=“simple” xlink:href=“https://mydomain.com/get/${grid_id}/${env(time)}/2007-12-31T23:00:00.000Z/10.svg” />

The idea is to make use of URL parameters. I have a time enabled WMS, thus the “TIME” parameter is contained in the URL.

I want to access the time parameter and add it to my URL. Problem is, that only 5 predefined query parameters / calculations can be used in SLD as described in the variable substitution documentation via the env function (e.g. “wms_bbox”). Besides, using the env function in the “xlink:href” attribute of the external graphic seems to be unsupported or broken, as GeoServer tries to find the given env attribute on the layer, which obviously does not exist, and fails with:

"The requested Style can not be used with this layer.  The style specifies an attribute named 'time', not found in the topp:test layer".

So i would like to accomplish two things and ask for your opinions:

  * Allow adding all query params to the RenderingVariables class (src/main/java/org/geoserver/wms/RenderingVariables.java) or at least some obviously missing ones like time
  * Get the env function working in this specific place

Any opinions / objections on this? Maybe security is an issue when simply adding all query parameters to the rendering variables.

Greetings,
Johannes

_______________________________________________
Geoserver-devel mailing list
[Geoserver-devel@lists.sourceforge.net](mailto:Geoserver-devel@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-devel](https://lists.sourceforge.net/lists/listinfo/geoserver-devel)


Hi Johannes,
this approach would work, but mind it has limitations that should be clearly explained in the docs:

  • The parameters in the map could overwrite the ones already existing because anyone can put anything in the request. This could lead to odd situations with rendering transformations. Best to add the existing ones after collecting the KVP params.
  • WMS request can be done also via POST XML, in this case, the raw KVP would be empty. It’s not very common, but it is possible, styles relying on KVP param access will break in those cases.
    About the support for href being broken… maybe it is not. When you write time without quoting it, it’s an attribute name, not a string. Try using env(‘time’) instead.

Cheers

Andrea

···

Regards,

Andrea Aime

==
GeoServer Professional Services from the experts!

Visit http://bit.ly/gs-services-us for more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions Group
phone: +39 0584 962313

fax: +39 0584 1660272

mob: +39 333 8128928

https://www.geosolutionsgroup.com/

http://twitter.com/geosolutions_it


Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.

This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail