[GIS] GeoServer/OpenLayers WFS: “Could not determine geoserver request from http request…”

geoserveropenlayerswfs

I'm using Openlayers + GeoServer to draw a new point and save it. But there are some errors.

Code as follows:

function onSaveNewPoint() {

      for(var i = 0 ; i < drawedFeaturePointArray.length ; i++){

      var geometry = drawedFeaturePointArray[i].getGeometry().clone();
      geometry.applyTransform(function(flatCoordinates, flatCoordinates2, stride) {
        for (var j = 0; j < flatCoordinates.length; j += stride) {
          var y = flatCoordinates[j];
          var x = flatCoordinates[j + 1];
          flatCoordinates[j] = x;
          flatCoordinates[j + 1] = y;
        }
      });
      var newFeature = new ol.Feature();
      newFeature.setId('cities.2406.new.' + newPointId);
      newFeature.setGeometryName('the_geom');
      newFeature.set('CITY_NAME', newFeature.getId());
      newFeature.set('GMI_ADMIN', newFeature.getId());
      newFeature.set('ADMIN_NAME', 0);
      newFeature.set('FIPS_CNTRY', '');
      newFeature.set('CNTRY_NAME', '');
      newFeature.set('STATUS', 'test');
      newFeature.set('POP_RANK', 0);
      newFeature.set('POP_CLASS', '');
      newFeature.set('PORT_ID', 0);
      newFeature.set('LABEL_FLAG', 0);
      newFeature.setGeometry(new ol.geom.Point([geometry.getCoordinates()]));

      addWfsPoint([newFeature]);
      newPointId = newPointId + 1;
      setTimeout(function(){
        console.log('next Feature');
      },3000);
    }      
  }

function addWfsPoint(features) {
      var WFSTSerializer = new ol.format.WFS();
      var featObject = WFSTSerializer.writeTransaction(features,
        null, null, {
          featureType: 'WorldCities',
          featureNS: 'http://geoserver.org/WorldCities',
          srsName: 'EPSG:4326'
        });
      var serializer = new XMLSerializer();
      var featString = serializer.serializeToString(featObject).replace('undefined','');;

      var request = new XMLHttpRequest();
      request.open('POST', 'http://localhost:8080/geoserver/wfs?service=wfs');
      request.setRequestHeader('Content-Type', 'text/xml');
      request.send(featString);
    }

Errors as follows:

<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://localhost:8080/geoserver/schemas/ows/1.1.0/owsAll.xsd">
<ows:Exception exceptionCode="MissingParameterValue" locator="request">
<ows:ExceptionText>
Could not determine geoserver request from http request org.geoserver.platform.AdvancedDispatchFilter$AdvancedDispatchHttpRequest@52de3d55
</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

with browser response as follows:

<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://localhost:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
  <ows:Exception exceptionCode="NoApplicableCode">
    <ows:ExceptionText>java.lang.RuntimeException: Parsing failed for pos: java.lang.RuntimeException: Parsing failed for null: java.lang.NumberFormatException: For input string: "40.73628139583304,-74.00918689125533"
Parsing failed for pos: java.lang.RuntimeException: Parsing failed for null: java.lang.NumberFormatException: For input string: "40.73628139583304,-74.00918689125533"
Parsing failed for null: java.lang.NumberFormatException: For input string: "40.73628139583304,-74.00918689125533"
For input string: "40.73628139583304,-74.00918689125533"</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

and the XML being posted by the browser:

<?xml version="1.0" encoding="utf-8"?>
<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
  <Insert>
    <WorldCities xmlns="http://geoserver.org/WorldCities" fid="cities.2406.new.1">
      <the_geom>
        <Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
          <pos  srsDimension="2">40.73698364739682,-74.00934294690373</pos>
        </Point>
      </the_geom>
      <CITY_NAME>cities.2406.new.1</CITY_NAME>
      <GMI_ADMIN>cities.2406.new.1</GMI_ADMIN>
      <ADMIN_NAME>0</ADMIN_NAME>
      <FIPS_CNTRY/>
      <CNTRY_NAME/>
      <STATUS>test</STATUS>
      <POP_RANK>0</POP_RANK>
      <POP_CLASS/>
      <PORT_ID>0</PORT_ID>
      <LABEL_FLAG>0</LABEL_FLAG>
    </WorldCities>
  </Insert>
</Transaction>

I've searched online, but still don't know how to resolve this problem. I hope someone here can help me out.

Best Answer

The request is lacking all namespaces besides the WFS one, you'll need to add namespace and prefix for the WorldCities feature and attributes, as well as the GML namespaces for the GML elements in it. Use a GeoServer WFS 1.1 response as guidance.

Related Question