geosolutions-it / MapStore2

The solution to create and share maps, dashboards, geostories with 3D support on the web. And it is open-source too!
https://mapstore.geosolutionsgroup.com/
Other
513 stars 401 forks source link

Error downloading filtered dataset, where filter is based on another layer #8603

Closed DavidQuartz closed 2 years ago

DavidQuartz commented 2 years ago

Description

Downloading filtered layer data for a layer which was filtered based on another layer does not work.

How to reproduce

Expected Result

The layer data is downloaded

Current Result

An error is thrown

Screenshot 2022-09-22 at 08 50 52
Browser info (use this site: https://www.whatsmybrowser.org/ for non expert users) | Browser Affected | Version | |---|---| |Internet Explorer| | |Edge| | |Chrome| | |Firefox| | |Safari| |

Other useful information

You may test with this map. It already contains a filtered dataset (Colorado Populated Places). From the network tab, this error is thrown

<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 https://development.demo.geonode.org/geoserver/schemas/ows/1.1.0/owsAll.xsd">
<ows:Exception exceptionCode="NoApplicableCode">
    <ows:ExceptionText>
        Could not parse XML request.
        The element type "wps:ComplexData" must be terminated by the matching end-tag "</wps:ComplexData>".
    </ows:ExceptionText>
</ows:Exception>
DavidQuartz commented 2 years ago

@tdipisa @giohappy I find that the issue stems from how the filter is being parsed here Such filter data seems to already contain come CDATA, and so wrapping it in CDATA breaks the xml syntax. A proposed solution would be limit the cdata function to only wrap data which does not already include cdata.

allyoucanmap commented 2 years ago

@DavidQuartz could you please make a comment with the old broken xml payload and the new one?

DavidQuartz commented 2 years ago

@allyoucanmap Here is an example of an old broken xml payload

<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.opengis.net/wps/1.0.0"
    xmlns:wfs="http://www.opengis.net/wfs"
    xmlns:wps="http://www.opengis.net/wps/1.0.0"
    xmlns:ows="http://www.opengis.net/ows/1.1"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:wcs="http://www.opengis.net/wcs/1.1.1"
    xmlns:dwn="http://geoserver.org/wps/download"
    xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
    <ows:Identifier>gs:DownloadEstimator</ows:Identifier>
    <wps:DataInputs>
        <wps:Input>
            <ows:Identifier>layerName</ows:Identifier>
            <wps:Data>
                <wps:LiteralData>geonode:ProvCM01012019_g_WGS84_lKHiGZ3</wps:LiteralData>
            </wps:Data>
        </wps:Input>
        <wps:Input>
            <ows:Identifier>filter</ows:Identifier>
            <wps:Data>
                <wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
                    <![CDATA[<ogc:Filter
                    xmlns:ogc="http://www.opengis.net/ogc"
                    xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:Intersects><ogc:PropertyName>the_geom</ogc:PropertyName><ogc:Function name="collectGeometries"><ogc:Function name="queryCollection"><ogc:Literal>geonode:test_export_filter0</ogc:Literal><ogc:Literal>the_geom</ogc:Literal><ogc:Literal>
                    <![CDATA[INCLUDE]]>
                </ogc:Literal>
            </ogc:Function>
        </ogc:Function>
    </ogc:Intersects>
</ogc:And></ogc:Filter>]]>undefined</wps:ComplexData>undefined</wps:Data>undefined</wps:Input>undefined</wps:DataInputs>undefined</wps:Execute>

And here is the fixed version of it

<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.opengis.net/wps/1.0.0"
    xmlns:wfs="http://www.opengis.net/wfs"
    xmlns:wps="http://www.opengis.net/wps/1.0.0"
    xmlns:ows="http://www.opengis.net/ows/1.1"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:wcs="http://www.opengis.net/wcs/1.1.1"
    xmlns:dwn="http://geoserver.org/wps/download"
    xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
    <ows:Identifier>gs:DownloadEstimator</ows:Identifier>
    <wps:DataInputs>
        <wps:Input>
            <ows:Identifier>layerName</ows:Identifier>
            <wps:Data>
                <wps:LiteralData>geonode:ProvCM01012019_g_WGS84_lKHiGZ3</wps:LiteralData>
            </wps:Data>
        </wps:Input>
        <wps:Input>
            <ows:Identifier>filter</ows:Identifier>
            <wps:Data>
                <wps:ComplexData mimeType="text/xml; subtype=filter/1.1">
                    <ogc:Filter
                        xmlns:ogc="http://www.opengis.net/ogc"
                        xmlns:gml="http://www.opengis.net/gml">
                        <ogc:And>
                            <ogc:Intersects>
                                <ogc:PropertyName>the_geom</ogc:PropertyName>
                                <ogc:Function name="collectGeometries">
                                    <ogc:Function name="queryCollection">
                                        <ogc:Literal>geonode:test_export_filter0</ogc:Literal>
                                        <ogc:Literal>the_geom</ogc:Literal>
                                        <ogc:Literal>
                                            <![CDATA[INCLUDE]]>
                                        </ogc:Literal>
                                    </ogc:Function>
                                </ogc:Function>
                            </ogc:Intersects>
                        </ogc:And>
                    </ogc:Filter>
                </wps:ComplexData>
            </wps:Data>
        </wps:Input>
    </wps:DataInputs>
</wps:Execute>