1

I have written a script using OpenLayers library to get some layers from Geoserver and display them on the map. I use both WMS and WFS layers. Everything worked fine in my localhost (MAMP) in windows OS. Now I have to migrate in an UBUNTU 12.10 system. Although I get the WMS correctly, I can not make it to get the WFS.

I used firebug and this is the POST request:

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <wfs:Query typeName="rural:foc_network" srsName="EPSG:4326" xmlns:rural="http://www.opengeospatial.net/rural">
 <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
 <ogc:BBOX>
 <gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
 <gml:lowerCorner>21.831815896484 37.948519811767</gml:lowerCorner>
 <gml:upperCorner>22.346800027344 38.120181188719</gml:upperCorner>
 </gml:Envelope>
 </ogc:BBOX>
 </ogc:Filter>
 </wfs:Query>
</wfs:GetFeature>

And this the POST response (which is actually the content of my cgi file:

 #!/usr/bin/env python

"""This is a blind proxy that we use to get around browser
restrictions that prevent the Javascript from loading pages not on the
same server as the Javascript.  This has several problems: it's less
efficient, it might break some sites, and it's a security risk because
people can use this proxy to browse the web and p

In the XML tag of firegu I get this error:

 XML Parsing Error: not well-formed Location: moz-nullprincipal:{79ed7c81-0daf-4525-a315-808f0894befd} Line Number 1, Column 2:

 #!/usr/bin/env python

Do you have any idea what is going wrong here? Is the path: #!/usr/bin/env python wrongly set? Or what else could be the problem?

And this is my WFS request:

  wfs_layer_komvoi = new OpenLayers.Layer.Vector("Κόμβοι", {
        strategies: [new OpenLayers.Strategy.BBOX()],
        protocol: new OpenLayers.Protocol.WFS({
                version: "1.1.0",
                url: "http://localhost:8080/geoserver/wfs", 
                featurePrefix: "rural", //workspace from geoserver
                featureType: "komvoi_real", //layer name from geoserver
                        featureNS : "http://www.opengeospatial.net/rural", //namespace from geoserver
                        styles: "point"
                    })
                })

1 Answer 1

3

There a two or three possible reasons that come to my mind:

Option1: your Webserver is not configured properly:

What happens for example if you try to access this site(presuming that you put your proxy.cgi in your usr/lib/cgi-bin -folder):

http://yourserver_ip_or_adress/cgi-bin/proxy.cgi?url=http://www.openstreetmap.org

If you wont see the openstreetmap-website (without proper styling) than you should have a look at your apache settings.

Here you will find infos: https://httpd.apache.org/docs/2.4/howto/cgi.html#configuring

one option would be to edit your vhosts in

/etc/apache2/sites-enabled/default or /etc/apache2/sites-available/default

where you could add some informations that cgi should be executed: Here is just a simple example how one virtual host definition could look like:

<VirtualHost *:80>
        ServerName yourservername
        ServerAlias yourservername
        DocumentRoot /var/www/xyz/
        ScriptAlias /cgi-bin /usr/lib/cgi-bin/
                <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI
                SetHandler cgi-script
                Order allow,deny
                Allow from all
        </Directory>


</VirtualHost>

--

Option2 / Option3: Encoding-Problems or cgi not executable:

Try a clean proxy.cgi-"setup":

  • download the proxy.cgi directly in your linux OS:

wget https://raw.githubusercontent.com/openlayers/openlayers/master/examples/proxy.cgi

  • add your site to the allowed hosts (for example with nano editor)

nano proxy.cgi

  • put it in your cgi-bin folder (for example /usr/lib/cgi-bin )

make sure it's executable ( for example chmod a+rx /usr/lib/cgi-bin/proxy.cgi )

  • set the OpenLayers.ProxyHost:

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

  • and give it a try
7
  • Thanks for your answer. When I run this: localhost/neo4jtest2/cgi-bin/proxy.cgi I just get the content of the cgi file. Can it be also that the first line of the cgi is wrong: #!/usr/bin/ python
    – user1919
    Commented Feb 10, 2015 at 13:02
  • I have serious problem understanding if I need to stop using my localhost LAMP server and place everything in the tomcat server or I should just use tomcat for geoserver and keep using my localhost LAMP server for my application..
    – user1919
    Commented Feb 10, 2015 at 13:09
  • sometimes there can be encoding problems when you use the proxy.cgi that you edited on windows-os. to see if that's the problem you can just directly download a sample proxy.cgi with wget in your linux console: wget raw.githubusercontent.com/openlayers/openlayers/master/examples/… see also trac.osgeo.org/openlayers/wiki/…
    – Thomas B
    Commented Feb 10, 2015 at 13:11
  • Nope this is not the case. It seems I have to have my whole app into tomcat and drop completely LAMP. I should place it in some folder webapps as described here: berndresch.com/blog/2011/11/01/installing-a-cgi-proxy-on-tomcat but I dont even know where this folder is..
    – user1919
    Commented Feb 10, 2015 at 13:16
  • 1
    If you use Apache you can dont have to put your webapp into tomcat... thats for 100% sure. I use this combination for loads of OL-Apps! the proxy just has to be setup properly. see Option2 that I added to my answer above.
    – Thomas B
    Commented Feb 10, 2015 at 13:25

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.