Search code examples
postgisgeoserver

Geoserver to PostGIS - line breaks working when inserting but not updating


I've been using geoserver along with a PostGIS database to display, add and update markers in Openlayers.
I need one of the feature properties to be a text with multiple line and respecting line breaks.

Inserting works great but when I try to update an existing feature, the updating process seems to remove line breaks.

The problem seems to come from Geoserver and not Openlayers or PostGIS.
To demonstrate that Geoserver recieves a correct transaction, here is an example WFS transaction sent to geoserver by my Openlayers implementation :

<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0">
<Update typeName="namespace:layername" xmlns:feature="https://www.example.com/geoserver/namespace">
<Property><Name>nom</Name><Value>TestName</Value></Property>
<Property><Name>description</Name><Value>First line

One line break




Multiple line breaks</Value></Property>

<Filter xmlns="http://www.opengis.net/ogc"><FeatureId fid="236"/>/Filter>
</Update>
</Transaction>

As you can see, Geoserver recognizes the line breaks in <description> naturally. All is well.

However, when it's time to update the database, Geoserver sends a query to PostGIS without the line breaks, like so :

Request: transaction
    service = WFS
    version = 1.1.0
    baseUrl = http://localhost:8080/geoserver/
    group[0] = wfs:update=net.opengis.wfs.impl.UpdateElementTypeImpl@5b3cc21a (filter: [ 236 ], handle: null, inputFormat: <unset>, srsName: null, typeName: {https://www.example.com/geoserver/namespace}layername)
    update[0]:
        property[0]:
            name = name
            value = TestNameproperty[0]:
            name = description
            value = First line One line break Multiple line breaksproperty[0]:            
        filter = [ 236 ]
        inputFormat = x-application/gml:3
        typeName = {https://www.example.com/geoserver/namespace}layername
    releaseAction = ALL

What's strange is that, when inserting a new feature, geoserver correctly insert line breaks into the PostGIS query ! It's only when updating that it removes line breaks.

Is that an actual Geoserver bug or am I doing something wrong ?

The postgis column for the <description> property is of the "character varying" type. Dunno if it is relevant.

PS : I had to edit out a few lines with URLs in the transaction because my question was flagged as spam...


Solution

  • XML will eat all but one of the white space characters when they are parsed. To avoid this you need to hide them inside a CDATA block.

    No idea why inserts would work though.