Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sorry for disturbing. I know my problem look common, but I really don't know what to make. Here is my code for getting a WMS layer in OpenLayers from Geoserver.

var wfs2 = 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: "topp",
                    featureType: "states",
                    featureNS: "www.openplans.org/topp",
                    srsName: "EPSG:4326",
                    geometryName: "position"
                  })          
         });

So i get this problem in developer tools for chrome :

XMLHttpRequest cannot load http://localhost:8080/geoserver/wfs. Origin null is not allowed by Access-Control-Allow-Origin. 

in developer tools for chrome

I saw that people recommend to set up a proxy, but my .html is in the geoserver/data_dir/www folder, and don't call external urls.

I however tried it, so I created the folder cgi-bin in /usr/local/geoserver/cgi-bin/, where i put the proxy code I found here :http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost

And then I added in the cript of my .html this : OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

But I then get this error in developer tools :

Failed to load resource file://localhost/cgi-bin/proxy.cgi?url=http%3A%2F%2Flocalhost%3A8080%2Fgeoserver%2Fwfs 

Probably the proxy is not in the right place, but I don't think the first problem (without problem) comes from here.

Please help !

Thks a lot !

share|improve this question
    
If your html file is in geoserver/data_dir/www folder, how are you calling it in your browser? what is teh Url in your Browser? Does it start with http:// or file://? –  Devdatta Tengshe May 24 '13 at 5:43
    
I access it this way : file://localhost/usr/local/geoserver/data_dir/www/map2.html –  Gabriel May 24 '13 at 5:50
add comment

1 Answer

up vote 3 down vote accepted

You should access it through http protocol. file protocol is not allowed with a WFS server. see this StackOverflow question.

To test geoserver WFS try GetCapabilities request.

For your case try this:

http://localhost:8080/geoserver/wfs?service=wfs&version=1.1.0&request=GetCapabilities.

More info at geoserver manual

share|improve this answer
    
yes, the right url was : localhost:8080/geoserver/www/map2.html Thks ! –  Gabriel May 24 '13 at 16:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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