public String wfsRequest() { // String getCapabilities = // "http://"+host+":"+port+"/geoserver/"+workspace+"/wfs?REQUEST=GetCapabilities&version=1.0.0"; String getCapabilities = "http://" + host + ":" + port + "/geoserver/" + workspace + "/ows?REQUEST=GetCapabilities&version=1.1.1&service=WFS"; Map connectionParameters = new HashMap(); connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities); connectionParameters.put("WFSDataStoreFactory:USERNAME", "admin"); connectionParameters.put("WFSDataStoreFactory:PASSWORD", "geoserver"); connectionParameters.put("WFSDataStoreFactory:WFS_STRATEGY", "geoserver"); connectionParameters.put("WFSDataStoreFactory:MAXFEATURES", 1000); WFSDataStoreFactory dsf = new WFSDataStoreFactory(); try { // WFS_1_0_0_DataStore wfs = dsf.createDataStore(connectionParameters); WFSDataStore dataStore = dsf.createDataStore(connectionParameters); String[] typeNames = dataStore.getTypeNames(); System.out.println(ArrayUtils.toString(typeNames)); SimpleFeatureSource source = dataStore.getFeatureSource(workspace + ":" + layer); SimpleFeatureCollection fc = source.getFeatures(); StringWriter writer = new StringWriter(); while (fc.features().hasNext()) { SimpleFeature sf = fc.features().next(); System.out.println(sf.getAttribute("myname")); FeatureJSON fjson = new FeatureJSON(); fjson.writeFeature(sf, writer); } String geojson = writer.toString(); return geojson; } catch (IOException ex) { ex.printStackTrace(); } return null; }
public IService createService(URL id, Map<String, Serializable> params) { if (params == null || !params.containsKey(WFSDataStoreFactory.URL.key)) return null; if (!params.containsKey(WFSDataStoreFactory.LENIENT.key)) { params.put(WFSDataStoreFactory.LENIENT.key, true); } if (!params.containsKey(WFSDataStoreFactory.TRY_GZIP.key)) { params.put(WFSDataStoreFactory.TRY_GZIP.key, true); } if (id == null) { URL base = (URL) params.get(WFSDataStoreFactory.URL.key); if (base == null) { return null; } id = WFSDataStoreFactory.createGetCapabilitiesRequest(base); } return new WFSServiceImpl(id, params); }