[GIS] Can’t see WFS-T layer with OpenLayers and GeoServer (Windows)

geoserveropenlayers-2wfswfs-t

I am trying to implement a simple test of a OpenLayers + WFS-T + GeoServer -setup. I have followed the instructions by populating PostGIS and configuring GeoServer, and can see the WFS-T layer data in GeoServer's preview fine.

I am following these steps: http://www.gistutor.com/openlayers/22-advanced-openlayers-tutorials/47-openlayers-wfs-t-using-a-geoserver-hosted-postgis-layer.html

When I view the test page in browser, WSF-T layer is not displayed.

I have not defined proxypass to GeoServer (I have not done this: http://www.gistutor.com/geoserver/21-intermediate-geoserver-tutorials/38-configuring-geoserver-proxy-for-public-and-remote-data-access.html)! This is because

  • I think this should not be necessary since I am testing my page only using file://somefolder/mytestpage.html URLs
  • My setup does not have Apache web server at all – GeoServer Windows installer did not install it
  • The symptoms do not sound like the problems are due to not using proxypass – there are no failed requests when I look at Firebug, and no "XMLHttpRequest cannot load http://www.yourdomain.com/geoserver/wfs. Origin localhost is not allowed by Access-Control-Allow-Origin." errors

What I am weirded about is that when the page loads, the only request to localhost is OPTIONS request to /geoserver/wfs. There's no POST messages to localhost at all.

enter image description here

I have installed GeoServer in port 28080, and this is how I modified the source code from http://www.gistutor.com/openlayers/22-advanced-openlayers-tutorials/47-openlayers-wfs-t-using-a-geoserver-hosted-postgis-layer.html

.

// disabled proxypass
// OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

// wfs-t editable overlay
var wfs_layer = new OpenLayers.Layer.Vector("Editable Features", {
strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
//projection: new OpenLayers.Projection("EPSG:26910"),
protocol: new OpenLayers.Protocol.WFS({
version: "1.1.0",
// loading data through localhost url path - jannem: use port 28080 as we have no apache proxy
url: "http://localhost:28080/geoserver/wfs",
featureNS :  "http://www.opengeospatial.net/cite",
maxExtent: mapextent,
// layer name
featureType: "wfst_test",
// geometry column name
geometryName: "geom",
schema: "http://localhost:28080/geoserver/wfs/DescribeFeatureType?version=1.1.0&;typename=cite:wfst_test"
})
});

If I open localhost:28080/geoserver/wfs/ with browser, I get

<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport version="2.0.0"
  xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://localhost:28080/geoserver/schemas/ows/1.1.0/owsAll.xsd"
  xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ows:Exception exceptionCode="MissingParameterValue" locator="request">
    <ows:ExceptionText>Could not determine geoserver request from http request org.geoserver.platform.AdvancedDispatchFilter$AdvancedDispatchHttpRequest@7db12fce</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

Any ideas?

EDIT: added two pictures for the discussion in the comments:

enter image description here
enter image description here

Best Answer

To expand on my earlier comment for the benefit of Janne and other readers.

When you use OpenLayers to make a WFS (and WFS-T) request you need to be aware of the same-origin policy, this is a clever way to prevent unscrupulous web sites from running malicious javascript exploits on your web browser. Basically what it says is that if a javascript app wants to talk to the network it can only talk to the machine and port combination that it was served from.

This means that if you load a page from http:// localhost:8080 then that is the only place that your script can send requests to. Alternatively if you load your page from file://mytomcat/webapps/mypage.html your script can only send requests to file://mytomcat/... which isn't actually a server so it won't work.