Hello All,
I am trying to use jQuery .ajax to POST requests to Geoserver for dynamically
creating featuretypes and amending them. I am using a proxy python script to
get round cross-domain issues. The request always comes back with an error
code of 500. I can run GET requests with no errors using the same proxy.
Can anyone see what is going wrong or offer assistance? Thanks.
My request looks like this:
var proxyurl = 'http://localhost/proxy.py?url=';
var lyrname = "subproject11_inputs";
$.ajax({
type: "POST",
url: proxyurl +
"http://localhost:8080/geoserver/rest/workspaces/jflow/datastores/jflow_testdb_v46/featuretypes.xml",
data: '<featureType><name>' + lyrname + '</name></featureType>',
username: "admin",
password: "geoserver",
contentType: "application/xml", //; charset=utf-8 -not needed
complete: function(xReq,txtStatus) {
alert('in complete: xReq.status=' + xReq.status + ' txtstatus=' + txtStatus +
'; responseText= ' + xReq.responseText);
}
}); // end of $.ajax
My proxy script looks like this:
'''#!C:/Python26 python'''
#!/usr/bin/env python
import urllib2
import cgi
import sys, os
default_url = 'http://www.bbc.co.uk'
# Designed to prevent Open Proxy type stuff. Add site domains, minus the
http:// prefix/part.
allowedHosts = ['ncl.ac.uk', 'localhost:8080',
'www.bbc.co.uk',
'www.techmeme.com',
'twitter.com',
'www.guardian.co.uk',
'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', 'localhost:4545']
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 = default_url
else:
fs = cgi.FieldStorage()
url = fs.getvalue('url', default_url) # get url to proxy to from request
URL, or use default
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
Thanks for any assistance.
Anne Brookes
Senior Analyst - GIS and System Development
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Geoserver-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-users