I'm trying to create a DataStore in Java with Geotools 12.3. With WFS services in geoserver works fine, but with WFS services in ArcGIS doesn't work at all.
This is the exception:
WARNING [net.refractions.xsi.element] (default task-78) Starting schema with ServiceExceptionReport element.
ERROR [stderr] (default task-78) java.lang.NullPointerException
ERROR [stderr] (default task-78) at org.geotools.data.wfs.v1_0_0.WFS_1_0_0_DataStore.getSchema(WFS_1_0_0_DataStore.java:368)
ERROR [stderr] (default task-78) at org.geotools.data.wfs.v1_0_0.WFSFeatureSource.getSchema(WFSFeatureSource.java:204)
This is my Java code: "Main Class"
public String getDataSelection(String url) throws IOException {
Map mapResponse = new HashMap();
String response = null;
double x1 = strToDbl(this.getBboxT()[0]);
double y1 = strToDbl(this.getBboxT()[1]);
double x2 = strToDbl(this.getBboxT()[2]);
double y2 = strToDbl(this.getBboxT()[3]);
try {
String url = "http://sigserv02.anla.gov.co:6080/arcgis/services/Alertas_tempranas_deforestacion/MapServer/WFSServer?service=WFS&VERSION=1.0.0&REQUEST=GetCapabilities";
int layerName = 0;
DataStore ds = configWFSDataStore(url);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
FeatureSource fs = ds.getFeatureSource(layerName);
FeatureType schema = fs.getSchema();
CoordinateReferenceSystem worldCRS = DefaultGeographicCRS.WGS84;
String geometryPropertyName = schema.getGeometryDescriptor().getLocalName();
CoordinateReferenceSystem targetCRS = schema.getGeometryDescriptor().getCoordinateReferenceSystem();
ReferencedEnvelope click = new ReferencedEnvelope(x1,x2, y1, y2, worldCRS);
ReferencedEnvelope bbox = click.transform(targetCRS, true);
Polygon clickPolygon = JTS.toGeometry(bbox);
Filter filter = ff.intersects(ff.property(geometryPropertyName), ff.literal(clickPolygon));
Query query = new Query(layerName, filter);
query.setMaxFeatures(1500);
FeatureReader<SimpleFeatureType, SimpleFeature> source = ds.getFeatureReader(query, Transaction.AUTO_COMMIT);
CoordinateReferenceSystem CRSobjetivo = CRS.decode("EPSG:4326");
if(source.hasNext()){
.......
}
else{
response = "empty";
}
} catch(Exception e){
e.printStackTrace();
..........
}
return response;
}
configWFSDataStore Method:
public static DataStore configWFSDataStore(String url) throws IOException {
DataStore dataStore = null;
BBConectionWFS conectionWFS = new BBConectionWFS();
conectionWFS.setGetCapabilities(url+"service=WFS&VERSION=1.0.0&REQUEST=GetCapabilities");
dataStore = conectionWFS.dataStoreWFS();
return dataStore;
}
BBConectionWFS Class:
public DataStore dataStoreWFS() {
DataStore dataStore = null;
try {
Map<String, String> connectionParameters;
String getCapabilities = "http://sigserv02.anla.gov.co:6080/arcgis/services/Alertas_tempranas_deforestacion/MapServer/WFSServer?service=WFS&VERSION=1.0.0&REQUEST=GetCapabilities";
String variableCapabilities = "WFSDataStoreFactory:GET_CAPABILITIES_URL";
connectionParameters = new HashMap<String, String>();
connectionParameters.put(variableCapabilities, getCapabilities);
dataStore = (new WFSDataStoreFactory()).createDataStore(connectionParameters);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dataStore;
}