@Test public void testGetLayerConfigFromWmsCapabilities_InvalidRequestUrl() throws Exception { WmsCapabilities wmsCapabilities = getBoilerPlateWmsCapabilities(); PowerMockito.when(wmsCapabilities.getCapability().getRequest().getGetMap().getGetUrl()).thenReturn(null); WmsLayer wmsLayer = wmsCapabilities.getNamedLayer(DEFAULT_LAYER_NAME); List<WmsLayer> layerCapabilities = Arrays.asList(wmsLayer); LayerFactory layerFactory = new LayerFactory(); try { WmsLayerConfig wmsLayerConfig = layerFactory.getLayerConfigFromWmsCapabilities(layerCapabilities); fail("Invalid Request URL"); } catch (RuntimeException e) { assertNotNull("Invalid Request URL", e); } }
protected WmsLayerConfig getLayerConfigFromWmsCapabilities(List<WmsLayer> wmsLayers) { WmsLayerConfig wmsLayerConfig = new WmsLayerConfig(); WmsCapabilities wmsCapabilities = wmsLayers.get(0).getCapability().getCapabilities(); String version = wmsCapabilities.getVersion(); if (version.equals("1.3.0")) { wmsLayerConfig.wmsVersion = version; } else if (version.equals("1.1.1")) { wmsLayerConfig.wmsVersion = version; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Version not compatible")); } String requestUrl = wmsCapabilities.getCapability().getRequest().getGetMap().getGetUrl(); if (requestUrl == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Unable to resolve GetMap URL")); } else { wmsLayerConfig.serviceAddress = requestUrl; } StringBuilder sb = null; Set<String> matchingCoordinateSystems = null; for (WmsLayer wmsLayer : wmsLayers) { String layerName = wmsLayer.getName(); if (sb == null) { sb = new StringBuilder(layerName); } else { sb.append(",").append(layerName); } List<String> wmsLayerCoordinateSystems = wmsLayer.getReferenceSystems(); if (matchingCoordinateSystems == null) { matchingCoordinateSystems = new HashSet<>(); matchingCoordinateSystems.addAll(wmsLayerCoordinateSystems); } else { matchingCoordinateSystems.retainAll(wmsLayerCoordinateSystems); } } wmsLayerConfig.layerNames = sb.toString(); if (matchingCoordinateSystems.contains("EPSG:4326")) { wmsLayerConfig.coordinateSystem = "EPSG:4326"; } else if (matchingCoordinateSystems.contains("CRS:84")) { wmsLayerConfig.coordinateSystem = "CRS:84"; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Coordinate systems not compatible")); } List<String> imageFormats = wmsCapabilities.getCapability().getRequest().getGetMap().getFormats(); for (String compatibleImageFormat : this.compatibleImageFormats) { if (imageFormats.contains(compatibleImageFormat)) { wmsLayerConfig.imageFormat = compatibleImageFormat; break; } } if (wmsLayerConfig.imageFormat == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Image Formats Not Compatible")); } return wmsLayerConfig; }
LayerFactory { protected WmsLayerConfig getLayerConfigFromWmsCapabilities(List<WmsLayer> wmsLayers) { WmsLayerConfig wmsLayerConfig = new WmsLayerConfig(); WmsCapabilities wmsCapabilities = wmsLayers.get(0).getCapability().getCapabilities(); String version = wmsCapabilities.getVersion(); if (version.equals("1.3.0")) { wmsLayerConfig.wmsVersion = version; } else if (version.equals("1.1.1")) { wmsLayerConfig.wmsVersion = version; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Version not compatible")); } String requestUrl = wmsCapabilities.getCapability().getRequest().getGetMap().getGetUrl(); if (requestUrl == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Unable to resolve GetMap URL")); } else { wmsLayerConfig.serviceAddress = requestUrl; } StringBuilder sb = null; Set<String> matchingCoordinateSystems = null; for (WmsLayer wmsLayer : wmsLayers) { String layerName = wmsLayer.getName(); if (sb == null) { sb = new StringBuilder(layerName); } else { sb.append(",").append(layerName); } List<String> wmsLayerCoordinateSystems = wmsLayer.getReferenceSystems(); if (matchingCoordinateSystems == null) { matchingCoordinateSystems = new HashSet<>(); matchingCoordinateSystems.addAll(wmsLayerCoordinateSystems); } else { matchingCoordinateSystems.retainAll(wmsLayerCoordinateSystems); } } wmsLayerConfig.layerNames = sb.toString(); if (matchingCoordinateSystems.contains("EPSG:4326")) { wmsLayerConfig.coordinateSystem = "EPSG:4326"; } else if (matchingCoordinateSystems.contains("CRS:84")) { wmsLayerConfig.coordinateSystem = "CRS:84"; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Coordinate systems not compatible")); } List<String> imageFormats = wmsCapabilities.getCapability().getRequest().getGetMap().getFormats(); for (String compatibleImageFormat : this.compatibleImageFormats) { if (imageFormats.contains(compatibleImageFormat)) { wmsLayerConfig.imageFormat = compatibleImageFormat; break; } } if (wmsLayerConfig.imageFormat == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Image Formats Not Compatible")); } return wmsLayerConfig; } }
LayerFactory { protected WmsLayerConfig getLayerConfigFromWmsCapabilities(List<WmsLayer> wmsLayers) { WmsLayerConfig wmsLayerConfig = new WmsLayerConfig(); WmsCapabilities wmsCapabilities = wmsLayers.get(0).getCapability().getCapabilities(); String version = wmsCapabilities.getVersion(); if (version.equals("1.3.0")) { wmsLayerConfig.wmsVersion = version; } else if (version.equals("1.1.1")) { wmsLayerConfig.wmsVersion = version; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Version not compatible")); } String requestUrl = wmsCapabilities.getCapability().getRequest().getGetMap().getGetUrl(); if (requestUrl == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Unable to resolve GetMap URL")); } else { wmsLayerConfig.serviceAddress = requestUrl; } StringBuilder sb = null; Set<String> matchingCoordinateSystems = null; for (WmsLayer wmsLayer : wmsLayers) { String layerName = wmsLayer.getName(); if (sb == null) { sb = new StringBuilder(layerName); } else { sb.append(",").append(layerName); } List<String> wmsLayerCoordinateSystems = wmsLayer.getReferenceSystems(); if (matchingCoordinateSystems == null) { matchingCoordinateSystems = new HashSet<>(); matchingCoordinateSystems.addAll(wmsLayerCoordinateSystems); } else { matchingCoordinateSystems.retainAll(wmsLayerCoordinateSystems); } } wmsLayerConfig.layerNames = sb.toString(); if (matchingCoordinateSystems.contains("EPSG:4326")) { wmsLayerConfig.coordinateSystem = "EPSG:4326"; } else if (matchingCoordinateSystems.contains("CRS:84")) { wmsLayerConfig.coordinateSystem = "CRS:84"; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Coordinate systems not compatible")); } List<String> imageFormats = wmsCapabilities.getCapability().getRequest().getGetMap().getFormats(); for (String compatibleImageFormat : this.compatibleImageFormats) { if (imageFormats.contains(compatibleImageFormat)) { wmsLayerConfig.imageFormat = compatibleImageFormat; break; } } if (wmsLayerConfig.imageFormat == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Image Formats Not Compatible")); } return wmsLayerConfig; } LayerFactory(); }
LayerFactory { protected WmsLayerConfig getLayerConfigFromWmsCapabilities(List<WmsLayer> wmsLayers) { WmsLayerConfig wmsLayerConfig = new WmsLayerConfig(); WmsCapabilities wmsCapabilities = wmsLayers.get(0).getCapability().getCapabilities(); String version = wmsCapabilities.getVersion(); if (version.equals("1.3.0")) { wmsLayerConfig.wmsVersion = version; } else if (version.equals("1.1.1")) { wmsLayerConfig.wmsVersion = version; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Version not compatible")); } String requestUrl = wmsCapabilities.getCapability().getRequest().getGetMap().getGetUrl(); if (requestUrl == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Unable to resolve GetMap URL")); } else { wmsLayerConfig.serviceAddress = requestUrl; } StringBuilder sb = null; Set<String> matchingCoordinateSystems = null; for (WmsLayer wmsLayer : wmsLayers) { String layerName = wmsLayer.getName(); if (sb == null) { sb = new StringBuilder(layerName); } else { sb.append(",").append(layerName); } List<String> wmsLayerCoordinateSystems = wmsLayer.getReferenceSystems(); if (matchingCoordinateSystems == null) { matchingCoordinateSystems = new HashSet<>(); matchingCoordinateSystems.addAll(wmsLayerCoordinateSystems); } else { matchingCoordinateSystems.retainAll(wmsLayerCoordinateSystems); } } wmsLayerConfig.layerNames = sb.toString(); if (matchingCoordinateSystems.contains("EPSG:4326")) { wmsLayerConfig.coordinateSystem = "EPSG:4326"; } else if (matchingCoordinateSystems.contains("CRS:84")) { wmsLayerConfig.coordinateSystem = "CRS:84"; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Coordinate systems not compatible")); } List<String> imageFormats = wmsCapabilities.getCapability().getRequest().getGetMap().getFormats(); for (String compatibleImageFormat : this.compatibleImageFormats) { if (imageFormats.contains(compatibleImageFormat)) { wmsLayerConfig.imageFormat = compatibleImageFormat; break; } } if (wmsLayerConfig.imageFormat == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Image Formats Not Compatible")); } return wmsLayerConfig; } LayerFactory(); Layer createFromGeoPackage(String pathName, Callback callback); Layer createFromWms(String serviceAddress, String layerName, Callback callback); Layer createFromWms(String serviceAddress, List<String> layerNames, Callback callback); Layer createFromWmsLayerCapabilities(WmsLayer layerCapabilities, Callback callback); Layer createFromWmsLayerCapabilities(List<WmsLayer> layerCapabilities, Callback callback); Layer createFromWmts(String serviceAddress, String layerIdentifier, Callback callback); Layer createFromWmtsLayer(WmtsLayer wmtsLayer, Callback callback); }
LayerFactory { protected WmsLayerConfig getLayerConfigFromWmsCapabilities(List<WmsLayer> wmsLayers) { WmsLayerConfig wmsLayerConfig = new WmsLayerConfig(); WmsCapabilities wmsCapabilities = wmsLayers.get(0).getCapability().getCapabilities(); String version = wmsCapabilities.getVersion(); if (version.equals("1.3.0")) { wmsLayerConfig.wmsVersion = version; } else if (version.equals("1.1.1")) { wmsLayerConfig.wmsVersion = version; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Version not compatible")); } String requestUrl = wmsCapabilities.getCapability().getRequest().getGetMap().getGetUrl(); if (requestUrl == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Unable to resolve GetMap URL")); } else { wmsLayerConfig.serviceAddress = requestUrl; } StringBuilder sb = null; Set<String> matchingCoordinateSystems = null; for (WmsLayer wmsLayer : wmsLayers) { String layerName = wmsLayer.getName(); if (sb == null) { sb = new StringBuilder(layerName); } else { sb.append(",").append(layerName); } List<String> wmsLayerCoordinateSystems = wmsLayer.getReferenceSystems(); if (matchingCoordinateSystems == null) { matchingCoordinateSystems = new HashSet<>(); matchingCoordinateSystems.addAll(wmsLayerCoordinateSystems); } else { matchingCoordinateSystems.retainAll(wmsLayerCoordinateSystems); } } wmsLayerConfig.layerNames = sb.toString(); if (matchingCoordinateSystems.contains("EPSG:4326")) { wmsLayerConfig.coordinateSystem = "EPSG:4326"; } else if (matchingCoordinateSystems.contains("CRS:84")) { wmsLayerConfig.coordinateSystem = "CRS:84"; } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Coordinate systems not compatible")); } List<String> imageFormats = wmsCapabilities.getCapability().getRequest().getGetMap().getFormats(); for (String compatibleImageFormat : this.compatibleImageFormats) { if (imageFormats.contains(compatibleImageFormat)) { wmsLayerConfig.imageFormat = compatibleImageFormat; break; } } if (wmsLayerConfig.imageFormat == null) { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLayerConfigFromWmsCapabilities", "Image Formats Not Compatible")); } return wmsLayerConfig; } LayerFactory(); Layer createFromGeoPackage(String pathName, Callback callback); Layer createFromWms(String serviceAddress, String layerName, Callback callback); Layer createFromWms(String serviceAddress, List<String> layerNames, Callback callback); Layer createFromWmsLayerCapabilities(WmsLayer layerCapabilities, Callback callback); Layer createFromWmsLayerCapabilities(List<WmsLayer> layerCapabilities, Callback callback); Layer createFromWmts(String serviceAddress, String layerIdentifier, Callback callback); Layer createFromWmtsLayer(WmtsLayer wmtsLayer, Callback callback);  }