1

I need to load a WFS layer from GeoServer 2.8 to a web app using OpenLayers 4.6.5 and JQuery 2.2.3 so that I can use Select to highlight a feature on click. I can preview the line layer as a WMS with no problems in GeoServer, but when I try loading in the app, in the network response gives this error:

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

There are no errors in the console.

What could be causing this? The ajax call is below:

var layerWFS = new ol.layer.Vector({
source: new ol.source.Vector({
    loader: function (extent) {
        $.ajax('http://servername:8080/geoserver/wfs', {
            type: 'GET',
            data: {
                service: 'WFS',
                version: '1.1.0',
                request: 'GetFeature',
                typename: 'lines',
                srsname: 'EPSG:2263',
            }
        }).done(function (response) {
            layerWFS
            .getSource()
            .addFeatures(new ol.format.WFS()
            .readFeatures(response));               
        });
    },

    strategy: ol.loadingstrategy.all,
    projection: 'EPSG:2263',
    crossOrigin: 'anonymous',
}),

here is a snippet of the GeoServer log file:

2020-03-30 12:10:50,790 INFO [geoserver.wfs] - Request: getServiceInfo 2020-03-30 12:10:50,806 INFO [geoserver.wfs] - Request: getFeature service = WFS version = 1.1.0 baseUrl = http://servername:8080/geoserver/ query[0]: srsName = EPSG:2263 typeName[0] = {http://boundlessgeo.com/}lines outputFormat = text/xml; subtype=gml/3.1.1 resultType = results 2020-03-30 12:10:50,853 ERROR [geoserver.ows] - java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at org.geotools.xml.Encoder.encode(Encoder.java:738) at org.geotools.xml.Encoder.encode(Encoder.java:609) at org.geoserver.wfs.xml.GML3OutputFormat.encode(GML3OutputFormat.java:302) at org.geoserver.wfs.xml.GML3OutputFormat.write(GML3OutputFormat.java:279) at org.geoserver.wfs.WFSGetFeatureOutputFormat.write(WFSGetFeatureOutputFormat.java:196) at org.geoserver.ows.Dispatcher.response(Dispatcher.java:996) at org.geoserver.ows.Dispatcher.handleRequestInternal(Dispatcher.java:279) at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)

here is what I found later in log under 'caused by':

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.AbstractStringBuilder.setLength(Unknown Source) at java.lang.StringBuffer.setLength(Unknown Source) at org.geotools.gml2.simple.GMLWriter.coordinates(GMLWriter.java:302) at org.geotools.gml2.simple.GMLWriter.positions(GMLWriter.java:291) at org.geotools.gml2.simple.GMLWriter.posList(GMLWriter.java:348) at org.geotools.gml3.simple.LineStringEncoder.encode(LineStringEncoder.java:52) at org.geotools.gml3.simple.LineStringEncoder.encode(LineStringEncoder.java:34) at org.geotools.gml2.simple.FeatureCollectionEncoderDelegate.encodeValue(FeatureCollectionEncoderDelegate.java:196) at org.geotools.gml2.simple.FeatureCollectionEncoderDelegate.encodeFeature(FeatureCollectionEncoderDelegate.java:176) at org.geotools.gml2.simple.FeatureCollectionEncoderDelegate.encode(FeatureCollectionEncoderDelegate.java:130) at org.geotools.xml.Encoder.encode(Encoder.java:735)

3
  • Please look in the log files and add any relevant error messages to your question using the edit button
    – Ian Turton
    Mar 30, 2020 at 15:25
  • @IanTurton I added log text above
    – JasonBK
    Mar 30, 2020 at 16:15
  • can you also add the actual XML being sent by the client - look in the network tab of the browser debugger
    – Ian Turton
    Mar 31, 2020 at 7:14

1 Answer 1

0

I received this response from Josh at Planet Federal (formerly BoundlessGeo):

"That code is trying to build a string from all of the coordinates in the current feature by using a simple for-loop and iterating over all of the coordinates. When it's done, it's trying to reduce the size of the string builder to 1 less than the current value. However, it appears that the coordinate size is zero, so the string builder length is zero, and when it tries to set the value to 1 less than the current value (-1), it's producing that exception. Is there a chance some of your data does not have geometries?"

so we looked for empty geometries using st_isemtpy(geom) and found some, once those were removed the table loaded correctly as WFS (btw, we use using PostgresSQL tables).

side note - I had already looked for empty value is an IS NULL query, but that returned no rows...then I learned that there can be rows with an empty string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.