I'm trying to use a WFS-T Service to insert a simple Point from OpenLayers 3 into Geoserver in a VirtualBox (test environment). There is always the same error message:
Failed to load resource: Origin http://localhost:8383 is not allowed by Access-Control-Allow-Origin. at http://HOST_IP:8082/geoserver/test/wfs
XMLHttpRequest cannot load http://HOST_IP:8082/geoserver/test/wfs. Origin http://localhost:8383 is not allowed by Access-Control-Allow-Origin. (13:29:51:925 | error, javascript) at resources/webappv1.html
I took the issue and tried to solve it with Cross-Origin Resource Sharing (CORS). (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
A ProxyPass (like http://www.gistutor.com/geoserver/21-intermediate-geoserver-tutorials/38-configuring-geoserver-proxy-for-public-and-remote-data-access.html) would be for security reason only a bad alternative.
I found a solution on the Geoserver Mailing Archive by Dusan Fedorcak (Search for [Geoserver-users] CORS for jetty 6.1.8 (Geoserver 2.x)) and tried to manage it , but it is still not working.
Where do I go wrong? Or is there an other workflow to make a post Request with OL3?
Here my versions:
- OpenLayers 3
- Geosever 2.4.4 runs on VirtualBox 4.3.10 with OSGeo Live7.9 installation
- Jetty 6.1.8
- PostGIS 2.1.1
Here my code:
var xmlData =
+'< wfs:Transaction\n'
+ 'service = "WFS"\n'
+ 'version = "1.0.0"\n'
+ 'xmlns:wfs = "http://www.opengis.net/wfs"\n'
+ 'xmlns:gml = "http://www.opengis.net/gml"\n'
+ 'xmlns:test = "http://test.org"\n'
+ 'xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" \n'
+ 'xsi:schemaLocation = "http://www.opengis.net/wfs \n'
+ 'http://HOST_IP:8082/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd \n'
+ 'http://test.org/ \n'
+ 'http://HOST_IP:8082/geoserver/test/wfs/DescribeFeatureType?
typename=test:user_poi">\n'
+ '< wfs:Insert >\n'
+ '< test:user_poi >\n'
+ '< test:gid >' + gid + '< /test:gid>\n'
+ '< test:id >' + id + '< /test:id>\n'
+ '< test:tid >' + id + '< /test:tid>\n'
+ '< test:auid >' + auid + '< /test:auid>\n'
+ '< test:mdid >' + mdid + '< /test:mdid>\n'
+ '< test:text >' + text + '< /test:text>\n'
+ '< test:the_geom >\n'
+ '< gml:Point srsDimension = "2" srsName = "urn:x-ogc:def:crs:EPSG:3857" \n'
+ '< gml:coordinates decimal = "." cs = "," ts = " " >' + lat + ',' + long + '< /gml:coordinates>\n'
+ '< /gml:Point>\n'
+ '< /test:the_geom>\n'
+ '< /test:user_poi>\n'
+ '< /wfs:Insert>\n'
+ '< /wfs:Transaction>\n';
$.ajax({
type: "POST",
crossDomain: true,
url: wfsurl,
dataType: "xml",
contentType: "text/xml",
data: xmlData,
xhrFields: {
withCredentials: true
},
username: 'user',
password: 'user',
success: function(data, textStatus, request) {
alert(request.getResponseHeader('some_header'));
},
error: function(request, textStatus, errorThrown) {
alert(request.getResponseHeader('some_header'));
}
});
Thanks for your help!