From: <svn...@os...> - 2012-03-27 09:59:55
|
Author: aaime Date: 2012-03-27 02:59:43 -0700 (Tue, 27 Mar 2012) New Revision: 38649 Added: trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/ConnectionFactoryWrapper.java trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/HttpProtocolWrapper.java Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStore.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/MapServerWFSStrategy.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/NonStrictWFSStrategy.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/StrictWFSStrategy.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS100ProtocolHandler.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/GetFeatureQueryAdapter.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_DataStore.java trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/GeoServerOnlineTest.java trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/GeoServerOnlineTest.java Log: [GEOT-4092] Add support for vendor parameters in WFS data store Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStore.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStore.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/WFSDataStore.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -18,12 +18,14 @@ import java.net.URI; import java.net.URL; +import java.util.Map; import java.util.Set; import javax.xml.namespace.QName; import org.geotools.data.DataAccess; import org.geotools.data.DataStore; +import org.geotools.factory.Hints.ClassKey; import org.geotools.geometry.jts.ReferencedEnvelope; import org.opengis.referencing.crs.CoordinateReferenceSystem; @@ -41,7 +43,16 @@ * /data/wfs/WFSDataStore.java $ */ public interface WFSDataStore extends DataStore { + /** + * Provides the vendor parameters to be used in a query + * + * @since 2.7.5 + */ + public static final ClassKey WFS_VENDOR_PARAMETERS = new ClassKey(Map.class); + + + /** * Overrides {@link DataAccess#getInfo()} so it type narrows to a {@link WFSServiceInfo} * * @return service information Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/MapServerWFSStrategy.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/MapServerWFSStrategy.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/MapServerWFSStrategy.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -100,8 +100,8 @@ BBOX newFilter = fac.bbox(attName, bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY(), "EPSG:4326"); - query2=new Query(query.getTypeName(), query.getNamespace(), newFilter, - query.getMaxFeatures(), query.getPropertyNames(), query.getHandle()); + query2 = new Query(query); + query2.setFilter(newFilter); } } catch (IllegalFilterException e) { query2=query; Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/NonStrictWFSStrategy.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/NonStrictWFSStrategy.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/NonStrictWFSStrategy.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -24,6 +24,7 @@ import org.geotools.data.Query; import org.geotools.data.Transaction; import org.geotools.data.crs.ForceCoordinateSystemFeatureReader; +import org.geotools.data.wfs.protocol.http.HttpMethod; import org.geotools.feature.SchemaException; import org.geotools.filter.visitor.FixBBOXFilterVisitor; import org.geotools.referencing.CRS; @@ -98,10 +99,18 @@ protected FeatureReader<SimpleFeatureType, SimpleFeature> createFeatureReader(Transaction transaction, Query query) throws IOException { Data data; - data = createFeatureReaderPOST(query, transaction); - - if (data.reader == null) + + if(store.preferredProtocol == HttpMethod.POST) { + data = createFeatureReaderPOST(query, transaction); + + if (data.reader == null) + data = createFeatureReaderGET(query, transaction); + } else { data = createFeatureReaderGET(query, transaction); + + if (data.reader == null) + data = createFeatureReaderPOST(query, transaction); + } if (data.reader == null && data.saxException != null) throw (IOException) new IOException(data.saxException.toString()).initCause(data.saxException); Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/StrictWFSStrategy.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/StrictWFSStrategy.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/StrictWFSStrategy.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -158,12 +158,13 @@ if( visitor.requiresPostProcessing() && query.getPropertyNames()!=Query.ALL_NAMES){ FilterAttributeExtractor attributeExtractor=new FilterAttributeExtractor(); query.getFilter().accept( attributeExtractor, null ); - Set<String> properties=new HashSet<String>(attributeExtractor.getAttributeNameSet()); + Set<String> properties = new HashSet<String>(attributeExtractor.getAttributeNameSet()); properties.addAll(Arrays.asList(query.getPropertyNames())); - this.query=new Query(query.getTypeName(), query.getFilter(), query.getMaxFeatures(), - (String[]) properties.toArray(new String[0]), query.getHandle()); - }else + this.query = new Query(query); + this.query.setPropertyNames((String[]) properties.toArray(new String[0])); + } else { this.query=query; + } this.filter=visitor.getFilter(); Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS100ProtocolHandler.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS100ProtocolHandler.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS100ProtocolHandler.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -59,7 +59,7 @@ return super.connectionFac; } - private WFSCapabilities parseCapabilities(InputStream capabilitiesReader) throws IOException { + protected WFSCapabilities parseCapabilities(InputStream capabilitiesReader) throws IOException { // TODO: move to some 1.0.0 specific class Map<String,Object> hints = new HashMap<String,Object>(); hints.put(DocumentFactory.VALIDATION_HINT, Boolean.FALSE); Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_0_0/WFS_1_0_0_DataStore.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -579,6 +579,15 @@ String encode = URLEncoder.encode(print,protocolHandler.getEncoding()); url += "&FILTER=" + encode; } + + // inject vendor params, if any + if(request.getHints() != null && request.getHints().get(WFSDataStore.WFS_VENDOR_PARAMETERS) != null) { + Map<String, String> vendorParams = (Map<String, String>) request.getHints().get(WFSDataStore.WFS_VENDOR_PARAMETERS); + for (Map.Entry<String, String> entry : vendorParams.entrySet()) { + url += "&" + entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), protocolHandler + .getEncoding()); + } + } } } @@ -731,6 +740,30 @@ return null; } + // inject vendor params, if any + if(query != null && query.getHints() != null && query.getHints().get(WFSDataStore.WFS_VENDOR_PARAMETERS) != null) { + String url = postUrl.toString(); + if ((url == null) || !url.endsWith("?")) { + url += "?"; + } + + boolean first = true; + if(query.getHints() != null && query.getHints().get(WFSDataStore.WFS_VENDOR_PARAMETERS) != null) { + Map<String, String> vendorParams = (Map<String, String>) query.getHints().get(WFSDataStore.WFS_VENDOR_PARAMETERS); + for (Map.Entry<String, String> entry : vendorParams.entrySet()) { + if(first) { + first = false; + } else { + url += "&"; + } + url += entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), protocolHandler + .getEncoding()); + } + } + + postUrl = new URL(url); + } + HttpURLConnection hc = protocolHandler.getConnectionFactory().getConnection(postUrl, POST); Writer w = getOutputStream(hc); Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/GetFeatureQueryAdapter.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/GetFeatureQueryAdapter.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/GetFeatureQueryAdapter.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -16,7 +16,10 @@ */ package org.geotools.data.wfs.v1_1_0; +import java.util.Map; + import org.geotools.data.Query; +import org.geotools.data.wfs.WFSDataStore; import org.geotools.data.wfs.protocol.wfs.GetFeature; import org.opengis.filter.Filter; import org.opengis.filter.sort.SortBy; @@ -76,5 +79,13 @@ public SortBy[] getSortBy() { return query.getSortBy(); } + + public Map<String, String> getVendorParameter() { + if(query.getHints() != null) { + return (Map<String, String>) query.getHints().get(WFSDataStore.WFS_VENDOR_PARAMETERS); + } else { + return null; + } + } } Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_DataStore.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_DataStore.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_DataStore.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -108,7 +108,7 @@ */ private static final boolean DEFAULT_HTTP_METHOD = true; - private final WFSProtocol wfs; + protected WFSProtocol wfs; private Map<String, SimpleFeatureType> byTypeNameTypes; @@ -320,8 +320,8 @@ Filter[] filters = wfs.splitFilters(query.getFilter()); Filter supportedFilter = filters[0]; Filter postFilter = filters[1]; - System.out.println("Supported filter: " + supportedFilter); - System.out.println("Unupported filter: " + postFilter); + LOGGER.fine("Supported filter: " + supportedFilter); + LOGGER.fine("Unupported filter: " + postFilter); ((Query) query).setFilter(supportedFilter); ((Query) query).setMaxFeatures(getMaxFeatures(query)); Modified: trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java =================================================================== --- trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/main/java/org/geotools/data/wfs/v1_1_0/WFS_1_1_0_Protocol.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -16,9 +16,8 @@ */ package org.geotools.data.wfs.v1_1_0; -import static org.geotools.data.wfs.protocol.http.HttpMethod.GET; -import static org.geotools.data.wfs.protocol.http.HttpMethod.POST; -import static org.geotools.data.wfs.protocol.wfs.WFSOperationType.DESCRIBE_FEATURETYPE; +import static org.geotools.data.wfs.protocol.http.HttpMethod.*; +import static org.geotools.data.wfs.protocol.wfs.WFSOperationType.*; import java.io.File; import java.io.FileOutputStream; @@ -29,12 +28,12 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLEncoder; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -69,10 +68,6 @@ import org.apache.commons.io.IOUtils; import org.eclipse.emf.ecore.EObject; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDParser; -import org.eclipse.xsd.util.XSDSchemaLocationResolver; -import org.eclipse.xsd.util.XSDSchemaLocator; import org.geotools.data.DataSourceException; import org.geotools.data.Query; import org.geotools.data.wfs.protocol.http.HTTPProtocol; @@ -88,25 +83,16 @@ import org.geotools.data.wfs.v1_1_0.parsers.EmfAppSchemaParser; import org.geotools.filter.Capabilities; import org.geotools.geometry.jts.ReferencedEnvelope; -import org.geotools.gml3.smil.SMIL20; -import org.geotools.gml3.smil.SMIL20LANG; import org.geotools.referencing.crs.DefaultGeographicCRS; import org.geotools.util.logging.Logging; import org.geotools.wfs.WFS; -import org.geotools.wfs.v1_1.WFSConfiguration; -import org.geotools.xlink.XLINK; import org.geotools.xml.Configuration; import org.geotools.xml.Encoder; import org.geotools.xml.Parser; -import org.geotools.xml.SchemaLocationResolver; -import org.geotools.xml.SchemaLocator; -import org.geotools.xml.Schemas; -import org.geotools.xml.XSD; import org.opengis.feature.simple.SimpleFeatureType; import org.opengis.filter.Filter; import org.opengis.filter.capability.FilterCapabilities; import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.picocontainer.MutablePicoContainer; import org.xml.sax.SAXException; /** @@ -142,9 +128,9 @@ */ private final Map<String, FeatureTypeType> typeInfos; - private HTTPProtocol http; + protected HTTPProtocol http; - private final Charset defaultEncoding; + protected final Charset defaultEncoding; public WFS_1_1_0_Protocol(InputStream capabilitiesReader, HTTPProtocol http, Charset defaultEncoding) throws IOException { @@ -475,11 +461,18 @@ URL url = getOperationURL(WFSOperationType.GET_FEATURE, false); RequestComponents reqParts = strategy.createGetFeatureRequest(this, request); + GetFeatureType requestType = reqParts.getServerRequest(); + + // build the kvp taking into account eventual vendor params Map<String, String> getFeatureKvp = reqParts.getKvpParameters(); - GetFeatureType requestType = reqParts.getServerRequest(); + if(request instanceof GetFeatureQueryAdapter) { + GetFeatureQueryAdapter adapter = (GetFeatureQueryAdapter) request; + if(adapter.getVendorParameter() != null) { + getFeatureKvp.putAll(adapter.getVendorParameter()); + } + } + - System.out.println(" > getFeatureGET: Request url: " + url + ". Parameters: " - + getFeatureKvp); WFSResponse response = issueGetRequest(requestType, url, getFeatureKvp); return response; @@ -493,7 +486,30 @@ throw new UnsupportedOperationException( "The server does not support GetFeature for HTTP method POST"); } - URL url = getOperationURL(WFSOperationType.GET_FEATURE, true); + URL postURL = getOperationURL(WFSOperationType.GET_FEATURE, true); + + // support vendor parameters, GeoServer way + if(request instanceof GetFeatureQueryAdapter) { + GetFeatureQueryAdapter adapter = (GetFeatureQueryAdapter) request; + if(adapter.getVendorParameter() != null) { + String url = postURL.toString(); + if ((url == null) || !url.endsWith("?")) { + url += "?"; + } + + boolean first = true; + for (Map.Entry<String, String> entry : adapter.getVendorParameter().entrySet()) { + if(first) { + first = false; + } else { + url += "&"; + } + url += entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8"); + } + + postURL = new URL(url); + } + } RequestComponents reqParts = strategy.createGetFeatureRequest(this, request); GetFeatureType serverRequest = reqParts.getServerRequest(); @@ -509,7 +525,7 @@ if (!XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { encoder.getNamespaces().declarePrefix(prefix, namespace); } - WFSResponse response = issuePostRequest(serverRequest, url, encoder); + WFSResponse response = issuePostRequest(serverRequest, postURL, encoder); return response; } @@ -543,7 +559,7 @@ return typeInfos.get(typeName); } - private WFSCapabilitiesType parseCapabilities(InputStream capabilitiesReader) + protected WFSCapabilitiesType parseCapabilities(InputStream capabilitiesReader) throws IOException { final Configuration wfsConfig = strategy.getWfsConfiguration(); final Parser parser = new Parser(wfsConfig); Added: trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/ConnectionFactoryWrapper.java =================================================================== --- trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/ConnectionFactoryWrapper.java (rev 0) +++ trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/ConnectionFactoryWrapper.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -0,0 +1,54 @@ +package org.geotools.data.wfs.v1_0_0; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.Charset; + +import org.geotools.data.wfs.protocol.http.HttpMethod; +import org.geotools.wfs.protocol.ConnectionFactory; + +/** + * Helper class for the tests + * @author aaime + * + */ +public class ConnectionFactoryWrapper implements ConnectionFactory { + + public ConnectionFactory delegate; + + public ConnectionFactoryWrapper(ConnectionFactory delegate) { + this.delegate = delegate; + } + + public String getAuthUsername() { + return delegate.getAuthUsername(); + } + + public String getAuthPassword() { + return delegate.getAuthPassword(); + } + + public boolean isTryGzip() { + return delegate.isTryGzip(); + } + + public Charset getEncoding() { + return delegate.getEncoding(); + } + + public HttpURLConnection getConnection(URL query, HttpMethod method) throws IOException { + return delegate.getConnection(query, method); + } + + public InputStream getInputStream(HttpURLConnection hc) throws IOException { + return delegate.getInputStream(hc); + } + + public InputStream getInputStream(URL query, HttpMethod method) throws IOException { + return delegate.getInputStream(query, method); + } + + +} Modified: trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/GeoServerOnlineTest.java =================================================================== --- trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/GeoServerOnlineTest.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_0_0/GeoServerOnlineTest.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -17,13 +17,12 @@ */ package org.geotools.data.wfs.v1_0_0; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import java.io.IOException; import java.io.InputStream; import java.net.ConnectException; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.NoRouteToHostException; import java.net.URL; @@ -48,13 +47,17 @@ import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.data.simple.SimpleFeatureSource; import org.geotools.data.simple.SimpleFeatureStore; +import org.geotools.data.wfs.WFSDataStore; import org.geotools.data.wfs.WFSDataStoreFactory; +import org.geotools.data.wfs.protocol.http.HttpMethod; import org.geotools.factory.CommonFactoryFinder; import org.geotools.factory.GeoTools; +import org.geotools.factory.Hints; import org.geotools.feature.IllegalAttributeException; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.filter.IllegalFilterException; import org.geotools.geometry.jts.ReferencedEnvelope; +import org.geotools.wfs.protocol.ConnectionFactory; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -490,7 +493,75 @@ } } } + + @Test + public void testVendorParametersGet() throws Exception { + testVendorParameters(Boolean.FALSE); + } + + @Test + public void testVendorParametersPost() throws Exception { + testVendorParameters(Boolean.TRUE); + } + private void testVendorParameters(Boolean usePost) throws IOException { + if (url == null) + return; + + Map m = new HashMap(); + m.put(WFSDataStoreFactory.URL.key, url); + m.put(WFSDataStoreFactory.TIMEOUT.key, new Integer(100000)); + m.put(WFSDataStoreFactory.PROTOCOL.key, usePost); + WFS_1_0_0_DataStore wfs = (WFS_1_0_0_DataStore) (new WFSDataStoreFactory()) + .createDataStore(m); + + final WFS100ProtocolHandler originalHandler = wfs.protocolHandler; + wfs.protocolHandler = new WFS100ProtocolHandler(null, originalHandler.getConnectionFactory()) { + @Override + protected WFSCapabilities parseCapabilities(InputStream capabilitiesReader) + throws IOException { + return originalHandler.getCapabilities(); + } + + @Override + public ConnectionFactory getConnectionFactory() { + return new ConnectionFactoryWrapper(super.getConnectionFactory()) { + + @Override + public HttpURLConnection getConnection(URL query, HttpMethod method) + throws IOException { + String[] keyValueArray = query.getQuery().split("&"); + Map<String, String> kvp = new HashMap<String, String>(); + for (String keyValue : keyValueArray) { + String[] skv = keyValue.split("="); + kvp.put(skv[0], skv[1]); + } + + // check the vendor params actually made it into the url + assertEquals("true", kvp.get("strict")); + assertEquals("mysecret", kvp.get("authkey")); + assertEquals("low%3A2000000%3Bhigh%3A5000000", kvp.get("viewparams")); + + return super.getConnection(query, method); + } + }; + } + }; + + Map<String, String> vparams = new HashMap<String, String>(); + vparams.put("authkey", "mysecret"); + vparams.put("viewparams", "low:2000000;high:5000000"); + vparams.put("strict", "true"); + Hints hints = new Hints(WFSDataStore.WFS_VENDOR_PARAMETERS, vparams); + Query q = new Query("topp:states"); + q.setHints(hints); + + // try with + FeatureReader fr = wfs.getFeatureReader(q, Transaction.AUTO_COMMIT); + assertTrue(fr.hasNext()); + fr.close(); + } + private Id createFidFilter(SimpleFeatureSource fs) throws IOException { SimpleFeatureIterator iter = fs.getFeatures().features(); @@ -508,4 +579,6 @@ iter.close(); } } + + } Modified: trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/GeoServerOnlineTest.java =================================================================== --- trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/GeoServerOnlineTest.java 2012-03-27 09:50:39 UTC (rev 38648) +++ trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/GeoServerOnlineTest.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -17,19 +17,27 @@ */ package org.geotools.data.wfs.v1_1_0; -import static org.geotools.data.wfs.v1_1_0.DataTestSupport.GEOS_STATES; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.geotools.data.wfs.v1_1_0.DataTestSupport.*; +import static org.junit.Assert.*; import java.io.IOException; +import java.io.Serializable; +import java.net.URL; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.geotools.data.FeatureReader; import org.geotools.data.Query; +import org.geotools.data.Transaction; import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.data.simple.SimpleFeatureSource; +import org.geotools.data.wfs.WFSDataStore; +import org.geotools.data.wfs.WFSDataStoreFactory; +import org.geotools.data.wfs.protocol.http.HTTPResponse; import org.geotools.factory.CommonFactoryFinder; +import org.geotools.factory.Hints; import org.junit.Test; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; @@ -98,5 +106,76 @@ iterator.close(); } } + + @Test + public void testVendorParametersGet() throws Exception { + testVendorParameters(Boolean.FALSE); + } + + @Test + public void testVendorParametersPost() throws Exception { + testVendorParameters(Boolean.TRUE); + } + private void testVendorParameters(Boolean usePost) throws IOException { + if (Boolean.FALSE.equals(serviceAvailable)) { + return; + } + + // we alter the data store, thus we cannot use the static "wfs" field, we need to create a new one + Map<String, Serializable> params = new HashMap<String, Serializable>(); + params.put(WFSDataStoreFactory.URL.key, SERVER_URL); + params.put(WFSDataStoreFactory.PROTOCOL.key, usePost); + params.put("USE_PULL_PARSER", Boolean.TRUE); + WFSDataStoreFactory dataStoreFactory = new WFSDataStoreFactory(); + WFSDataStore wfs = dataStoreFactory.createDataStore(params); + + final WFS_1_1_0_Protocol originalHandler = (WFS_1_1_0_Protocol) ((WFS_1_1_0_DataStore) wfs).wfs; + originalHandler.http = new HttpProtocolWrapper(originalHandler.http) { + + @Override + public HTTPResponse issueGet(URL baseUrl, Map<String, String> kvp) throws IOException { + // check the vendor params actually made it into the url (at this stage they are not url encoded) + assertEquals("true", kvp.get("strict")); + assertEquals("mysecret", kvp.get("authkey")); + assertEquals("low:2000000;high:5000000", kvp.get("viewparams")); + + return super.issueGet(baseUrl, kvp); + } + + @Override + public HTTPResponse issuePost(URL targetUrl, POSTCallBack callback) throws IOException { + String[] keyValueArray = targetUrl.getQuery().split("&"); + Map<String, String> kvp = new HashMap<String, String>(); + for (String keyValue : keyValueArray) { + String[] skv = keyValue.split("="); + kvp.put(skv[0], skv[1]); + } + + // check the vendor params actually made it into the url + assertEquals("true", kvp.get("strict")); + assertEquals("mysecret", kvp.get("authkey")); + assertEquals("low%3A2000000%3Bhigh%3A5000000", kvp.get("viewparams")); + + return super.issuePost(targetUrl, callback); + } + + }; + + + Map<String, String> vparams = new HashMap<String, String>(); + vparams.put("authkey", "mysecret"); + vparams.put("viewparams", "low:2000000;high:5000000"); + vparams.put("strict", "true"); + Hints hints = new Hints(WFSDataStore.WFS_VENDOR_PARAMETERS, vparams); + Query q = new Query("topp:states"); + q.setHints(hints); + + // read some features, check + FeatureReader fr = wfs.getFeatureReader(q, Transaction.AUTO_COMMIT); + assertTrue(fr.hasNext()); + fr.close(); + } + + } Added: trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/HttpProtocolWrapper.java =================================================================== --- trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/HttpProtocolWrapper.java (rev 0) +++ trunk/modules/unsupported/wfs/src/test/java/org/geotools/data/wfs/v1_1_0/HttpProtocolWrapper.java 2012-03-27 09:59:43 UTC (rev 38649) @@ -0,0 +1,56 @@ +package org.geotools.data.wfs.v1_1_0; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; + +import org.geotools.data.wfs.protocol.http.HTTPProtocol; +import org.geotools.data.wfs.protocol.http.HTTPResponse; + +public class HttpProtocolWrapper implements HTTPProtocol { + + HTTPProtocol delegate; + + public HttpProtocolWrapper(HTTPProtocol delegate) { + this.delegate = delegate; + } + + public void setTryGzip(boolean tryGzip) { + delegate.setTryGzip(tryGzip); + } + + public boolean isTryGzip() { + return delegate.isTryGzip(); + } + + public void setAuth(String username, String password) { + delegate.setAuth(username, password); + } + + public boolean isAuthenticating() { + return delegate.isAuthenticating(); + } + + public void setTimeoutMillis(int milliseconds) { + delegate.setTimeoutMillis(milliseconds); + } + + public int getTimeoutMillis() { + return delegate.getTimeoutMillis(); + } + + public HTTPResponse issueGet(URL baseUrl, Map<String, String> kvp) throws IOException { + return delegate.issueGet(baseUrl, kvp); + } + + public HTTPResponse issuePost(URL targetUrl, POSTCallBack callback) throws IOException { + return delegate.issuePost(targetUrl, callback); + } + + public URL createUrl(URL baseUrl, Map<String, String> queryStringKvp) + throws MalformedURLException { + return delegate.createUrl(baseUrl, queryStringKvp); + } + +} |