@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); }
if (gml == null) { addGml(service, WFSInfo.Version.V_10, SrsNameStyle.URL, false); } else if (gml.getOverrideGMLAttributes() == null) { gml.setOverrideGMLAttributes(true); } else if (gml.getOverrideGMLAttributes() == null) { gml.setOverrideGMLAttributes(false);
public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof GMLInfo)) return false; final GMLInfo other = (GMLInfo) obj; if (srsNameStyle == null) { if (other.getSrsNameStyle() != null) return false; } else if (!srsNameStyle.equals(other.getSrsNameStyle())) return false; return true; }
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); } }
gmlInfo.setMimeTypeToForce(null); getGeoServer().save(info); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); assertThat(gmlInfo.getMimeTypeToForce().get(), is("text/xml")); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(false));
transformer.setGmlPrefixing(wfs.isCiteCompliant() || !gml.getOverrideGMLAttributes()); transformer.setSrsName(gml.getSrsNameStyle().getPrefix() + srs);
WFSInfo wfs = getWFS(); GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_20); gml.setOverrideGMLAttributes(false); getGeoServer().save(wfs); getGeoServer().reset(); 200); } finally { gml.setOverrideGMLAttributes(true); getGeoServer().save(wfs);
/** * 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); }
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); } }
if (gml == null || !gml.getOverrideGMLAttributes()) { continue;
gmlInfo.setMimeTypeToForce(null); getGeoServer().save(info); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(true)); assertThat(gmlInfo.getMimeTypeToForce().get(), is("text/xml")); assertThat(gmlInfo.getMimeTypeToForce().isPresent(), is(false));
gml.setOverrideGMLAttributes(true); gml.setSrsNameStyle(SrsNameStyle.XML); } else { gml.setSrsNameStyle(SrsNameStyle.NORMAL); gml.setSrsNameStyle(SrsNameStyle.URN); gml.setOverrideGMLAttributes(false); wfs.getGML().put(WFSInfo.Version.V_11, gml); gml.setSrsNameStyle(SrsNameStyle.URN2); gml.setOverrideGMLAttributes(false); wfs.getGML().put(WFSInfo.Version.V_20, gml);
@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); }
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); } }
@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); }
private String applySRSNameStyle(GMLInfo gml, String srs) { if (srs != null) { String prefix = gml.getSrsNameStyle().getPrefix(); if (srs.matches("(?ui)EPSG:[0-9]+")) { srs = prefix + srs.substring(5); } else { srs = prefix + srs; } } return srs; }
@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); }
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; }
@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); }
wfs.getGML().get(WFSInfo.Version.V_11).getSrsNameStyle().toSrsSyntax());