use of gov.usgs.cida.gml.GMLStreamingFeatureCollection in project coastal-hazards by USGS-CIDA.
the class HttpComponentsWFSClient method getFeatureCollection.
@Override
public SimpleFeatureCollection getFeatureCollection(String typeName, Filter filter) throws IOException {
SimpleFeatureCollection collection = null;
String filterXml = null;
InputStream is = null;
OutputStream os = null;
DefaultHttpClient httpClient = new DefaultHttpClient();
if (filter != null) {
try {
FilterTransformer transformer = new FilterTransformer();
transformer.setOmitXMLDeclaration(true);
transformer.setNamespaceDeclarationEnabled(false);
filterXml = "<ogc:Filter>" + transformer.transform(filter) + "</ogc:Filter>";
} catch (TransformerException ex) {
throw new RuntimeException("Specified filter cannot be transformed", ex);
}
} else {
filterXml = "";
}
try {
HttpPost post = new HttpPost(wfsEndpoint);
StringEntity stringEntity = new StringEntity(fillInTemplate(typeName, filterXml), ContentType.APPLICATION_XML);
post.setEntity(stringEntity);
HttpContext localContext = new BasicHttpContext();
httpClient.setReuseStrategy(new NoConnectionReuseStrategy());
HttpResponse methodResponse = httpClient.execute(post, localContext);
if (methodResponse.getStatusLine().getStatusCode() != 200) {
throw new IOException(methodResponse.getStatusLine().getReasonPhrase());
}
is = methodResponse.getEntity().getContent();
os = new FileOutputStream(tmpWfsFile);
IOUtils.copy(is, os);
} finally {
if (httpClient.getConnectionManager() != null) {
httpClient.getConnectionManager().closeExpiredConnections();
}
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
collection = new GMLStreamingFeatureCollection(tmpWfsFile);
return collection;
}
Aggregations