Source:
private int getFeatureCountFromWFS11Request(Operation operation, WFSInfo wfs) throws IOException { final FilterFactory2 FF = CommonFactoryFinder.getFilterFactory2(null); int totalCount = 0; Catalog catalog = wfs.getGeoServer().getCatalog(); GetFeatureType request = (GetFeatureType) operation.getParameters()[0]; List<Map<String, String>> viewParams = new GetFeatureRequest.WFS11(request).getViewParams(); int idx = 0; for (QueryType query : (EList<QueryType>) request.getQuery()) { QName typeName = (QName) query.getTypeName().get(0); FeatureTypeInfo meta = catalog.getFeatureTypeByName(typeName.getNamespaceURI(), typeName.getLocalPart()); FeatureSource<? extends FeatureType, ? extends Feature> source = meta.getFeatureSource( null, null); Filter filter = query.getFilter(); if (filter == null) { filter = Filter.INCLUDE; } else if (filter instanceof org.geotools.filter.spatial.AbstractPreparedGeometryFilter){ CoordinateReferenceSystem crs = source.getSchema().getCoordinateReferenceSystem(); if(crs != null) { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(FF, source.getSchema()); filter = (Filter) filter.accept(reprojector, null); } } Query countQuery = new Query(typeName.getLocalPart(), filter); Map<String, String> viewParam = viewParams != null && viewParams.size() > idx ? viewParams .get(idx) : null; if (viewParam != null) { final Hints hints = new Hints(); hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, viewParam); countQuery.setHints(hints); } int count = 0; count = source.getCount(countQuery); if (count == -1) { org.geotools.data.Query gtQuery = new org.geotools.data.Query(countQuery); FeatureCollection<? extends FeatureType, ? extends Feature> features = source .getFeatures(gtQuery); count = features.size(); } totalCount +=count; } return totalCount; }

Target:
private int getFeatureCountFromWFS11Request(Operation operation, WFSInfo wfs) throws IOException { final FilterFactory2 FF = CommonFactoryFinder.getFilterFactory2(null); int totalCount = 0; Catalog catalog = wfs.getGeoServer().getCatalog(); GetFeatureType request = (GetFeatureType) operation.getParameters()[0]; List<Map<String, String>> viewParams = new GetFeatureRequest.WFS11(request).getViewParams(); int idx = 0; for (QueryType query : (EList<QueryType>) request.getQuery()) { QName typeName = (QName) query.getTypeName().get(0); FeatureTypeInfo meta = catalog.getFeatureTypeByName(typeName.getNamespaceURI(), typeName.getLocalPart()); FeatureSource<? extends FeatureType, ? extends Feature> source = meta.getFeatureSource( null, null); Filter filter = query.getFilter(); if (filter == null) { filter = Filter.INCLUDE; } else { ReprojectingFilterVisitor reprojector = new ReprojectingFilterVisitor(FF, source.getSchema()); filter = (Filter) filter.accept(reprojector, null); } Query countQuery = new Query(typeName.getLocalPart(), filter); Map<String, String> viewParam = viewParams != null && viewParams.size() > idx ? viewParams .get(idx) : null; if (viewParam != null) { final Hints hints = new Hints(); hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, viewParam); countQuery.setHints(hints); } int count = 0; count = source.getCount(countQuery); if (count == -1) { org.geotools.data.Query gtQuery = new org.geotools.data.Query(countQuery); FeatureCollection<? extends FeatureType, ? extends Feature> features = source .getFeatures(gtQuery); count = features.size(); } totalCount +=count; } return totalCount; }