@Override protected GMLInfo getGMLConfig(WFSInfo wfs) { return wfs.getGML().get(WFSInfo.Version.V_10); } }
@Override protected GMLInfo getGMLConfig(WFSInfo wfs) { return wfs.getGML().get(WFSInfo.Version.V_11); } }
void addGml(WFSInfo info, WFSInfo.Version ver, SrsNameStyle srs, boolean overrideGmlAtts) { GMLInfo gml = new GMLInfoImpl(); gml.setSrsNameStyle(srs); gml.setOverrideGMLAttributes(overrideGmlAtts); info.getGML().put(ver, gml); } }
public DomainType getSrsParameter(WFSInfo wfs) { List<String> extraSRS = wfs.getSRS(); Set<String> srsParameterValues; GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_20); String prefix = gml.getSrsNameStyle().getPrefix(); Function<String, String> epsgMapper = srs -> qualifySRS(prefix, srs); if (extraSRS != null && !extraSRS.isEmpty()) { srsParameterValues = extraSRS.stream() .map(epsgMapper) .collect(Collectors.toCollection(LinkedHashSet::new)); } else { srsParameterValues = new LinkedHashSet<>(); } // add values from feature types gs.getCatalog() .getFeatureTypes() .forEach( ft -> { String srs = epsgMapper.apply(ft.getSRS()); srsParameterValues.add(srs); }); // build the parameter DomainType srsParameter = new DomainType("srsName", new ArrayList<>(srsParameterValues)); return srsParameter; }
if (service.getGML() == null) { ((WFSInfoImpl) service).setGML(new HashMap<WFSInfo.Version, GMLInfo>()); GMLInfo gml = service.getGML().get(WFSInfo.Version.V_10); if (gml == null) { addGml(service, WFSInfo.Version.V_10, SrsNameStyle.URL, false); gml.setOverrideGMLAttributes(true); gml = service.getGML().get(WFSInfo.Version.V_11); if (gml == null) { addGml(service, WFSInfo.Version.V_11, SrsNameStyle.URN, false); gml.setOverrideGMLAttributes(false); gml = service.getGML().get(WFSInfo.Version.V_20); if (gml == null) { addGml(service, WFSInfo.Version.V_20, SrsNameStyle.URN2, false);
@Test public void testGmlCreateFromScratch() throws Exception { WFSXStreamLoader loader = GeoServerExtensions.bean(WFSXStreamLoader.class); WFSInfo wfs = loader.createServiceFromScratch(null); assertNotNull(wfs); assertTrue(wfs.getGML().containsKey(WFSInfo.Version.V_10)); assertTrue(wfs.getGML().containsKey(WFSInfo.Version.V_11)); assertTrue(wfs.getGML().containsKey(WFSInfo.Version.V_20)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (!(obj instanceof WFSInfo)) return false; final WFSInfo other = (WFSInfo) obj; if (gml == null) { if (other.getGML() != null) return false; } else if (!gml.equals(other.getGML())) return false; if (maxFeatures != other.getMaxFeatures()) return false; if (featureBounding != other.isFeatureBounding()) return false; if (canonicalSchemaLocation != other.isCanonicalSchemaLocation()) return false; if (serviceLevel == null) { if (other.getServiceLevel() != null) return false; } else if (!serviceLevel.equals(other.getServiceLevel())) return false; if (encodeFeatureMember != other.isEncodeFeatureMember()) return false; if (hitsIgnoreMaxFeatures != other.isHitsIgnoreMaxFeatures()) return false; if (srs == null) { if (other.getSRS() != null) return false; } else if (!srs.equals(other.getSRS())) return false; return true; } }
@Override public Response responseDispatched( Request request, Operation operation, Object result, Response response) { Service service = operation.getService(); if (service == null || service.getId() == null || !service.getId().equalsIgnoreCase("wfs")) { // not a WFS service so we are not interested in it return response; } String responseMimeType = response.getMimeType(result, operation); if (!isGmlBased(responseMimeType)) { // no a GML based response return response; } WFSInfo wfs = geoserver.getService(WFSInfo.class); GMLInfo gmlInfo = wfs.getGML().get(WFSInfo.Version.negotiate(service.getVersion().toString())); if (gmlInfo == null || !gmlInfo.getMimeTypeToForce().isPresent()) { // we don't need to force any specific MIME type return response; } // enforce the configured MIME type String mimeType = gmlInfo.getMimeTypeToForce().get(); LOGGER.info( String.format( "Overriding MIME type '%s' with '%s' for WFS operation '%s'.", responseMimeType, mimeType, operation.getId())); return new ResponseWrapper(response, mimeType); }
/** * Helper method that just sets the GML 3.2 MIME type to force. If NULL is provided then GML * MIME type overriding will be deactivated. This changes will be applied to WFS global * configuration. */ protected void setGmlMimeTypeOverride(String mimeTypeToForce) { WFSInfo info = getGeoServer().getService(WFSInfo.class); GMLInfo gmlInfo = info.getGML().get(WFSInfo.Version.V_20); gmlInfo.setMimeTypeToForce(mimeTypeToForce); getGeoServer().save(info); }
@Override protected Configuration customizeConfiguration( Configuration configuration, Map<String, Set<ResourceInfo>> resources, Object request) { FeatureTypeSchemaBuilder schemaBuilder = new FeatureTypeSchemaBuilder.GML32(geoServer); ApplicationSchemaXSD2 xsd = new ApplicationSchemaXSD2(schemaBuilder); xsd.setBaseURL(GetFeatureRequest.adapt(request).getBaseURL()); xsd.setResources(resources); org.geotools.wfs.v2_0.WFSConfiguration wfs = new org.geotools.wfs.v2_0.WFSConfiguration(); wfs.getDependency(GMLConfiguration.class) .setSrsSyntax( getInfo() .getGML() .get(WFSInfo.Version.V_20) .getSrsNameStyle() .toSrsSyntax()); ApplicationSchemaConfiguration2 config = new ApplicationSchemaConfiguration2(xsd, wfs); // adding properties from original configuration to allow // hints handling config.getProperties().addAll(configuration.getProperties()); return config; }
void doTestSrsNameSyntax(SrsNameStyle srsNameStyle, boolean doSave) throws Exception { if (doSave) { WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_20); gml.setSrsNameStyle(srsNameStyle); getGeoServer().save(wfs); } String q = "wfs?request=getfeature&service=wfs&version=2.0.0&typenames=cgf:Points"; Document d = getAsDOM(q); assertEquals("wfs:FeatureCollection", d.getDocumentElement().getNodeName()); XMLAssert.assertXpathExists( "//gml:Envelope[@srsName = '" + srsNameStyle.getPrefix() + "32615']", d); XMLAssert.assertXpathExists( "//gml:Point[@srsName = '" + srsNameStyle.getPrefix() + "32615']", d); } }
void doTestSrsNameSyntax11(SrsNameStyle srsNameStyle, boolean doSave) throws Exception { if (doSave) { WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_11); gml.setSrsNameStyle(srsNameStyle); getGeoServer().save(wfs); } String q = "wfs?request=getfeature&service=wfs&version=1.1.0&typename=cgf:Points"; Document d = getAsDOM(q); assertEquals("wfs:FeatureCollection", d.getDocumentElement().getNodeName()); XMLAssert.assertXpathExists( "//gml:Envelope[@srsName = '" + srsNameStyle.getPrefix() + "32615']", d); XMLAssert.assertXpathExists( "//gml:Point[@srsName = '" + srsNameStyle.getPrefix() + "32615']", d); } }
GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_10); transformer.setGmlPrefixing(wfs.isCiteCompliant() || !gml.getOverrideGMLAttributes());
@Test public void testGMLAttributeMapping() throws Exception { WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_11); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs); Document dom = getAsDOM( "ows?service=WFS&version=1.1.0&request=DescribeFeatureType" + "&typename=" + getLayerId(CiteTestData.PRIMITIVEGEOFEATURE)); XMLAssert.assertXpathNotExists("//xsd:element[@name = 'name']", dom); XMLAssert.assertXpathNotExists("//xsd:element[@name = 'description']", dom); wfs = getWFS(); gml = wfs.getGML().get(WFSInfo.Version.V_11); gml.setOverrideGMLAttributes(true); getGeoServer().save(wfs); wfs = getWFS(); gml = wfs.getGML().get(WFSInfo.Version.V_11); assertTrue(gml.getOverrideGMLAttributes()); dom = getAsDOM( "ows?service=WFS&version=1.1.0&request=DescribeFeatureType" + "&typename=" + getLayerId(CiteTestData.PRIMITIVEGEOFEATURE)); XMLAssert.assertXpathExists("//xsd:element[@name = 'name']", dom); XMLAssert.assertXpathExists("//xsd:element[@name = 'description']", dom); }
GMLInfo gmlInfo = info.getGML().get(WFSInfo.Version.V_20); gmlInfo.setMimeTypeToForce(null); getGeoServer().save(info); gmlInfo = info.getGML().get(WFSInfo.Version.V_20); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); gmlInfo = info.getGML().get(WFSInfo.Version.V_20); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); assertThat(gmlInfo.getMimeTypeToForce().get(), is("text/xml")); gmlInfo = info.getGML().get(WFSInfo.Version.V_20); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(false));
GMLInfo gmlInfo = info.getGML().get(WFSInfo.Version.V_20); gmlInfo.setMimeTypeToForce(null); getGeoServer().save(info); gmlInfo = info.getGML().get(WFSInfo.Version.V_20); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); gmlInfo = info.getGML().get(WFSInfo.Version.V_20); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); assertThat(gmlInfo.getMimeTypeToForce().get(), is("text/xml")); gmlInfo = info.getGML().get(WFSInfo.Version.V_20); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(false));
@Test public void testInsertPreserveId() throws Exception { WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_20); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs);
@Test public void testGMLAttributeMapping() throws Exception { WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_11); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs); Document dom = getAsDOM( "ows?service=WFS&version=2.0.0&request=DescribeFeatureType" + "&typename=" + getLayerId(CiteTestData.PRIMITIVEGEOFEATURE)); assertSchema(dom, CiteTestData.PRIMITIVEGEOFEATURE); XMLAssert.assertXpathNotExists("//xsd:element[@name = 'name']", dom); XMLAssert.assertXpathNotExists("//xsd:element[@name = 'description']", dom); gml.setOverrideGMLAttributes(true); dom = getAsDOM( "ows?service=WFS&version=2.0.0&request=DescribeFeatureType" + "&typename=" + getLayerId(CiteTestData.PRIMITIVEGEOFEATURE)); assertSchema(dom, CiteTestData.PRIMITIVEGEOFEATURE); XMLAssert.assertXpathExists("//xsd:element[@name = 'name']", dom); XMLAssert.assertXpathExists("//xsd:element[@name = 'description']", dom); }
@Test public void testGMLAttributeMapping() throws Exception { WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_11); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs); Document dom = getAsDOM( "ows?service=WFS&version=2.0.0&request=GetFeature" + "&typename=" + getLayerId(MockData.PRIMITIVEGEOFEATURE)); XMLAssert.assertXpathExists("//gml:name", dom); XMLAssert.assertXpathExists("//gml:description", dom); XMLAssert.assertXpathNotExists("//sf:name", dom); XMLAssert.assertXpathNotExists("//sf:description", dom); gml.setOverrideGMLAttributes(true); getGeoServer().save(wfs); dom = getAsDOM( "ows?service=WFS&version=2.0.0&request=GetFeature" + "&typename=" + getLayerId(MockData.PRIMITIVEGEOFEATURE)); XMLAssert.assertXpathNotExists("//gml:name", dom); XMLAssert.assertXpathNotExists("//gml:description", dom); XMLAssert.assertXpathExists("//sf:name", dom); XMLAssert.assertXpathExists("//sf:description", dom); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs); }
@Test public void testGMLAttributeMapping() throws Exception { WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_11); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs); Document dom = getAsDOM( "ows?service=WFS&version=1.1.0&request=GetFeature" + "&typename=" + getLayerId(SystemTestData.PRIMITIVEGEOFEATURE)); assertXpathExists("//gml:name", dom); assertXpathExists("//gml:description", dom); XMLAssert.assertXpathNotExists("//sf:name", dom); XMLAssert.assertXpathNotExists("//sf:description", dom); gml.setOverrideGMLAttributes(true); getGeoServer().save(wfs); dom = getAsDOM( "ows?service=WFS&version=1.1.0&request=GetFeature" + "&typename=" + getLayerId(SystemTestData.PRIMITIVEGEOFEATURE)); XMLAssert.assertXpathNotExists("//gml:name", dom); XMLAssert.assertXpathNotExists("//gml:description", dom); assertXpathExists("//sf:name", dom); assertXpathExists("//sf:description", dom); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs); }