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 get(URL url) throws IOException {
// check the vendor params actually made it into the url (at this stage they are not url encoded)
Map<String, String> kvp = HttpUtil.requestKvp(url);
assertEquals("true", kvp.get("strict"));
assertEquals("mysecret", kvp.get("authkey"));
assertEquals("low:2000000;high:5000000", kvp.get("viewparams"));
return super.get(url);
}
@Override
public HTTPResponse post(URL url, InputStream postContent, String postContentType)
throws IOException {
Map<String, String> kvp = HttpUtil.requestKvp(url);
// 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.post(url, postContent, postContentType);
}
};
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();
}