GeoServer WFS-T – Resolving Missing Schema Element Declarations in WFS Insert Transaction

geoserverwfswfs-t

I am attempting to post the following xml through geoserver to make a WFS insert:

<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs/2.0" service="WFS" version="2.0.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:my_db="http://localhost:8080/geoserver/schemas/my_db" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd http://localhost:8080/geoserver/schemas/my_db http://localhost:8080/geoserver/wfs/DescribeFeatureType?typename=test_db:avoidance_points" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <wfs:Insert>
    <my_db:avoidance_points>
      <my_db:weight>2</my_db:weight>
    </my_db:avoidance_points>
  </wfs:Insert>
</wfs:Transaction>

The schema at the specified url ([…]/wfs/DescribeFeatureType?[…]) is as follows, and the relevant store is backed by a postgis database.

<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:test_db="test_db" xmlns:wfs="http://www.opengis.net/wfs/2.0" elementFormDefault="qualified" targetNamespace="test_db">
  <xsd:import namespace="http://www.opengis.net/gml/3.2" schemaLocation="http://192.168.1.19:8080/geoserver/schemas/gml/3.2.1/gml.xsd"/>
  <xsd:complexType name="avoidance_pointsType">
    <xsd:complexContent>
      <xsd:extension base="gml:AbstractFeatureType">
        <xsd:sequence>
          <xsd:element maxOccurs="1" minOccurs="0" name="geom" nillable="true" type="gml:PointPropertyType"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="distance" nillable="true" type="xsd:int"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="weight" nillable="true" type="xsd:int"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="avoidance_points" substitutionGroup="gml:AbstractFeature" type="test_db:avoidance_pointsType"/>
</xsd:schema>

This results in no insertions. I am aware that, as I'm attempting to simplify the problem as much as possible for debugging, I am not specifying all values within the schema (geom, distance), but neither of these are set to 'not null', so I don't expect that this is my underlying issue.

After putting geoserver into verbose logging, the following appears in the log:

2022-02-19 04:13:53,885 DEBUG [geoserver.requests] - First 4 bytes of XML doc are : 3C ('<') 3F ('?') 78 ('x') 6D ('m')
2022-02-19 04:13:53,885 DEBUG [geoserver.requests] - Charset detection phase 1. Inferred encoding: UTF-8
2022-02-19 04:13:53,885 DEBUG [geoserver.requests] - Charset detection phase 2. Charset in XML declaration is `null`.
2022-02-19 04:13:53,885 DEBUG [geoserver.ows] - Raw XML request: <?xml version="1.0"?>
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs/2.0" service="WFS" version="2.0.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:my_db="http://localhost:8080/geoserver/schemas/my_db" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd http://localhost:8080/geoserver/schemas/my_db http://localhost:8080/geoserver/wfs/DescribeFeatureType?typename=test_db:avoidance_points" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <wfs:Insert>
    <my_db:avoidance_points>
      <my_db:weight>2</my_db:weight>
    </my_db:avoidance_points>
  </wfs:Insert>
</wfs:Transaction>
2022-02-19 04:13:53,886 INFO [geoserver.wfs] -
Request: getServiceInfo
2022-02-19 04:13:53,887 DEBUG [xsd.impl] - schemaLocation found: http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd http://localhost:8080/geoserver/schemas/my_db http://localhost:8080/geoserver/wfs/DescribeFeatureType?typename=test_db:avoidance_points
2022-02-19 04:13:53,888 DEBUG [xsd.impl] - Found override for http://www.opengis.net/wfs/2.0: http://schemas.opengis.net/wfs/2.0/wfs.xsd ==> jar:file:/home/pjablonski/geoserver/webapps/geoserver/WEB-INF/lib/gt-xsd-wfs-26.2.jar!/org/geotools/wfs/v2_0/wfs.xsd
2022-02-19 04:13:53,889 DEBUG [xsd.impl] - Found override for http://www.opengis.net/gml/3.2: http://schemas.opengis.net/gml/3.2.1/gml.xsd ==> jar:file:/home/pjablonski/geoserver/webapps/geoserver/WEB-INF/lib/gt-xsd-gml3-26.2.jar!/org/geotools/gml3/v3_2/gml.xsd
2022-02-19 04:13:53,889 DEBUG [wfs.xml] - Hostname localhost is in known aliases for self
2022-02-19 04:13:53,895 DEBUG [xsd.impl] - Could not find declaration for: {http://localhost:8080/geoserver/schemas/my_db}avoidance_points. Checking if containing type declares a single particle.
2022-02-19 04:13:53,895 DEBUG [xsd.impl] - Could not find declaration for: {http://localhost:8080/geoserver/schemas/my_db}avoidance_points. Performing lookup by ignoring namespace
2022-02-19 04:13:53,895 DEBUG [xsd.impl] - Could not find declaration for: {http://localhost:8080/geoserver/schemas/my_db}avoidance_points. Creating a mock element declaration and parsing anyways...
2022-02-19 04:13:53,896 DEBUG [xsd.impl] - Could not find declaration for: {http://localhost:8080/geoserver/schemas/my_db}weight. Checking if containing type declares a single particle.
2022-02-19 04:13:53,896 DEBUG [xsd.impl] - Could not find declaration for: {http://localhost:8080/geoserver/schemas/my_db}weight. Performing lookup by ignoring namespace
2022-02-19 04:13:53,896 DEBUG [xsd.impl] - Could not find declaration for: {http://localhost:8080/geoserver/schemas/my_db}weight. Creating a mock element declaration and parsing anyways...
2022-02-19 04:13:53,897 DEBUG [geoserver.wfs] - Insert was empty - does not need a FeatureSource
2022-02-19 04:13:53,897 INFO [geoserver.wfs] -
Request: transaction
    service = WFS
    version = 2.0.0
    baseUrl = http://localhost:8080/geoserver/
    group[0] = wfs:abstractTransactionAction=net.opengis.wfs20.impl.InsertTypeImpl@411828cc (handle: null) (any: [], inputFormat: <unset>, srsName: null)
    abstractTransactionActionGroup[0] = wfs:abstractTransactionAction=net.opengis.wfs20.impl.InsertTypeImpl@411828cc (handle: null) (any: [], inputFormat: <unset>, srsName: null)
    abstractTransactionAction[0]:
        inputFormat = application/gml+xml; version=3.2
    releaseAction = ALL
2022-02-19 04:13:53,899 DEBUG [geoserver.filters] - Compressing output for mimetype: text/xml
2022-02-19 04:13:53,899 DEBUG [filter.GeoServerSecurityContextPersistenceFilter$1] - SecurityContextHolder now cleared, as request processing completed
2022-02-19 04:13:57,877 TRACE [platform.resource] - polling contents of /home/pjablonski/geoserver/data_dir/gwc-layers
2022-02-19 04:13:57,877 TRACE [platform.resource] - delta computed in 319us for /home/pjablonski/geoserver/data_dir/gwc-layers

My interpretation of this is that somehow, geoserver is failing to load my my_db namespace. How can I fix this?

Best Answer

Your features are in the test_db namespace not the my_db which is why the lookup of the schema fails.

See:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml/3.2"
  xmlns:test_db="test_db" xmlns:wfs="http://www.opengis.net/wfs/2.0"                        elementFormDefault="qualified" targetNamespace="test_db">
Related Question