hello all, as an update on this issue: using GeoTools 2.5.3 (instead of 2.4.4) and communicating with a GeoServer 1.6.4b, i was able to get the test case running (a) without exceptions, and (b) demonstrating proper handling of the 'matchCase' attribute in string-based comparison filters when using WFS version 1.1.0 even on a shapefile based data store. i'm including at the end an updated version of the test case in the hope that it may be of help to somebody else facing the same situation.
On Fri, 13 Feb 2009 12:56:28 pm Raif S. Naffah wrote:
> ...
> i recently learned on the GeoServer users list that string equality
> with ignore case (in WFS Filters) only work with WFS 1.1.0. i'm
> trying to replicate programatically the Demo Request sample for
> WFS_getFeature for both 1.0 and 1.1 versions but i'm having problems
> with the latter version, and would appreciate any push in the right
> direction. i'm thinking it cannot be a missing JAR since the WFS 1.0
> test does not cause a parsing exception but i could be wrong.
>
> with a GeoServer 1.6.4b (using the same version of the gt2 libraries;
> i.e. 2.4.4) the test-case at the end demonstrates what i'm trying to
> do. it works as expected for WFS 1.0 but throws the following
> exception for WFS 1.1:
// default package
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.DefaultQuery;
import org.geotools.data.FeatureSource;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.filter.FilterFactoryImpl;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.PropertyIsEqualTo;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;
/**
* Test literal string case matching for WFS 1.0 and 1.1.
*/
public class TestWFSGetFeature extends TestCase {
private final String BASE_URL =
"http://localhost:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetCapabilities";
private final String CAPABILITIES_1_0 = BASE_URL + "&VERSION=1.0.0";
private final String CAPABILITIES_1_1 = BASE_URL + "&VERSION=1.1.0";
private final String LAYER_NAME = "topp:states";
private final String ATTRIBUTE_NAME = "STATE_NAME";
public void testVersion1_0() throws IOException {
// Step 1 - connection parameters
final Map<String, String> connectionParams = new HashMap<String, String>();
connectionParams.put(
"WFSDataStoreFactory:GET_CAPABILITIES_URL", CAPABILITIES_1_0);
_test(connectionParams);
}
@SuppressWarnings("unchecked")
public void testVersion1_1_AUTO() throws IOException {
// Step 1 - connection parameters
final Map connectionParams = new HashMap();
connectionParams.put(
"WFSDataStoreFactory:GET_CAPABILITIES_URL", CAPABILITIES_1_1);
connectionParams.put("WFSDataStoreFactory:PROTOCOL:", null);
_test(connectionParams);
}
@SuppressWarnings("unchecked")
public void testVersion1_1_GET() throws IOException {
// Step 1 - connection parameters
final Map connectionParams = new HashMap();
connectionParams.put(
"WFSDataStoreFactory:GET_CAPABILITIES_URL", CAPABILITIES_1_1);
connectionParams.put("WFSDataStoreFactory:PROTOCOL:", Boolean.FALSE);
_test(connectionParams);
}
@SuppressWarnings("unchecked")
public void testVersion1_1_POST() throws IOException {
// Step 1 - connection parameters
final Map connectionParams = new HashMap();
connectionParams.put(
"WFSDataStoreFactory:GET_CAPABILITIES_URL", CAPABILITIES_1_1);
connectionParams.put("WFSDataStoreFactory:PROTOCOL:", Boolean.TRUE);
_test(connectionParams);
}
public void _test(final Map<String, String> connectionParams)
throws IOException {
// Step 2 - connection
final DataStore ds = DataStoreFinder.getDataStore(connectionParams);
assertNotNull("Data store MUST NOT be null", ds);
// Step 3 - discovery
final List<String> typeNames = Arrays.asList(ds.getTypeNames());
assertNotNull("Type names MUST NOT be null", typeNames);
assertFalse("Type names MUST NOT be empty", typeNames.isEmpty());
final String layerName = LAYER_NAME;
assertTrue("Type names MUST contain [" + layerName + "]",
typeNames.contains(layerName));
final SimpleFeatureType schema = ds.getSchema(layerName);
assertNotNull("Feature type (schema) MUST NOT be null", schema);
final List<AttributeDescriptor> attributes =
schema.getAttributeDescriptors();
assertNotNull("Attributes list MUST NOT be null", attributes);
assertTrue("Attributes list MUST contain at least 2 elements",
attributes.size() > 1);
final String atName = ATTRIBUTE_NAME;
boolean found = false;
for (final AttributeDescriptor attribute : attributes)
if (attribute.getLocalName().equals(atName)) {
found = true;
break;
}
assertTrue("Attribute named [" + atName + "] MUST be found", found);
// Step 4 - query
final int r1 = process(ds, layerName, atName, "Delaware", true);
System.out.println("*** r1 = " + r1);
final int r2 = process(ds, layerName, atName, "DELAWARE", false);
System.out.println("*** r2 = " + r2);
assertEquals("MUST be able to find same feature", r1, r2);
}
private int process(final DataStore dataStore, final String featureName,
final String attributeName, final String literalValue,
final boolean matchCase)
throws IOException {
final FilterFactoryImpl ff = new FilterFactoryImpl();
final PropertyName property = ff.property(attributeName);
final Literal literal = ff.literal(literalValue);
final PropertyIsEqualTo equalFilter = ff.equal(property, literal,
matchCase);
final DefaultQuery query = new DefaultQuery(featureName, equalFilter);
final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
dataStore.getFeatureSource(featureName);
final FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
featureSource.getFeatures(query);
FeatureIterator<SimpleFeature> fit = null;
int result = 0;
try {
for (fit = fc.features(); fit.hasNext(); ) {
final SimpleFeature f = fit.next();
System.out.println("*** Processing feature: " + f);
result++;
}
} finally {
if (fit != null) fc.close(fit);
}
System.out.println("*** PropertyIsEqualTo filter, with "
+ (matchCase ? "match" : "ignore") + "-case, found "
+ result + " feature(s) with [" + literalValue
+ "] as the value of the [" + attributeName + "] attribute");
return result;
}
}
cheers;
rsn
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H
_______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
