GeoWebCache / geowebcache

GeoWebCache is a tile caching server implemented in Java that provides various tile caching services like WMS-C, TMS, WMTS, Google Maps, MS Bing and more

Home Page:https://www.geowebcache.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can REST API seed return Task ID

petrbizon opened this issue · comments

Hello,

Can REST API seed return Task ID?

I understood from documentation, that I can check tasks over API. The resulting array contain task IDs, but I dont know the task ID to pair.

I tried send post with seed request over Postman and response body is empty.

Can somebody help me please?

Thank You.

Petr B.

I change the code in version 1.22.x so:

Here
https://github.com/GeoWebCache/geowebcache/blob/1.22.x/geowebcache/core/src/main/java/org/geowebcache/seed/TileBreeder.java
I changed the seed metod that now return GWCTask array:

    public GWCTask[] seed(final String layerName, final SeedRequest sr)
            throws GeoWebCacheException {

        TileLayer tl = findTileLayer(layerName);

        TileRange tr = createTileRange(sr, tl);

        GWCTask[] tasks =
                createTasks(tr, tl, sr.getType(), sr.getThreadCount(), sr.getFilterUpdate());

        dispatchTasks(tasks);

        return tasks;
    }

and here:
https://github.com/GeoWebCache/geowebcache/blob/1.22.x/geowebcache/rest/src/main/java/org/geowebcache/rest/service/SeedService.java
I changed the doSeeding metod that now return array of task Id:

    public ResponseEntity<?> doSeeding(
            HttpServletRequest request, String layer, String extension, String body) {
        XStream xs = configXStream(new GeoWebCacheXStream(new DomDriver()));

        Object obj = null;

        try {
            if (extension == null || extension.equalsIgnoreCase("xml")) {
                obj = xs.fromXML(body);
            } else if (extension.equalsIgnoreCase("json")) {
                obj = xs.fromXML(convertJson(body));
            } else {
                throw new RestException(
                        "Format extension unknown or not specified: " + extension,
                        HttpStatus.BAD_REQUEST);
            }
            List<Long> taskIds = handleRequest(layer, obj);
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.TEXT_PLAIN);
            return new ResponseEntity<>(taskIds.toString(), headers, HttpStatus.OK);
            // return new ResponseEntity<>(headers, HttpStatus.OK);
        } catch (IOException e) {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.TEXT_PLAIN);
            return new ResponseEntity<>(headers, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
    protected List<Long> handleRequest(String layerName, Object obj) {
        final SeedRequest sr = (SeedRequest) obj;
        try {
            GWCTask[] tasks = seeder.seed(layerName, sr);

            List<Long> taskIds =
                    Arrays.stream(tasks).map(GWCTask::getTaskId).collect(Collectors.toList());
            return taskIds;

        } catch (IllegalArgumentException e) {
            throw new RestException(e.getMessage(), HttpStatus.BAD_REQUEST);
        } catch (GeoWebCacheException e) {
            throw new RestException(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

After this my action Geoserver get memory leak. It takes 8 GB RAM. Is it joined with my action please?