5

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

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

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.

6

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 :

<filter>
    <filter-name>cross-origin</filter-name>
    <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>cross-origin</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

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

  • 1
    in my package of Geoserver it was already there, so no needs to download from internetz. Worked for me, may work for others. $> cp $GEOSERVER_HOME\lib\jetty-servlets-9.2.13.v20150730.jar $GEOSERVER_HOME\webapps\geoserver\WEB-INF\lib – Sanctus Aug 14 '18 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.