@Test public void testParseMaplinkAndLayersWithGeoJSONFromJsonTest() throws IOException, ParseException, com.vividsolutions.jts.io.ParseException { XMLConfiguration config = shared.getConfig(); TileLayer tileLayer = config.getTileLayer(layerTemplate); GridSubset gridSubset = tileLayer.getGridSubset(gridSubsetName); MapLayerJSONParser layerJsonParser = new MapLayerJSONParser(props); MaplinkGeoJsonParser parser = new MaplinkGeoJsonParser(); parser.setDebug(true); InputStream inp = MapProducer.class.getResourceAsStream("geojsPrintTest.json"); try { assertTrue(MapLinkGeoJsonParseContext.Default.getPm().buildMap); Map<String, ?> root = parser.parse(inp); assertTrue(root.size() != 0); assertTrue(root.get("layers") != null); assertTrue(root.get("maplink") != null); assertTrue(root.get("state") != null); assertTrue(root.get("layers") != null); MapLink mapLink = layerJsonParser.parseMapLinkJSON(root, shared.getGf(), gridSubset.getResolutions()); assertTrue(mapLink != null); } finally { inp.close(); } }
/** * 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); }
@Test @SuppressWarnings({"rawtypes", "unchecked"}) public void testParseMaplinkAndLayersWithGeoJSONFromJsonEmbedded() throws IOException, ParseException, com.vividsolutions.jts.io.ParseException { XMLConfiguration config = shared.getConfig(); TileLayer tileLayer = config.getTileLayer(layerTemplate); GridSubset gridSubset = tileLayer.getGridSubset(gridSubsetName); MapLayerJSONParser layerJsonParser = new MapLayerJSONParser(props); MaplinkGeoJsonParser parser = new MaplinkGeoJsonParser(); parser.setDebug(true); InputStream inp = MapProducer.class.getResourceAsStream("action_route_parcel.json"); try { assertTrue(MapLinkGeoJsonParseContext.Default.getPm().buildMap); Map<String, ?> root = parser.parse(inp); assertTrue(root.size() != 0); assertTrue(root.get("layers") != null); assertTrue(root.get("maplink") != null); assertTrue(root.get("state") != null); assertTrue(root.get("layers") != null); assertTrue(((List<Map<String, Object>>) root.get("layers")).size() == 11); assertTrue( "geojson".equals(((List<Map<String, Object>>) root.get("layers")).get(10).get("type"))); assertTrue( ((List<Map<String, Object>>) root.get("layers")).get(10).get(".data") instanceof FeatureCollection); FeatureCollection fc10 = (FeatureCollection) ((List<Map<String, Object>>) root.get("layers")).get(10).get(".data"); FeatureIterator fi = fc10.features(); assertTrue(fi.hasNext()); Feature f = fc10.features().next(); assertTrue(f != null); assertTrue(f.getProperty("prop0") != null); assertTrue(f.getProperty("prop0").getValue() != null); Object pv = f.getProperty("prop0").getValue(); assertTrue(pv instanceof String); assertTrue("value0forPoints".equals(pv)); assertTrue(f.getDefaultGeometryProperty() != null); GeometryAttribute g = f.getDefaultGeometryProperty(); assertTrue(g.getValue() != null); Object gv = g.getValue(); assertTrue(gv instanceof Point); Point pt = (Point) gv; System.out.println(pt.toText()); Style style = null; new FeatureLayer(fc10, style); MapLink mapLink = layerJsonParser.parseMapLinkJSON(root, shared.getGf(), gridSubset.getResolutions()); /* assertions */ assertTrue(mapLink != null); assertTrue(mapLink.getScale() != null); assertTrue(mapLink.getCentre() != null); assertTrue(Double.valueOf(530163).equals(mapLink.getCentre().getX())); assertTrue(Double.valueOf(6754057).equals(mapLink.getCentre().getY())); assertTrue(Integer.valueOf(11).equals(mapLink.getZoom())); assertTrue(mapLink.getMapLinkLayers() != null); assertTrue(mapLink.getMapLinkLayers().size() == 4); assertTrue("base_35".equals(mapLink.getMapLinkLayers().get(0).getLayerid())); assertTrue(mapLink.getMapLinkLayers().get(0).getGeom() == null); } finally { inp.close(); } }