WFS_1_1_0_DataStore implements WFSDataStore { public FeatureReader<SimpleFeatureType, SimpleFeature> getFeatureReader(Query query, final Transaction transaction) throws IOException { if (Filter.EXCLUDE.equals(query.getFilter())) { return new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(getQueryType(query)); } Filter[] filters = wfs.splitFilters(query.getFilter()); Filter supportedFilter = filters[0]; Filter postFilter = filters[1]; if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Supported filter: " + supportedFilter); LOGGER.fine("Unupported filter: " + postFilter); } query = createNewQuery(query, supportedFilter, postFilter); final CoordinateReferenceSystem queryCrs = query.getCoordinateSystem(); WFSResponse response = executeGetFeatures(query, transaction, ResultType.RESULTS); Object result = WFSExtensions.process(this, response, mappedURIs); GetFeatureParser parser; if (result instanceof WFSException) { throw (WFSException) result; } else if (result instanceof GetFeatureParser) { parser = (GetFeatureParser) result; } else { throw new IllegalStateException("Unknown response result for GetFeature: " + result); } final SimpleFeatureType contentType = getQueryType(query); FeatureReader<SimpleFeatureType, SimpleFeature> reader; reader = new WFSFeatureReader((GetFeatureParser) parser); if (!reader.hasNext()) { return new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(contentType); } final SimpleFeatureType readerType = reader.getFeatureType(); CoordinateReferenceSystem readerCrs = readerType.getCoordinateReferenceSystem(); String serverSrs = getServerSrs(query); if (queryCrs != null && serverSrs == null && !queryCrs.equals(readerCrs)) { try { reader = new ReprojectFeatureReader(reader, queryCrs); } catch (Exception e) { throw new DataSourceException(e); } } if(serverSrs != null) { try { reader = new ForceCoordinateSystemFeatureReader(reader, CRS.decode(serverSrs)); } catch (Exception e) { throw new DataSourceException(e); } } if (Filter.INCLUDE != postFilter) { reader = new FilteringFeatureReader<SimpleFeatureType, SimpleFeature>(reader, postFilter); } if (!contentType.equals(readerType)) { final boolean cloneContents = false; reader = new ReTypeFeatureReader(reader, contentType, cloneContents); } if (this.maxFeaturesHardLimit.intValue() > 0 || query.getMaxFeatures() != Integer.MAX_VALUE) { int maxFeatures = maxFeaturesHardLimit.intValue() > 0 ? Math.min( maxFeaturesHardLimit.intValue(), query.getMaxFeatures()) : query .getMaxFeatures(); reader = new MaxFeatureReader<SimpleFeatureType, SimpleFeature>(reader, maxFeatures); } return reader; } WFS_1_1_0_DataStore(final WFSProtocol wfs); void setMappedURIs(Map<String, String> mappedURIs); void setAxisOrder(String axisOrderOutput, String axisOrderFilter); String getAxisOrderForOutput(); String getAxisOrderForFilter(); void setNamespaceOverride(String namespaceOverride); void setMaxFeatures(Integer maxFeatures); Integer getMaxFeatures(); boolean isPreferPostOverGet(); void setPreferPostOverGet(Boolean booleanValue); WFSServiceInfo getInfo(); SimpleFeatureType getSchema(final String prefixedTypeName); SimpleFeatureType getSchema(Name name); List<Name> getNames(); String[] getTypeNames(); void dispose(); static boolean invertAxisNeeded(String axisOrder,
            CoordinateReferenceSystem crs); FeatureReader<SimpleFeatureType, SimpleFeature> getFeatureReader(Query query,
            final Transaction transaction); WFSFeatureSource getFeatureSource(final String typeName); LockingManager getLockingManager(); FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriter(String typeName,
            Filter filter, Transaction transaction); FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriter(String typeName,
            Transaction transaction); FeatureWriter<SimpleFeatureType, SimpleFeature> getFeatureWriterAppend(String typeName,
            Transaction transaction); SimpleFeatureSource getFeatureSource(Name typeName); void updateSchema(Name typeName, SimpleFeatureType featureType); void updateSchema(String typeName, SimpleFeatureType featureType); void createSchema(SimpleFeatureType featureType); QName getFeatureTypeName(String typeName); String getFeatureTypeTitle(String typeName); String getFeatureTypeAbstract(String typeName); ReferencedEnvelope getFeatureTypeWGS84Bounds(String typeName); ReferencedEnvelope getFeatureTypeBounds(String typeName); CoordinateReferenceSystem getFeatureTypeCRS(String typeName); Set<String> getFeatureTypeKeywords(String typeName); URL getDescribeFeatureTypeURL(String typeName); String getServiceAbstract(); Set<String> getServiceKeywords(); URI getServiceProviderUri(); URL getCapabilitiesURL(); String getServiceTitle(); String getServiceVersion(); ReferencedEnvelope getBounds(final Query query); int getCount(Query query); @Override String toString(); @Override void setUseDefaultSRS(Boolean useDefaultSRS); void setGetFeatureOutputFormat(String outputFormat); @Override void removeSchema(String typeName); @Override void removeSchema(Name typeName);  }
