2

I am trying to enable the CORS for GeoServer. I am using GeoServer 2.16 and the Tomcat version of 9.0.8. I already tried to add following code in geoserver/WEB-INF/web.xml file,

<filter>
    <filter-name>cross-origin</filter-name>
    <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
    <init-param>
        <param-name>chainPreflight</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>allowedOrigins</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>allowedMethods</param-name>
        <param-value>GET,POST,PUT,DELETE,HEAD,OPTIONS</param-value>
    </init-param>
    <init-param>
        <param-name>allowedHeaders</param-name>
        <param-value>*</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>cross-origin</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

While I add this code to the web.xml file, the GeoServer couldn't start. It shows the 404 error. I don't know why the 404 error occur when I added this filter in my web.xml file.

How can I find the solution?

geoserver not working, 404 error

However Tomcat server is still working. And the GeoServer log file shows following error;

2020-02-08 20:40:55,709 INFO [storage.DefaultStorageFinder] - ***************************************************************************************
2020-02-08 20:40:55,709 INFO [storage.DefaultStorageFinder] - *** Reverting to java.io.tmpdir null for storage. Please set GEOWEBCACHE_CACHE_DIR. ***
2020-02-08 20:40:55,709 INFO [storage.DefaultStorageFinder] - ***************************************************************************************
2020-02-08 20:40:55,766 INFO [gwc.config] - Initializing GeoServer specific GWC configuration from gwc-gs.xml
2020-02-08 20:40:56,091 INFO [config.GeoserverXMLResourceProvider] - Will look for 'geowebcache-diskquota.xml' in directory '/opt/tomcat/apache-tomcat-9.0.8/webapps/geoserver/data/gwc'.
2020-02-08 20:40:56,098 INFO [config.GeoserverXMLResourceProvider] - Will look for 'geowebcache-diskquota-jdbc.xml' in directory '/opt/tomcat/apache-tomcat-9.0.8/webapps/geoserver/data/gwc'.
2020-02-08 20:40:56,101 INFO [diskquota.ConfigLoader] - DiskQuota configuration is not readable: gwc/geowebcache-diskquota.xml
2020-02-08 20:40:56,107 INFO [diskquota.ConfigLoader] - DiskQuota configuration is not readable: gwc/geowebcache-diskquota.xml
2020-02-08 20:40:56,108 INFO [diskquota.DiskQuotaMonitor] - Setting up disk quota periodic enforcement task
2020-02-08 20:40:56,108 INFO [diskquota.DiskQuotaMonitor] - 0 layers configured with their own quotas.
2020-02-08 20:40:56,134 INFO [diskquota.DiskQuotaMonitor] - 43 layers attached to global quota 500.0 MB
2020-02-08 20:40:56,159 INFO [diskquota.DiskQuotaMonitor] - Disk quota periodic enforcement task set up every 10 SECONDS
2020-02-08 20:41:01,125 INFO [geoserver.platform] - Falling back to embedded data directory: /opt/tomcat/apache-tomcat-9.0.8/webapps/geoserver/data
2020-02-08 20:41:01,500 INFO [geowebcache.GeoWebCacheDispatcher] - Invoked setServletPrefix(gwc)
2020-02-08 20:41:01,510 INFO [georss.GeoRSSPoller] - Initializing GeoRSS poller in a background job...
2020-02-08 20:41:01,515 INFO [georss.GeoRSSPoller] - No enabled GeoRSS feeds found, poller will not run.
2020-02-08 20:41:01,696 INFO [wms.WMSService] - Will NOT recombine tiles for non-tiling clients.
2020-02-08 20:41:01,696 INFO [wms.WMSService] - Will proxy requests to backend that are not getmap or getcapabilities.
2020-02-08 20:41:02,105 WARN [gce.imagemosaic] - Unable to set ordering between tiff readers spi
2020-02-08 20:41:03,188 INFO [geoserver.security] - Start reloading user/groups for service named default
2020-02-08 20:41:03,191 INFO [geoserver.security] - Reloading user/groups successful for service named default
2020-02-08 20:41:03,342 INFO [geoserver.security] - AuthenticationCache Initialized with 1000 Max Entries, 300 seconds idle time, 600 seconds time to live and 3 concurrency level
2020-02-08 20:41:03,342 INFO [geoserver.security] - AuthenticationCache Eviction Task created to run every 600 seconds
2020-02-08 20:41:04,381 INFO [georss.GeoRSSPoller] - destroy() invoked
2020-02-08 20:41:04,381 INFO [geowebcache.GeoWebCacheDispatcher] - GeoWebCacheDispatcher.destroy() was invoked, shutting down.
2020-02-08 20:41:04,383 INFO [diskquota.DiskQuotaMonitor] - Disk quota monitor shutting down...
2020-02-08 20:41:04,383 INFO [diskquota.DiskQuotaMonitor] - Shutting down quota usage monitor...
2020-02-08 20:41:04,383 INFO [diskquota.QuotaUpdatesMonitor] - Shutting down quota usage monitor...
2020-02-08 20:41:04,386 INFO [diskquota.DiskQuotaMonitor] - Shutting down quota statistics gathering monitor...
2020-02-08 20:41:04,386 INFO [diskquota.QueuedQuotaUpdatesConsumer] - Shutting down quota update background task due to InterruptedException
2020-02-08 20:41:04,388 INFO [diskquota.QueuedUsageStatsConsumer] - Shutting down quota update background task due to interrupted exception
2020-02-08 20:41:04,389 INFO [seed.SeederThreadPoolExecutor] - Initiating shut down for running and pending seed tasks...
2020-02-08 20:41:04,389 INFO [seed.SeederThreadPoolExecutor] - Seeder thread pool executor shut down complete.
2020-02-08 20:41:04,389 INFO [storage.DefaultStorageBroker] - Destroying StorageBroker

2
  • 2
    It seems as if you deleted a previous question from several hours back and added this new one with the requested information. It is far better to just edit the question, then toggle the reopen button, since SE can detect the delete/re-ask and may treat the user account harshly if it becomes a habit.
    – Vince
    Feb 8 '20 at 15:04
  • I don't see any errors in the log you have included
    – Ian Turton
    Feb 8 '20 at 20:09
3

It looks like you are using the Jetty instructions on a tomcat server - try following the tomcat ones.

You need to add the following to $CATALINA_HOME/conf/web.xml:

<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>
1
  • this might depend on the server type, but on my EC2 Ubuntu installation of tomcat8 GeoServer, the web.xml is located in: /var/lib/tomcat8/webapps/geoserver/WEB-INF/. And even though it's in a tomcat directory, the web.xml has 'Jetty' CORS filters... confusing. there is another CORS filter written a few lines below it, maybe that's tomcat? Another web.xml exists in /etc/tomcat8/ but it has no CORS filters to change.
    – Theo F
    Jul 17 '20 at 15:23

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.