/** * Handles the encoding of the layers elements. * * <p>This method does a search over the SRS of all the layers to see if there are at least a * common one, as needed by the spec: "<i>The root Layer element shall include a sequence of * zero or more <SRS> elements listing all SRSes that are common to all subsidiary layers. * Use a single SRS element with empty content (like so: "<SRS></SRS>") if there is * no common SRS."</i> * * <p>By the other hand, this search is also used to collecto the whole latlon bbox, as stated * by the spec: <i>"The bounding box metadata in Capabilities XML specify the minimum enclosing * rectangle for the layer as a whole."</i> * * @task TODO: manage this differently when we have the layer list of the WMS service decoupled * from the feature types configured for the server instance. (This involves nested layers, * gridcoverages, etc) */ private void handleLayers() { start("Layer"); final List<LayerInfo> layers; // filter the layers if a namespace filter has been set if (request.getNamespace() != null) { final List<LayerInfo> allLayers = wmsConfig.getLayers(); layers = new ArrayList<LayerInfo>(); String namespace = wmsConfig.getNamespaceByPrefix(request.getNamespace()); for (LayerInfo layer : allLayers) { Name name = layer.getResource().getQualifiedName(); if (name.getNamespaceURI().equals(namespace)) { layers.add(layer); } } } else { layers = wmsConfig.getLayers(); } WMSInfo serviceInfo = wmsConfig.getServiceInfo(); element("Title", serviceInfo.getTitle()); element("Abstract", serviceInfo.getAbstract()); List<String> srsList = serviceInfo.getSRS(); Set<String> srs = new HashSet<String>(); if (srsList != null) { srs.addAll(srsList); } handleRootCrsList(srs); handleRootBbox(layers); // now encode each layer individually LayerTree featuresLayerTree = new LayerTree(layers); handleLayerTree(featuresLayerTree); try { List<LayerGroupInfo> layerGroups = wmsConfig.getLayerGroups(); handleLayerGroups(new ArrayList<LayerGroupInfo>(layerGroups)); } catch (FactoryException e) { throw new RuntimeException("Can't obtain Envelope of Layer-Groups: " + e.getMessage(), e); } catch (TransformException e) { throw new RuntimeException("Can't obtain Envelope of Layer-Groups: " + e.getMessage(), e); } end("Layer"); }
/** * Before using {@code gwc-gs.xml} to hold the integrated GWC configuration, the only property * configured was whether the direct WMS integration option was enabled, and it was saved as part * of the {@link WMSInfo} metadata map under the {@code GWC_WMS_Integration} key. This method * removes that key from WMSInfo if present and sets its value to the {@code gwcConfig} instead. */ private void upgradeWMSIntegrationConfig(final GeoServer geoServer, final GWCConfig gwcConfig) throws IOException { // Check whether we're using the old way of storing this information, and get rid of it WMSInfo service = geoServer.getService(WMSInfo.class); if (service != null) { MetadataMap metadata = service.getMetadata(); if (service != null && metadata != null) { Boolean storedValue = metadata.get(WMS_INTEGRATION_ENABLED_KEY, Boolean.class); if (storedValue != null) { boolean enabled = storedValue.booleanValue(); gwcConfig.setDirectWMSIntegrationEnabled(enabled); metadata.remove(WMS_INTEGRATION_ENABLED_KEY); geoServer.save(service); } } } }
public void testRootLayer() throws Exception { WMSInfo serviceInfo = getWMS().getServiceInfo(); addAuthUrl("rootAuth1", "http://geoserver/wms/auth1", serviceInfo.getAuthorityURLs()); addAuthUrl("rootAuth2", "http://geoserver/wms/auth2", serviceInfo.getAuthorityURLs()); addIdentifier("rootAuth1", "rootId1", serviceInfo.getIdentifiers()); addIdentifier("rootAuth2", "rootId2", serviceInfo.getIdentifiers()); getGeoServer().save(serviceInfo); Document doc = getAsDOM("/wms?service=WMS&request=getCapabilities&version=1.3.0", true); assertXpathExists( "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:AuthorityURL[@name = 'rootAuth1']", doc); assertXpathEvaluatesTo( "http://geoserver/wms/auth1", "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:AuthorityURL[@name = 'rootAuth1']/wms:OnlineResource/@xlink:href", doc); assertXpathExists( "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:AuthorityURL[@name = 'rootAuth2']", doc); assertXpathEvaluatesTo( "http://geoserver/wms/auth2", "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:AuthorityURL[@name = 'rootAuth2']/wms:OnlineResource/@xlink:href", doc); assertXpathExists( "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Identifier[@authority = 'rootAuth1']", doc); assertXpathEvaluatesTo( "rootId1", "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Identifier[@authority = 'rootAuth1']", doc); assertXpathExists( "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Identifier[@authority = 'rootAuth2']", doc); assertXpathEvaluatesTo( "rootId2", "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Identifier[@authority = 'rootAuth2']", doc); }
/** * Retrieves the WMS's capabilities document. * * @param scaleHintUnitsPerDiaPixel true if the scalehint must be in units per diagonal of a pixel * @return Capabilities as {@link Document} */ private Document findCapabilities(Boolean scaleHintUnitsPerDiaPixel) throws Exception { // set the Scalehint units per diagonal pixel setting. WMS wms = getWMS(); WMSInfo info = wms.getServiceInfo(); MetadataMap mm = info.getMetadata(); mm.put(WMS.SCALEHINT_MAPUNITS_PIXEL, scaleHintUnitsPerDiaPixel); info.getGeoServer().save(info); GetCapabilitiesTransformer tr = new GetCapabilitiesTransformer(wms, BASE_URL, FORMATS, LEGEND_FORMAT, null); GetCapabilitiesRequest req = new GetCapabilitiesRequest(); req.setBaseUrl(BASE_URL); req.setVersion(WMS.VERSION_1_1_1.toString()); Document dom = WMSTestSupport.transform(req, tr); Element root = dom.getDocumentElement(); Assert.assertEquals(WMS.VERSION_1_1_1.toString(), root.getAttribute("version")); return dom; }
@Override protected void setUpInternal() throws Exception { super.setUpInternal(); Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("xlink", "http://www.w3.org/1999/xlink"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); namespaces.put("wms", "http://www.opengis.net/wms"); namespaces.put("ows", "http://www.opengis.net/ows"); namespaces.put("ogc", "http://www.opengis.net/ogc"); namespaces.put("wfs", "http://www.opengis.net/wfs"); namespaces.put("gml", "http://www.opengis.net/gml"); namespaces.put(WCS_PREFIX, WCS_URI); NamespaceContext ctx = new SimpleNamespaceContext(namespaces); XMLUnit.setXpathNamespaceContext(ctx); Logging.getLogger("org.geoserver.ows").setLevel(Level.OFF); WMSInfo wmsInfo = getGeoServer().getService(WMSInfo.class); wmsInfo.setMaxBuffer(50); getGeoServer().save(wmsInfo); }
@Override public void encode(Translator tx, WMSInfo wms, GetCapabilitiesRequest request) throws IOException { Version requestVersion = WMS.version(request.getVersion()); // if this is not a wms 1.3.0 request if (!WMS.VERSION_1_3_0.equals(requestVersion)) { return; } MetadataMap serviceMetadata = wms.getMetadata(); Boolean createExtendedCapabilities = serviceMetadata.get(CREATE_EXTENDED_CAPABILITIES.key, Boolean.class); String metadataURL = (String) serviceMetadata.get(SERVICE_METADATA_URL.key); // Don't create extended capabilities element if mandatory content not present // or turned off if (metadataURL == null || createExtendedCapabilities != null && !createExtendedCapabilities) { return; } String mediaType = (String) serviceMetadata.get(SERVICE_METADATA_TYPE.key); String language = (String) serviceMetadata.get(LANGUAGE.key); // IGN : INSPIRE SCENARIO 1 tx.start("inspire_vs:ExtendedCapabilities"); tx.start("inspire_common:MetadataUrl"); tx.start("inspire_common:URL"); tx.chars(metadataURL); tx.end("inspire_common:URL"); if (mediaType != null) { tx.start("inspire_common:MediaType"); tx.chars(mediaType); tx.end("inspire_common:MediaType"); } tx.end("inspire_common:MetadataUrl"); tx.start("inspire_common:SupportedLanguages"); language = language != null ? language : "eng"; tx.start("inspire_common:DefaultLanguage"); tx.start("inspire_common:Language"); tx.chars(language); tx.end("inspire_common:Language"); tx.end("inspire_common:DefaultLanguage"); tx.end("inspire_common:SupportedLanguages"); tx.start("inspire_common:ResponseLanguage"); tx.start("inspire_common:Language"); tx.chars(language); tx.end("inspire_common:Language"); tx.end("inspire_common:ResponseLanguage"); tx.end("inspire_vs:ExtendedCapabilities"); }
/** Encodes the service metadata section of a WMS capabilities document. */ private void handleService() { start("Service"); final WMSInfo serviceInfo = wmsConfig.getServiceInfo(); element("Name", "OGC:WMS"); element("Title", serviceInfo.getTitle()); element("Abstract", serviceInfo.getAbstract()); handleKeywordList(serviceInfo.getKeywords()); AttributesImpl orAtts = new AttributesImpl(); orAtts.addAttribute("", "xmlns:xlink", "xmlns:xlink", "", XLINK_NS); orAtts.addAttribute(XLINK_NS, "xlink:type", "xlink:type", "", "simple"); String onlineResource = serviceInfo.getOnlineResource(); if (onlineResource == null || onlineResource.trim().length() == 0) { String requestBaseUrl = request.getBaseUrl(); onlineResource = buildURL(requestBaseUrl, null, null, URLType.SERVICE); } else { try { new URL(onlineResource); } catch (MalformedURLException e) { LOGGER.log( Level.WARNING, "WMS online resource seems to be an invalid URL: '" + onlineResource + "'"); } } orAtts.addAttribute("", "xlink:href", "xlink:href", "", onlineResource); element("OnlineResource", null, orAtts); GeoServer geoServer = wmsConfig.getGeoServer(); ContactInfo contact = geoServer.getGlobal().getContact(); handleContactInfo(contact); element("Fees", serviceInfo.getFees()); element("AccessConstraints", serviceInfo.getAccessConstraints()); end("Service"); }