hello all, 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:
Feb 13, 2009 12:37:16 PM org.geotools.xml.XMLSAXHandler processException
SEVERE: Too few children
org.geotools.xml.wfs.WFSCapabilitiesComplexTypes$OperationsType.getValue(WFSCapabilitiesComplexTypes.java:475)
org.geotools.xml.handlers.ComplexElementHandler.endElement(ComplexElementHandler.java:185)
org.geotools.xml.XMLSAXHandler.endElement(XMLSAXHandler.java:265)
org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown
Source)
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
org.geotools.xml.DocumentFactory.getInstance(DocumentFactory.java:139)
org.geotools.data.wfs.WFSDataStore.findCapabilities(WFSDataStore.java:223)
org.geotools.data.wfs.WFSDataStore.<init>(WFSDataStore.java:204)
org.geotools.data.wfs.WFSDataStore.<init>(WFSDataStore.java:141)
org.geotools.data.wfs.WFSDataStoreFactory.createNewDataStore(WFSDataStoreFactory.java:213)
org.geotools.data.wfs.WFSDataStoreFactory.createDataStore(WFSDataStoreFactory.java:131)
org.geotools.data.DataStoreFinder.getDataStore(DataStoreFinder.java:91)
TestWFSGetFeature._test(TestWFSGetFeature.java:59)
TestWFSGetFeature.testVersion1_1(TestWFSGetFeature.java:52)
...
Feb 13, 2009 12:37:16 PM org.geotools.xml.XMLSAXHandler endElement
WARNING: Too few children
Feb 13, 2009 12:37:16 PM org.geotools.xml.XMLSAXHandler endElement
WARNING: Line 7 Col 3129
Feb 13, 2009 12:37:16 PM org.geotools.data.wfs.WFSDataStoreFactory
createNewDataStore
WARNING: org.xml.sax.SAXException: Too few children
Feb 13, 2009 12:37:16 PM org.geotools.data.DataStoreFinder getDataStore
WARNING: Could not acquire The WFSDataStore represents a connection to a Web
Feature Server. This connection provides access to the Features published by
the server, and the ability to perform transactions on the server (when
supported / allowed).:java.io.IOException: org.xml.sax.SAXException: Too few
children
java.io.IOException: org.xml.sax.SAXException: Too few children
at
org.geotools.data.wfs.WFSDataStoreFactory.createNewDataStore(WFSDataStoreFactory.java:217)
at
org.geotools.data.wfs.WFSDataStoreFactory.createDataStore(WFSDataStoreFactory.java:131)
at
org.geotools.data.DataStoreFinder.getDataStore(DataStoreFinder.java:91)
at TestWFSGetFeature._test(TestWFSGetFeature.java:59)
at TestWFSGetFeature.testVersion1_1(TestWFSGetFeature.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
some info on my environment follows --the JDK has the JAI and
ImageIO extensions installed:
$ uname -a
Linux solomon 2.6.26.8-57.fc8 #1 SMP Thu Dec 18 19:19:45 EST 2008 i686 i686
i386 GNU/Linux
$ java -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
and finally the test case:
// 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.AttributeType;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.FeatureType;
import org.geotools.filter.FilterFactoryImpl;
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 wfsCapabilitiesURL_1_0 =
"http://localhost:8080/geoserver/wfs?SERVICE=WFS&REQUEST=GetCapabilities";
private final String wfsCapabilitiesURL_1_1 =
wfsCapabilitiesURL_1_0 + "&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", wfsCapabilitiesURL_1_0);
_test(connectionParams);
}
public void testVersion1_1() throws IOException {
// Step 1 - connection parameters
final Map<String, String> connectionParams = new HashMap<String, String>();
connectionParams.put(
"WFSDataStoreFactory:GET_CAPABILITIES_URL", wfsCapabilitiesURL_1_1);
_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 FeatureType schema = ds.getSchema(layerName);
assertNotNull("Feature type (schema) MUST NOT be null", schema);
final AttributeType[] attributes = schema.getAttributeTypes();
assertNotNull("Attributes array MUST NOT be null", attributes);
assertTrue("Attributes array MUST contain at least 2 elements",
attributes.length > 1);
final String atName = ATTRIBUTE_NAME;
boolean found = false;
for (final AttributeType attribute : attributes)
if (attribute.getLocalName().equals(atName)) {
found = true;
break;
}
assertTrue(
"Attribute named [" + atName + "] MUST be in the Attributes array",
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);
}
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 featureSource = dataStore.getFeatureSource(featureName);
final FeatureCollection fc = featureSource.getFeatures(query);
FeatureIterator fit = null;
int result = 0;
try {
for (fit = fc.features(); fit.hasNext(); ) {
final Feature 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;
}
}
TIA + 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
