WFS 2.0 leniency for OGC filter

Hi,

I had some problems with a WFS request giving weird responses and log messages. Ultimately I realized that the troubles were caused by me using WFS 2.0.0 while having a filter with the OGC namespace.

    <ogc:Filter>
        <ogc:PropertyIsEqualTo>
            <ogc:PropertyName>nummer</ogc:PropertyName>
            <ogc:Literal>56</ogc:Literal>
        </ogc:PropertyIsEqualTo>
    </ogc:Filter>

In WFS 2.0 we should use the FES filter which would look like:

    <fes:Filter>
        <fes:PropertyIsEqualTo>
            <fes:ValueReference>nummer</fes:ValueReference>
            <fes:Literal>56</fes:Literal>
        </fes:PropertyIsEqualTo>
    </fes:Filter>

I also know that Geoserver tries to be lenient by the user input, and in this case I certainly would hope / suppose that both versions would be acceptable. That is simply not the case. The first request will give this response:

<ows:Exception exceptionCode=“OperationParsingFailed”>
ows:ExceptionTextRequest parsing failed
Parsing failed for PropertyIsEqualTo: java.lang.ClassCastException: class java.lang.String cannot be cast to class org.geotools.api.filter.expression.Expression (java.lang.String is in module java.base of loader &apos;bootstrap&apos;; org.geotools.api.filter.expression.Expression is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @24d09c1)
class java.lang.String cannot be cast to class org.geotools.api.filter.expression.Expression (java.lang.String is in module java.base of loader &apos;bootstrap&apos;; org.geotools.api.filter.expression.Expression is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @24d09c1)</ows:ExceptionText>
</ows:Exception>

Not very user friendly.

I have found some clues why this gets so wrong, but I wonder how far we want to go when it comes to leniency and user friendliness.

Best regards,
Roar Brænden

Hi Roar,
both of the filters you shared can be valid, it all depends on what the prefix “ogc” and “fes” are bound to at the top of the request…
Here are some examples.

Valid:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs/2.0" 
                xmlns:fes="http://www.opengis.net/fes/2.0" 
                xmlns:sf="http://www.openplans.org/spearfish" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="2.0.0">
  <wfs:Query typeNames="sf:bugsites">
    <fes:Filter>
      <fes:PropertyIsEqualTo>
        <fes:ValueReference>nummer</fes:ValueReference>
        <fes:Literal>56</fes:Literal>
      </fes:PropertyIsEqualTo>
    </fes:Filter>
  </wfs:Query>
</wfs:GetFeature>

Also valid:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs/2.0" 
                xmlns:ogc="http://www.opengis.net/fes/2.0" 
                xmlns:sf="http://www.openplans.org/spearfish" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="2.0.0">
  <wfs:Query typeNames="sf:bugsites">
    <ogc:Filter>
      <ogc:PropertyIsEqualTo>
        <ogc:ValueReference>nummer</ogc:ValueReference>
        <ogc:Literal>56</ogc:Literal>
      </ogc:PropertyIsEqualTo>
    </ogc:Filter>
  </wfs:Query>
</wfs:GetFeature>

Surprise surprise, valid too:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs/2.0" 
                xmlns:mickeyMouse="http://www.opengis.net/fes/2.0" 
                xmlns:sf="http://www.openplans.org/spearfish" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="2.0.0">
  <wfs:Query typeNames="sf:bugsites">
    <mickeyMouse:Filter>
      <mickeyMouse:PropertyIsEqualTo>
        <mickeyMouse:ValueReference>nummer</mickeyMouse:ValueReference>
        <mickeyMouse:Literal>56</mickeyMouse:Literal>
      </mickeyMouse:PropertyIsEqualTo>
    </mickeyMouse:Filter>
  </wfs:Query>
</wfs:GetFeature>

In a properly setup XML document the element prefix is completely irrelevant, what matters is what namespace you bind it to… that has to be “http://www.opengis.net/fes/2.0” for a WFS 2.0 request to be valid.

This is something so basic at the XML level, that I’m hesitant being lenient towards it. Gut feeling, I’d be strongly opposed to it, but I also see most don’t realize that prefixes are just shorthands for namespaces, so if other core developers feel like being lenient, I’ll be ok with it.

Cheers
Andrea

Hi,
Sorry for not sharing the namespaces. Those would have been:

fes=http://www.opengis.net/fes/2.0
ogc=http://www.opengis.net/ogc

The real question was whether we should allow old ogc filters in a wfs 2.0 request. You did answer that question as you say:
that has to be “http://www.opengis.net/fes/2.0” for a WFS 2.0 request to be valid.

So we shouldn’t allow using old OGC filter in WFS 2.0 requests. Then I might look at how to improve that error message.

Best Roar