Importer doesn't pass spring request context to jobs threads

Description

This error happens with geofence-server installed (but is not specific to geofence) and can be reproduced performing the following steps:

1 - Create an importer task:

1 2 3 4 5 6 7 8 9 { "import": { "targetWorkspace": { "workspace": { "name": "it.geosolutions" } } } }
1 curl -u admin:geoserver -XPOST -H "Content-type: application/json" -d @import.json "http://localhost:8080/geoserver/rest/imports"

2 - Upload the data (I zipped nyc shapefiles provided with GeoServer):

1 curl -u admin:geoserver -F name=nyc.zip -F filedata=@nyc.zip "http://localhost:8080/geoserver/rest/imports/0/tasks"

3 - Start the import task asynchronously:

1 curl -u admin:geoserver -XPOST "http://localhost:8080/geoserver/rest/imports/0?async=true"

We should get this exception:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) at org.geoserver.geofence.GeofenceAccessManager.retrieveCallerIpAddress(GeofenceAccessManager.java:253) at org.geoserver.geofence.GeofenceAccessManager.getAccessLimits(GeofenceAccessManager.java:367) at it.geosolutions.security.alb.AlbMultiplexingAccessManager.getAccessLimits(AlbMultiplexingAccessManager.java:122) at org.geoserver.security.ResourceAccessManagerWrapper.getAccessLimits(ResourceAccessManagerWrapper.java:210) at org.geoserver.security.CatalogFilterAccessManager.getAccessLimits(CatalogFilterAccessManager.java:64) at org.geoserver.security.SecureCatalogImpl.buildWrapperPolicy(SecureCatalogImpl.java:811) at org.geoserver.security.SecureCatalogImpl.buildWrapperPolicy(SecureCatalogImpl.java:771) at org.geoserver.security.SecureCatalogImpl.checkAccess(SecureCatalogImpl.java:510) at org.geoserver.security.SecureCatalogImpl.getResourceByName(SecureCatalogImpl.java:390) at org.geoserver.catalog.impl.AbstractFilteredCatalog.getResourceByName(AbstractFilteredCatalog.java:304) at org.geoserver.catalog.impl.AbstractCatalogDecorator.getResourceByName(AbstractCatalogDecorator.java:234) at org.geoserver.importer.Importer.findUniqueResourceName(Importer.java:1427) at org.geoserver.importer.Importer.addToCatalog(Importer.java:1374) at org.geoserver.importer.Importer.doIndirectImport(Importer.java:1000) at org.geoserver.importer.Importer.run(Importer.java:852) at org.geoserver.importer.Importer.run(Importer.java:802) at org.geoserver.importer.Importer$5.call(Importer.java:881) at org.geoserver.importer.Importer$5.call(Importer.java:875) at org.geoserver.importer.job.Job.call(Job.java:16) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

This error happens because the importer is not sharing the current request context when running a job asynchronously:

https://github.com/geoserver/geoserver/blob/master/src/extension/importer/core/src/main/java/org/geoserver/importer/Importer.java#L874-L890

Environment

None

Status

Assignee

Nuno Oliveira

Reporter

Nuno Oliveira

Triage

None

Fix versions

Affects versions

None

Components

Priority

Medium
Configure