More

WFS via Geoserver - Proxy or MapDocument Issues?


I struggle getting a WFS overlay from geoserver to work. I think I meet all the requirements for the WFS to be displayed in my map, but the request seems to get stuck somewhere… FireBug gives the error-message:

Access to restricted URI denied" code: "1012 http://www.openlayers.org/api/OpenLayers.js Line 1188

whereas Line 1188 contains the following:

this._object.send(vData);if(bGecko&&!this._async){this.readyState=cXMLHttpRequest.OPENED; fSynchronizeValues(this)while(this.readyState

The whole applications are running on localhost, I installed Apache Webserver and configured a proxy since that was recommended in most Threads concerning WFS running on localhost. I used the proxy.cgi from http://trac.osgeo.org/openlayers/browser/trunk/openlayers/examples/proxy.cgi and allowed access for 'localhost','localhost:80' and 'localhost:8080'same with my IP (IP, IP:80, IP:8080).

When I visit localhost/cgi-bin/proxy.cgi I get to see the OpenLayers Page so that should be working! My WFS Variable looks like this:

var wfs = new OpenLayers.Layer.Vector("WFS", { strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.WFS({ version: "1.1.0", url: "http://localhost:8080/geoserver/wfs", featurePrefix: "workspacename", featureType: "layername", featureNS: "http://lvr", [tried many, it doesn't need to be an existing URL right?] srsName: "EPSG:4326", geometryName: "the_geom" }) });

then I set

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

Is that one complete and where do I put it in the map document? Can anybody help? Tried a lot of options, nothing really helped but it seems like it's some connection/security issue rather than smth related to the map script itself… Do I neccesarily need a format variable, a schema location or a stylemap? Anything else important missing?


Update from comments:

I can open it, typing localhost:8080/map.html… And when I just did that, the WFS data showed up!

Can't believe it - I just accessed the html wrongly?! Beginners mistake. Thanks geographika…


A quick solution which avoids the need for proxies while testing is to put your web pages in the www directory of your GeoServer data directory. The page will then be served through the same port and host as your WFS and all will work fine.

Ultimately you will need a proxy if (and only if) you move the web pages to some other location.


The error indicates a cross-domain issue.

How are you accessing your site? Through http://localhost:80 or http://localhost:8080? And where is your proxy hosted? It should match the location and port of your site.

You say you are running the application locally, but your FireBug message implies you are using the OpenLayers Javascript hosted at: http://www.openlayers.org/api/OpenLayers.js

The alternative is to download and host the JavaScript and CSS files yourself from http://openlayers.org/download/

This shouldn't make a difference however.


Watch the video: Web Map GeoServer (October 2021).