[GIS] How to add Cross Origin Filter for Jetty in GeoServer on Mac

geoserverjetty

I want to add an Access-Control-Allow-Origin:* to the response from GeoServer because I need to download images from another domain. Instand of build 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? Thank you!

Best Answer

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.