I'm having trouble with the standard proxy.cgi written in Python for OpenLayers. Here's my code:
#!C:/Python27/python.exe -u
"""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 possibly do bad stuff
with it. It only loads pages via http and https, but it can load any
content type. It supports GET and POST requests."""
import urllib2
import cgi
import sys, os
# Designed to prevent Open Proxy type stuff.
allowedHosts = ['www.openlayers.org', 'openlayers.org',
'labs.metacarta.com', 'world.freemap.in',
'prototype.openmnnd.org', 'geo.openplans.org',
'sigma.openplans.org', 'demo.opengeo.org',
'www.openstreetmap.org', 'sample.azavea.com',
'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080',
'vmap0.tiles.osgeo.org', 'www.openrouteservice.org',
'dcdu.municipiodeslp.gob.mx:8082', 'www.ssn.unam.mx',
'localhost','localhost:8082', 'localhost:80','127.0.0.1:8082','127.0.0.1']
method = os.environ["REQUEST_METHOD"]
if method == "POST":
qs = os.environ["QUERY_STRING"]
d = cgi.parse_qs(qs)
if d.has_key("url"):
url = d["url"][0]
else:
url = "http://www.openlayers.org"
else:
fs = cgi.FieldStorage()
url = fs.getvalue('url', "http://www.openlayers.org")
try:
host = url.split("/")[2]
if allowedHosts and not host in allowedHosts:
print "Status: 502 Bad Gateway"
print "Content-Type: text/plain"
print
print "This proxy does not allow you to access that location (%s)." % (host,)
print
print os.environ
elif url.startswith("http://") or url.startswith("https://"):
if method == "POST":
length = int(os.environ["CONTENT_LENGTH"])
headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
body = sys.stdin.read(length)
r = urllib2.Request(url, body, headers)
y = urllib2.urlopen(r)
else:
y = urllib2.urlopen(url)
# print content type header
i = y.info()
if i.has_key("Content-Type"):
print "Content-Type: %s" % (i["Content-Type"])
else:
print "Content-Type: text/plain"
print
print y.read()
y.close()
else:
print "Content-Type: text/plain"
print
print "Illegal request."
except Exception, E:
print "Status: 500 Unexpected Error"
print "Content-Type: text/plain"
print
print "Some unexpected error occurred. Error text was:", E
The odd thing is that I am able to receive a GeoRSS feed through the same proxy but not a WFS from GeoServer as shown below:
Even though 'localhost:8082' is added to my 'allowedHosts', I receive a '502 Bad Gateway' error. I've looked at many questions on proxy.cgi and a tutorial but I still have no idea what's wrong.
I'm running Apache on XAMPP on port 80 while GeoServer is on port 8082.
UPDATE
Here's what my "Workspace" in GeoServer is:
and the layer is registering as WFS:
And if I browse to the WFS at:
http://localhost:8082/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=zac:gcolonia
I receive xml:
I'm beginning to think it's a problem with OpenLayers. Here's how I'm adding it to the map:
gcolonia = new OpenLayers.Layer.Vector("gcolonia", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.WFS({
srsName: new OpenLayers.Projection("EPSG:4326"),
url: "http://localhost:8082/geoserver/wfs",
featurePrefix:"zac",
featureType: "gcolonia",
featureNS: "http://localhost:80/Atlas_TLX/zac",
geometryName: "col_geom"
}),
visibility: false
});
Newest Update
Browsing to http://localhost/cgi-bin/proxy.cgi?url=http://www.ssn.unam.mx
-> fine Browsing to http://localhost/cgi-bin/proxy.cgi?url=http://localhost:8082/geoserver/web
->
This proxy does not allow you to access (localhost:8082).
Yet, my proxy.cgi
contains that location as shown above. My cgi-bin
is located in xampp/cgi-bin
. I've also cleared my browser cache.
Any thoughts?
No comments:
Post a Comment