FeatureSource<SimpleFeatureType, SimpleFeature> source = layer.getResource(FeatureSource.class, ProgressManager.instance().get());
SimpleFeatureType schema=source.getSchema();
//FilterFactory fac=CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
//final List<String> queryAtts = obtainQueryAttributesForFeatureTable(schema);
Set<String> required = (Set<String>) filter.accept( new FilterAttributeExtractor(), null );
String[] names = required.toArray( new String[ required.size()]);
final DefaultQuery query=new DefaultQuery(schema.getName().getLocalPart(), filter, names );
FeatureCollection<SimpleFeatureType, SimpleFeature> features;
features = source.getFeatures( query ); // we just want the FeatureID no attributes needed