Wednesday, 18 January 2017

geoserver - Access-Control-Allow-Origin Openlayers WFS


I try to use a WFS service with OpenStreetMap to request GeoServer GeoJSON file. First I had a error message on the Firefox Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/geoserver/robot/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=robot:geofield&outputFormat=aoolication%2Fjson. (Reason: CORS header 'Access-Control-Allow-Origin' missing).



Then I pasted the following lines in the web.xml from /usr/share/geoserver/webapps/geoserver/WEB-INF



CorsFilter
org.apache.catalina.filters.CorsFilter

cors.allowed.origins
*




CorsFilter
/*


After when I go on http://localhost:8080/geoserver/ I have a HTTP ERROR: 503 and still have the same CORS header problem


I don't know what is wrong, maybe this method doesn't work with latest GeoServer versions


If someone has a good and clear answer, it will be great because I think I'm not the only one who want to use a wfs with GeoServer and OpenLayers.



Answer



I think you are using jetty and not catalina, I got same problem in Windows :


http://www.eclipse.org/jetty/documentation/current/cross-origin-filter.html



Try putting instead in web.xml :



cross-origin
org.eclipse.jetty.servlets.CrossOriginFilter


cross-origin
/*



And copy into C:\Program Files (x86)\GeoServer 2.10.0\webapps\geoserver\WEB-INF\lib folder : jetty-servlets-9.2.13.v20150730.jar


Get jar needed from http://central.maven.org/maven2/org/eclipse/jetty/jetty-servlets/, and check needed version from your folder C:\Program Files (x86)\GeoServer 2.10.0\lib


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...