2

I want to add an Access-Control-Allow-Origin:* to the response from GeoServer because I need to download images from another domain. Instead of building a proxy, I prefer to use Cross Origin Filter of Jetty(GeoServer's Web Server) to achieve this. However, I don't know how to set it up in GeoServer.

  1. My GeoServer's version is 2.1.3 so the Jetty's version is 6, which does not include the jetty-servlets.jar.
  2. I downloaded the jetty-servlets-8.1.5.v20120716.jar from here and renamed it to jetty-servlets.jar, then put it into /Applications/GeoServer.app/Contents/Resources/Java/webapps/geoserver/WEB-INF/lib/
  3. Then I add the following codes to the web.xml file at /Applications/GeoServer.app/Contents/Resources/Java/webapps/geoserver/WEB-INF/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>

At last, I restarted GeoServer but the page at http://localhost:8080/geoserver/web showed me an error 404:

HTTP ERROR: 404
NOT_FOUND
RequestURI=/geoserver/web
Powered by jetty://

Is there anyone who can help me?

2
  • I just had your code <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 i have the same mitake : ERROR 503 !
    – ROCHEDY
    Feb 11, 2013 at 14:11
  • look at the jetty log. I think you sould also add jetty-util lib
    – user58939
    Sep 9, 2015 at 8:36

1 Answer 1

1

It's very unlikely that you can add random jars to your jetty install and expect it to work - which seems to be case here.

The easiest solution (if you really can't be bothered to add a proxy script) is to download the latest version of jetty and add the GeoServer war file to it and then modify the web.xml file.

2
  • I downloaded jetty-distribution-8.1.5.v20120716.tar.gz and added the GeoServer 2.1.4 war to the webapps folder. After I started Jetty, other apps like "test" and "spdy" could run very well but the "geoserver" could not run, which showed me an Error 503. Does the GeoServer needs other settings? I'm a newbie of GIS and I just feel that use proxy is not an elegant way, so could you provide more detail steps? Thank you very much!
    – houhr
    Aug 30, 2012 at 9:53
  • you can use tomcat +apache
    – neogeomat
    Apr 12, 2013 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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