@Test public void tesUseDefaultSRS() throws IOException, NoSuchAuthorityCodeException, FactoryException { final InputStream dataStream = TestData.openStream(this, CUBEWERX_GOVUNITCE.DATA); TestHttpResponse httpResponse = new TestHttpResponse( "text/xml; subtype=gml/3.1.1", "UTF-8", dataStream); TestHttpProtocol mockHttp = new TestHttpProtocol(httpResponse); createTestProtocol(CUBEWERX_GOVUNITCE.CAPABILITIES, mockHttp); URL describeUrl = TestData.getResource(this, CUBEWERX_GOVUNITCE.SCHEMA); wfs.setDescribeFeatureTypeURLOverride(describeUrl); WFS_1_1_0_DataStore ds = new WFS_1_1_0_DataStore(wfs); Query query = new Query(CUBEWERX_GOVUNITCE.FEATURETYPENAME); CoordinateReferenceSystem otherCrs = CRS .decode(CUBEWERX_GOVUNITCE.ALTERNATIVECRS); query.setCoordinateSystem(otherCrs); FeatureReader<SimpleFeatureType, SimpleFeature> featureReader; featureReader = ds.getFeatureReader(query, Transaction.AUTO_COMMIT); assertNotNull(featureReader); assertTrue(featureReader instanceof ForceCoordinateSystemFeatureReader); assertEquals(otherCrs, featureReader.getFeatureType() .getCoordinateReferenceSystem()); GetFeature request = wfs.getRequest(); assertEquals(CUBEWERX_GOVUNITCE.ALTERNATIVECRS, request.getSrsName()); CoordinateReferenceSystem unknownCrs = CRS.decode("EPSG:3003"); query.setCoordinateSystem(unknownCrs); featureReader = ds.getFeatureReader(query, Transaction.AUTO_COMMIT); assertNotNull(featureReader); assertTrue(featureReader instanceof ReprojectFeatureReader); assertEquals(unknownCrs, featureReader.getFeatureType() .getCoordinateReferenceSystem()); request = wfs.getRequest(); assertEquals(CUBEWERX_GOVUNITCE.CRS, request.getSrsName()); }
@Test public void tesUseOtherSRSUsingURN() throws IOException, NoSuchAuthorityCodeException, FactoryException { final InputStream dataStream = TestData.openStream(this, CUBEWERX_GOVUNITCE.DATA); TestHttpResponse httpResponse = new TestHttpResponse( "text/xml; subtype=gml/3.1.1", "UTF-8", dataStream); TestHttpProtocol mockHttp = new TestHttpProtocol(httpResponse); createTestProtocol(CUBEWERX_GOVUNITCE.CAPABILITIES, mockHttp); URL describeUrl = TestData.getResource(this, CUBEWERX_GOVUNITCE.SCHEMA); wfs.setDescribeFeatureTypeURLOverride(describeUrl); WFS_1_1_0_DataStore ds = new WFS_1_1_0_DataStore(wfs); Query query = new Query(CUBEWERX_GOVUNITCE.FEATURETYPENAME); CoordinateReferenceSystem otherCrs = CRS.decode(CUBEWERX_GOVUNITCE.URNCRS); query.setCoordinateSystem(otherCrs); FeatureReader<SimpleFeatureType, SimpleFeature> featureReader; featureReader = ds.getFeatureReader(query, Transaction.AUTO_COMMIT); assertNotNull(featureReader); assertTrue(featureReader instanceof ForceCoordinateSystemFeatureReader); assertEquals(GML2EncodingUtils.epsgCode(otherCrs), GML2EncodingUtils.epsgCode(featureReader.getFeatureType() .getCoordinateReferenceSystem())); GetFeature request = wfs.getRequest(); assertEquals("urn:ogc:def:crs:EPSG::3857", request.getSrsName()); }
@Test public void tesGetFeatureReader() throws IOException { final InputStream dataStream = TestData.openStream(this, CUBEWERX_GOVUNITCE.DATA); TestHttpResponse httpResponse = new TestHttpResponse("text/xml; subtype=gml/3.1.1", "UTF-8", dataStream); TestHttpProtocol mockHttp = new TestHttpProtocol(httpResponse); createTestProtocol(CUBEWERX_GOVUNITCE.CAPABILITIES, mockHttp); URL describeUrl = TestData.getResource(this, CUBEWERX_GOVUNITCE.SCHEMA); wfs.setDescribeFeatureTypeURLOverride(describeUrl); WFS_1_1_0_DataStore ds = new WFS_1_1_0_DataStore(wfs); Query query = new Query(CUBEWERX_GOVUNITCE.FEATURETYPENAME); FeatureReader<SimpleFeatureType, SimpleFeature> featureReader; featureReader = ds.getFeatureReader(query, Transaction.AUTO_COMMIT); assertNotNull(featureReader); assertTrue(featureReader.hasNext()); assertNotNull(featureReader.next()); assertTrue(featureReader.hasNext()); assertNotNull(featureReader.next()); assertTrue(featureReader.hasNext()); assertNotNull(featureReader.next()); assertFalse(featureReader.hasNext()); }