diff --git a/src/community/wms-eo/src/main/java/applicationContext.xml b/src/community/wms-eo/src/main/java/applicationContext.xml index 0bcca8766e1..29098b86a71 100755 --- a/src/community/wms-eo/src/main/java/applicationContext.xml +++ b/src/community/wms-eo/src/main/java/applicationContext.xml @@ -13,7 +13,7 @@ - + diff --git a/src/community/wms-eo/src/main/java/org/geoserver/wms/eo/XMLFeatureInfoOutputFormat.java b/src/community/wms-eo/src/main/java/org/geoserver/wms/eo/XMLFeatureInfoOutputFormat.java index a6238cc68a4..f61aedbae15 100755 --- a/src/community/wms-eo/src/main/java/org/geoserver/wms/eo/XMLFeatureInfoOutputFormat.java +++ b/src/community/wms-eo/src/main/java/org/geoserver/wms/eo/XMLFeatureInfoOutputFormat.java @@ -7,7 +7,7 @@ import org.geoserver.wms.WMS; import org.geoserver.wms.featureinfo.GML3FeatureInfoOutputFormat; - +import org.geoserver.wfs.xml.GML3OutputFormat; /** * A GetFeatureInfo response handler specialized in producing xml data for a GetFeatureInfo request. @@ -25,7 +25,7 @@ public class XMLFeatureInfoOutputFormat extends GML3FeatureInfoOutputFormat { /** * Default constructor, sets up the supported output format string. */ - public XMLFeatureInfoOutputFormat(final WMS wms) { - super(wms, FORMAT); + public XMLFeatureInfoOutputFormat(final GML3OutputFormat outputFormat) { + super(outputFormat, FORMAT); } } \ No newline at end of file diff --git a/src/wms/src/main/java/applicationContext.xml b/src/wms/src/main/java/applicationContext.xml index 221d80af41a..d9f7a92379e 100644 --- a/src/wms/src/main/java/applicationContext.xml +++ b/src/wms/src/main/java/applicationContext.xml @@ -82,11 +82,11 @@ - + - + diff --git a/src/wms/src/main/java/org/geoserver/wms/featureinfo/GML3FeatureInfoOutputFormat.java b/src/wms/src/main/java/org/geoserver/wms/featureinfo/GML3FeatureInfoOutputFormat.java index ad6502f7dcb..31f015d44b5 100644 --- a/src/wms/src/main/java/org/geoserver/wms/featureinfo/GML3FeatureInfoOutputFormat.java +++ b/src/wms/src/main/java/org/geoserver/wms/featureinfo/GML3FeatureInfoOutputFormat.java @@ -18,30 +18,25 @@ import net.opengis.wfs.QueryType; import net.opengis.wfs.WfsFactory; -import org.geoserver.config.GeoServer; import org.geoserver.platform.Operation; import org.geoserver.platform.Service; import org.geoserver.platform.ServiceException; -import org.geoserver.wfs.xml.FeatureTypeSchemaBuilder; import org.geoserver.wfs.xml.GML3OutputFormat; -import org.geoserver.wfs.xml.v1_1_0.WFS; -import org.geoserver.wfs.xml.v1_1_0.WFSConfiguration; import org.geoserver.wms.GetFeatureInfoRequest; -import org.geoserver.wms.WMS; import org.geotools.feature.FeatureCollection; import org.geotools.gml2.bindings.GML2EncodingUtils; import org.opengis.feature.type.Name; /** * A GetFeatureInfo response handler specialized in producing GML 3 data for a GetFeatureInfo request. - * + * *

* This class does not deals directly with GML encoding. Instead, it works by taking the * FeatureResults produced in execute() and constructs a GetFeaturesResult * wich is passed to a GML2FeatureResponseDelegate, as if it where the result of a * GetFeature WFS request. *

- * + * * @author Niels Charlier */ public class GML3FeatureInfoOutputFormat extends GetFeatureInfoOutputFormat { @@ -50,26 +45,25 @@ public class GML3FeatureInfoOutputFormat extends GetFeatureInfoOutputFormat { */ public static final String FORMAT = "application/vnd.ogc.gml/3.1.1"; - private WMS wms; + private GML3OutputFormat outputFormat; /** * Default constructor, sets up the supported output format string. */ - public GML3FeatureInfoOutputFormat(final WMS wms) { - this(wms, FORMAT); + public GML3FeatureInfoOutputFormat(final GML3OutputFormat outputFormat) { + this(outputFormat, FORMAT); } - - protected GML3FeatureInfoOutputFormat(WMS wms, String format) { + + protected GML3FeatureInfoOutputFormat(GML3OutputFormat outputFormat, String format) { super(format); - this.wms = wms; + this.outputFormat = outputFormat; } /** * Takes the FeatureResults generated by the execute method in the * superclass and constructs a GetFeaturesResult wich is passed to a * GML2FeatureResponseDelegate. - * - * @see AbstractFeatureInfoResponse#writeTo(OutputStream) + * */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override @@ -82,25 +76,25 @@ public void write(FeatureCollectionType results, GetFeatureInfoRequest fInfoReq, // the 'request' object we'll pass to our OutputFormat GetFeatureType gfreq = WfsFactory.eINSTANCE.createGetFeatureType(); gfreq.setBaseUrl(fInfoReq.getBaseUrl()); - + for (int i=0; i < results.getFeature().size(); i++) { - + FeatureCollection fc = (FeatureCollection) results.getFeature().get(i); Name name = FeatureCollectionDecorator.getName(fc); QName qname = new QName(name.getNamespaceURI(), name.getLocalPart()); - + features.getFeature().add(fc); QueryType qt = WfsFactory.eINSTANCE.createQueryType(); - + qt.setTypeName(Collections.singletonList(qname)); - + String crs = GML2EncodingUtils.epsgCode(fc.getSchema().getCoordinateReferenceSystem()); if (crs != null) { final String srsName = "EPSG:" + crs; try { qt.setSrsName(new URI(srsName)); - + } catch (URISyntaxException e) { throw new ServiceException( "Unable to determite coordinate system for featureType " @@ -116,14 +110,7 @@ public void write(FeatureCollectionType results, GetFeatureInfoRequest fInfoReq, // accept it. Service serviceDesc = new Service("wms", null, null, Collections.EMPTY_LIST); Operation opDescriptor = new Operation("", serviceDesc, null, new Object[] { gfreq }); - - final GeoServer gs = wms.getGeoServer(); - - FeatureTypeSchemaBuilder sb = new FeatureTypeSchemaBuilder.GML3(gs); - WFSConfiguration configuration = new WFSConfiguration(gs, sb, new WFS(sb)); - - GML3OutputFormat format = new GML3OutputFormat(gs, configuration); - format.write(features, out, opDescriptor); + outputFormat.write(features, out, opDescriptor); } } diff --git a/src/wms/src/main/java/org/geoserver/wms/featureinfo/XML311FeatureInfoOutputFormat.java b/src/wms/src/main/java/org/geoserver/wms/featureinfo/XML311FeatureInfoOutputFormat.java index 3ecae655890..5914ea6e0e9 100644 --- a/src/wms/src/main/java/org/geoserver/wms/featureinfo/XML311FeatureInfoOutputFormat.java +++ b/src/wms/src/main/java/org/geoserver/wms/featureinfo/XML311FeatureInfoOutputFormat.java @@ -5,7 +5,7 @@ */ package org.geoserver.wms.featureinfo; -import org.geoserver.wms.WMS; +import org.geoserver.wfs.xml.GML3OutputFormat; /** * A GetFeatureInfo response handler specialized in producing GML 3.1.1 data for a GetFeatureInfo request. @@ -28,10 +28,10 @@ public class XML311FeatureInfoOutputFormat extends GML3FeatureInfoOutputFormat { /** * Default constructor, sets up the supported output format String. * - * @param wms WMS to use. + * @param outputFormat format to use */ - public XML311FeatureInfoOutputFormat(WMS wms) { - super(wms, FORMAT); + public XML311FeatureInfoOutputFormat(GML3OutputFormat outputFormat) { + super(outputFormat, FORMAT); } -} \ No newline at end of file +} diff --git a/src/wms/src/test/java/org/geoserver/wms/wms_1_3/GetFeatureInfoIntegrationTest.java b/src/wms/src/test/java/org/geoserver/wms/wms_1_3/GetFeatureInfoIntegrationTest.java index c2b898ae0ad..c724d1073b7 100644 --- a/src/wms/src/test/java/org/geoserver/wms/wms_1_3/GetFeatureInfoIntegrationTest.java +++ b/src/wms/src/test/java/org/geoserver/wms/wms_1_3/GetFeatureInfoIntegrationTest.java @@ -21,6 +21,7 @@ import org.custommonkey.xmlunit.XMLAssert; import org.custommonkey.xmlunit.XMLUnit; import org.custommonkey.xmlunit.XpathEngine; +import org.eclipse.xsd.XSDSchema; import org.geoserver.catalog.Catalog; import org.geoserver.catalog.LayerInfo; import org.geoserver.data.test.MockData; @@ -35,6 +36,7 @@ import org.geoserver.wms.featureinfo.TextFeatureInfoOutputFormat; import org.geoserver.wms.featureinfo.XML311FeatureInfoOutputFormat; import org.geoserver.wms.wms_1_1_1.CapabilitiesTest; +import org.geotools.filter.v1_1.OGC; import org.geotools.util.logging.Logging; import org.junit.Test; import org.w3c.dom.Document; @@ -840,4 +842,23 @@ public void testGetFeatureInfoOnLineStringsWithGenericGeometry() throws Exceptio assertThat(xpath.evaluate("boolean(//wfs:FeatureCollection/gml:featureMember/gs:genericLines[@fid='line.2'][gs:name='line2'])", result), is("true")); assertThat(xpath.evaluate("boolean(//wfs:FeatureCollection/gml:featureMember/gs:genericLines[@fid='line.3'][gs:name='line3'])", result), is("true")); } + + @Test + public void testSchemaLeak() throws Exception { + String layer = getLayerId(MockData.FORESTS); + String request = "wms?version=1.3.0&bbox=-0.002,-0.002,0.002,0.002&styles=&format=jpeg&info_format=" + GML3FeatureInfoOutputFormat.FORMAT + "&request=GetFeatureInfo&layers=" + + layer + "&query_layers=" + layer + "&width=20&height=20&i=10&j=10"; + // prime system, make sure everything is wired + getAsDOM(request); + + // count how many imports in the OGC filter schema + XSDSchema schema = OGC.getInstance().getSchema(); + int expectedImportCounts = schema.getReferencingDirectives().size(); + + // now check how many there are after anothe request, should not go up + getAsDOM(request); + int actualImportCounts = schema.getReferencingDirectives().size(); + assertEquals(expectedImportCounts, actualImportCounts); + } + }