6

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

2
  • 2
    don't run from file://somefolder/mytestpage.html always use localhost:28080/geoserver/www/mytestpage.html this should fix your problem.
    – Ian Turton
    Oct 1, 2012 at 14:32
  • Nice and simple, that fixed it! I don't fully understand why it works like that, though. Can you explain what happens in OpenLayers when I access the page using file:// and when I use localhost:28080 instead? Oct 2, 2012 at 8:18

1 Answer 1

7

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.

4
  • Your suggestion fixed the problem, but can this really be same-origin problem? I am still confused about why I am not seeing any same-origin policy related error messages or failed requests in Firebug when I access the page using file:// URL? Also, when I load the page from http:// localhost:28080, that is not the only place my script can send requests to. It does send requests to for example maps.google.com (as I do not have a proxy configured), successfully. I am marking this as an answer as it fixed my problem, but would still very much love to understand what really is going on. Oct 2, 2012 at 9:57
  • Your browser is probably not sending the requests as it "knows" they violate the same origin policy. The same origin policy only refers to data requests not images which is probably what you're requesting from google.
    – Ian Turton
    Oct 2, 2012 at 10:00
  • 1
    Stupid browser, failing silently is confusing and makes it difficult to find the source of the problem while developing. I would much prefer to see an error somewhere, at least when I look at it with Firebug. That makes sense, thanks for the clarification. Oct 2, 2012 at 10:05
  • Ummm....I have to say I still do not understand how this works. See the two images I added to original question. I am viewing the page from localhost:28080, and it fetches data (not images) from maps.googleapis.com. Isn't this violating same-origin policy? Oct 2, 2012 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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