private void capabilityLayerOuter(StringBuilder str) { str.append(" <Layer>\n"); str.append(" <Title>GeoWebCache WMS</Title>\n"); str.append( " <Abstract>Note that not all GeoWebCache instances provide a full WMS service.</Abstract>\n"); str.append( " <LatLonBoundingBox minx=\"-180.0\" miny=\"-90.0\" maxx=\"180.0\" maxy=\"90.0\"/>\n"); Iterable<TileLayer> layerIter = tld.getLayerList(); for (TileLayer layer : layerIter) { if (!layer.isEnabled()) { continue; } try { capabilityLayerInner(str, layer); } catch (GeoWebCacheException e) { log.error(e.getMessage()); } } str.append(" </Layer>\n"); }
private void capabilityVendorSpecific(StringBuilder str) { str.append(" <VendorSpecificCapabilities>\n"); Iterable<TileLayer> layerIter = tld.getLayerList(); for (TileLayer layer : layerIter) { if (!layer.isEnabled()) { continue; } for (String gridSetId : layer.getGridSubsets()) { GridSubset grid = layer.getGridSubset(gridSetId); List<String> formats = new ArrayList<String>(2); if (layer.getMimeTypes() != null) { for (MimeType mime : layer.getMimeTypes()) { formats.add(mime.getFormat()); } } else { formats.add(ImageMime.png.getFormat()); formats.add(ImageMime.jpeg.getFormat()); } List<String> styles = getStyles(layer.getParameterFilters()); for (String format : formats) { for (String style : styles) { try { capabilityVendorSpecificTileset(str, layer, grid, format, style); } catch (GeoWebCacheException e) { log.error(e.getMessage()); } } } } } str.append(" </VendorSpecificCapabilities>\n"); }
/** * Initializes the layer, creating internal structures for calculating grid location and so forth. * * <p>Subclasses shall implement {@link #initializeInternal(GridSetBroker)} for anything else */ @Override public final boolean initialize(GridSetBroker gridSetBroker) { if (this.expireCacheList == null) { this.expireCacheList = new ArrayList<ExpirationRule>(1); if (this.expireCache == null) { expireCacheList.add(new ExpirationRule(0, GWCVars.CACHE_NEVER_EXPIRE)); } else { int expireCacheInt = Integer.parseInt(expireCache); if (expireCacheInt == GWCVars.CACHE_USE_WMS_BACKEND_VALUE) { saveExpirationHeaders = true; } expireCacheList.add(new ExpirationRule(0, expireCacheInt)); } } if (this.expireClientsList == null) { this.expireClientsList = new ArrayList<ExpirationRule>(1); if (this.expireClients == null) { expireClientsList.add(new ExpirationRule(0, 7200)); } else { int expireClientsInt = Integer.parseInt(expireClients); if (expireClientsInt == GWCVars.CACHE_USE_WMS_BACKEND_VALUE) { saveExpirationHeaders = true; } else if (expireClientsInt == GWCVars.CACHE_NEVER_EXPIRE) { // One year should do expireClientsInt = 3600 * 24 * 365; } expireClientsList.add(new ExpirationRule(0, expireClientsInt)); } } try { // mimetypes this.formats = new ArrayList<MimeType>(); if (mimeFormats != null) { for (String fmt : mimeFormats) { formats.add(MimeType.createFromFormat(fmt)); } } if (formats.size() == 0) { formats.add(0, MimeType.createFromFormat("image/png")); formats.add(1, MimeType.createFromFormat("image/jpeg")); } } catch (GeoWebCacheException gwce) { log.error(gwce.getMessage()); gwce.printStackTrace(); } if (subSets == null) { subSets = new HashMap<String, GridSubset>(); } if (this.gridSubsets != null) { Iterator<XMLGridSubset> iter = gridSubsets.iterator(); while (iter.hasNext()) { XMLGridSubset xmlGridSubset = iter.next(); GridSubset gridSubset = xmlGridSubset.getGridSubSet(gridSetBroker); if (gridSubset == null) { log.error( xmlGridSubset.getGridSetName() + " is not known by the GridSetBroker, skipping for layer " + name); } else { subSets.put(gridSubset.getName(), gridSubset); } } this.gridSubsets = null; } // Convert version 1.1.x and 1.0.x grid objects if (grids != null && !grids.isEmpty()) { Iterator<XMLOldGrid> iter = grids.values().iterator(); while (iter.hasNext()) { GridSubset converted = iter.next().convertToGridSubset(gridSetBroker); subSets.put(converted.getSRS().toString(), converted); } // Null it for the garbage collector grids = null; } if (this.subSets.size() == 0) { subSets.put( gridSetBroker.WORLD_EPSG4326.getName(), GridSubsetFactory.createGridSubSet(gridSetBroker.WORLD_EPSG4326)); subSets.put( gridSetBroker.WORLD_EPSG3857.getName(), GridSubsetFactory.createGridSubSet(gridSetBroker.WORLD_EPSG3857)); } return initializeInternal(gridSetBroker); }
/** * Method responsible for handling incoming POSTs. It will parse the XML document and deserialize * it into a SeedRequest, then create a SeedTask and forward it to the thread pool executor. */ public void doPost(Request req, Response resp) throws RestletException, IOException { String formatExtension = (String) req.getAttributes().get("extension"); SeedRequest sr = null; XStream xs = xmlConfig.getConfiguredXStream(new XStream(new DomDriver())); try { if (formatExtension.equalsIgnoreCase("xml")) { String xml_body = req.getEntity().getText(); log.debug("doPost, xml = " + xml_body); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); ByteArrayInputStream xml_bs = new ByteArrayInputStream(xml_body.getBytes()); Document doc = db.parse(xml_bs); Node rootNode = doc.getFirstChild(); xs.alias("seedRequest", SeedRequest.class); sr = (SeedRequest) xs.unmarshal(new DomReader((Element) rootNode)); log.debug("doPost, sr = " + sr.getLayerName()); } else if (formatExtension.equalsIgnoreCase("json")) { sr = (SeedRequest) xs.fromXML(convertJson(req.getEntity().getText())); } else { throw new RestletException( "Format extension unknown or not specified: " + formatExtension, Status.CLIENT_ERROR_BAD_REQUEST); } } catch (Exception e) { log.error("Exception type = " + e.getClass().getName() + " msg = " + e.getMessage()); e.printStackTrace(); if (e.getCause() != null) { log.error("cause = " + e.getCause().getMessage()); } } StringBuilder strBld = new StringBuilder(); strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); String layerName = null; try { layerName = URLDecoder.decode((String) req.getAttributes().get("layer"), "UTF-8"); } catch (UnsupportedEncodingException uee) { log.error("Exception type = " + uee.getClass().getName() + " msg = " + uee.getMessage()); throw new RestletException(uee.getMessage(), Status.SERVER_ERROR_INTERNAL); } log.debug( "layerName = " + layerName + " sr.GridSetId = " + sr.getGridSetId() + " type = " + sr.getType()); GWCTask[] tasks = null; try { TileLayer tl = null; try { tl = seeder.findTileLayer(layerName); } catch (GeoWebCacheException e) { strBld.append("<GeoWebCacheException>"); strBld.append(e.getMessage()); strBld.append("</GeoWebCacheException>"); resp.setEntity(strBld.toString(), MediaType.TEXT_XML); throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL); } TileRange tr = TileBreeder.createTileRange(sr, tl); tasks = seeder.createTasks(tr, tl, sr.getType(), sr.getThreadCount(), sr.getFilterUpdate()); seeder.dispatchTasks(tasks); // Give the thread executor a chance to run try { Thread.sleep(500); } catch (InterruptedException e) { // Ok, no worries } } catch (IllegalArgumentException e) { log.error("IllegalArgumentException occured: " + e.getMessage()); throw new RestletException(e.getMessage(), Status.CLIENT_ERROR_BAD_REQUEST); } catch (GeoWebCacheException e) { log.error("GeoWebCacheException occured: " + e.getMessage()); throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL); } strBld.append("<Tasks>"); if (tasks.length == 0) { log.debug("No running tasks"); } for (int i = 0; i < tasks.length; i++) { if (i > 0) { strBld.append(","); } strBld.append(tasks[i].getDbId()); } strBld.append("</Tasks>\n"); log.debug("post response = " + strBld.toString()); resp.setEntity(strBld.toString(), MediaType.TEXT_XML); }