[GIS] OpenLayers 3.5 WFS-T update to GeoServer 2.7 raises StringIndexOutOfBoundsException

geoserverhtmljavascriptopenlayerswfs-t

I am using ol.format.WFS.writeTransaction() (OL3.5) to generate WFS-T statements. This works well for insert and delete. The problem is with the update statement.

Any update statement returns following exception from GeoServer:

<ows:Exception exceptionCode="NoApplicableCode">
<ows:ExceptionText>java.lang.StringIndexOutOfBoundsException: String index out of range: -1 String index out of range: -1</ows:ExceptionText>
</ows:Exception>

Edits via QGIS work as expected.

This is an example POST generated by OL3.5

<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Update typeName="feature:playa_poly_noattribute" xmlns:feature="http://argeomatica.com">
    <Property>
      <Name>boundedBy</Name>
      <Value>-9693316.43121855,2347365.748407976,-9692555.877885746,2347961.5151853375</Value>
    </Property>
    <Property>
      <Name>geometry</Name>
      <Value>
        <Polygon xmlns="http://www.opengis.net/gml">
          <exterior>
            <LinearRing>
              <posList>-9693072.420357607 2347961.5151853375 -9693316.43121855 2347628.7731022364 -9692822.071552228 2347365.748407976 -9692555.877885746 2347758.700963257 -9692555.877885746 2347758.700963257 -9692737.951605482 2347825.076779921 -9692893.214319186 2347748.042587353 -9693072.420357607 2347961.5151853375</posList>
            </LinearRing>
          </exterior>
        </Polygon>
      </Value>
   </Property>
   <Filter xmlns="http://www.opengis.net/ogc">
     <FeatureId fid="playa_poly_noattribute.1"></FeatureId>
   </Filter>
 </Update>
</Transaction>

Best Answer

This is because boundedBy / bbox is a property that OpenLayers creates when parsing the GML, it is not a real feature property. So when you update, you should clone the feature and get rid of it. Some example code:

// do a WFS transaction to update the geometry
var properties = feature.getProperties();
// get rid of bbox which is not a real property
delete properties.bbox;
var clone = new ol.Feature(properties);
clone.setId(fid);

If you need more example code, here is the code we use in the OpenGeo Suite SDK for WFS-T: https://github.com/boundlessgeo/suite/blob/master/sdk/src/main/resources/client/ol3-common/app/TransactionHandler.js#L105:L110

Related Question