use of org.geotoolkit.gml.xml.v311.FeatureCollectionType in project ddf by codice.
the class FeatureCollectionMessageBodyReaderWfs20 method readFrom.
@SuppressWarnings({ "unchecked", "squid:S2093" })
@Override
public Wfs20FeatureCollection readFrom(Class<Wfs20FeatureCollection> clazz, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream inStream) throws IOException, WebApplicationException {
// Save original input stream for any exception message that might need to be
// created and additional attributes
String originalInputStream = IOUtils.toString(inStream, "UTF-8");
LOGGER.debug("{}", LogSanitizer.sanitize(originalInputStream));
ClassLoader ccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(FeatureCollectionMessageBodyReaderWfs20.class.getClassLoader());
// Fetch FeatureCollection attributes
Unmarshaller unmarshaller = null;
JAXBElement<FeatureCollectionType> wfsFeatureCollectionType = null;
xstream.allowTypeHierarchy(Wfs20FeatureCollection.class);
try {
unmarshaller = JAXB_CONTEXT.createUnmarshaller();
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(originalInputStream));
wfsFeatureCollectionType = (JAXBElement<FeatureCollectionType>) unmarshaller.unmarshal(xmlStreamReader);
} catch (ClassCastException e1) {
LOGGER.debug("Exception unmarshalling {}, could be an OWS Exception Report from server.", e1.getMessage());
// If an ExceptionReport is sent from the remote WFS site it will be sent with an
// JAX-RS "OK" status, hence the ErrorResponse exception mapper will not fire.
// Instead the ServiceExceptionReport will come here and be treated like a GetFeature
// response, resulting in an XStreamException since ExceptionReport cannot be
// unmarshalled. So this catch clause is responsible for catching that XStream
// exception and creating a JAX-RS response containing the original stream
// (with the ExceptionReport) and rethrowing it as a WebApplicationException,
// which CXF will wrap as a ClientException that the WfsSource catches, converts
// to a WfsException, and logs.
ByteArrayInputStream bis = new ByteArrayInputStream(originalInputStream.getBytes(StandardCharsets.UTF_8));
ResponseBuilder responseBuilder = Response.ok(bis);
responseBuilder.type("text/xml");
Response response = responseBuilder.build();
throw new WebApplicationException(e1, response);
} catch (VirtualMachineError e) {
throw e;
} catch (JAXBException | XMLStreamException e1) {
LOGGER.debug("Error in retrieving feature collection.", e1);
} catch (RuntimeException e) {
LOGGER.debug("Error processing collection", e);
throw e;
}
Wfs20FeatureCollection featureCollection = null;
if (null != wfsFeatureCollectionType && null != wfsFeatureCollectionType.getValue()) {
BigInteger numberReturned = wfsFeatureCollectionType.getValue().getNumberReturned();
String numberMatched = wfsFeatureCollectionType.getValue().getNumberMatched();
// Re-create the input stream (since it has already been read for potential
// exception message creation)
inStream = new ByteArrayInputStream(originalInputStream.getBytes("UTF-8"));
try {
xstream.allowTypeHierarchy(Wfs20FeatureCollection.class);
featureCollection = (Wfs20FeatureCollection) xstream.fromXML(inStream);
featureCollection.setNumberMatched(numberMatched);
featureCollection.setNumberReturned(numberReturned);
} catch (XStreamException e) {
LOGGER.debug("Exception unmarshalling", e);
} finally {
IOUtils.closeQuietly(inStream);
}
}
return featureCollection;
} finally {
Thread.currentThread().setContextClassLoader(ccl);
}
}
use of org.geotoolkit.gml.xml.v311.FeatureCollectionType in project geo-platform by geosdi.
the class WFSGetFeatureTest method a_statesHits.
@Test
public void a_statesHits() throws Exception {
WFSGetFeatureRequest<FeatureCollectionType> request = serverConnector.createGetFeatureRequest();
request.setResultType(HITS.value());
request.setTypeName(statesName);
FeatureCollectionType response = request.getResponse();
logger.info("@@@@@@@@@@@@@@@ STATES Features Found : " + "@@@@@@@@@@@@@@@@@ {}\n\n", response.getNumberOfFeatures());
}
use of org.geotoolkit.gml.xml.v311.FeatureCollectionType in project geo-platform by geosdi.
the class WFSGetFeatureTest method o_statesSecureGreatherThanRestrictionTest.
@Test
public void o_statesSecureGreatherThanRestrictionTest() throws Exception {
WFSGetFeatureRequest<FeatureCollectionType> request = secureServerConnector.createGetFeatureRequest();
request.setTypeName(statesName);
request.setResultType(HITS.value());
request.setQueryDTO(GPJAXBContextBuilder.newInstance().unmarshal(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<QueryDTO>\n" + " <matchOperator>ALL</matchOperator>\n" + " <queryRestrictionList>\n" + " <queryRestriction>\n" + " <attribute>\n" + " <maxOccurs>1</maxOccurs>\n" + " <minOccurs>0</minOccurs>\n" + " <name>WORKERS</name>\n" + " <nillable>true</nillable>\n" + " <type>double</type>\n" + " <value></value>\n" + " </attribute>\n" + " <operator>GREATER</operator>\n" + " <restriction>6000000</restriction>\n" + " </queryRestriction>\n" + " </queryRestrictionList>\n" + "</QueryDTO>"), QueryDTO.class));
logger.info("#############################REQUEST_AS_STRING : \n{}\n", request.showRequestAsString());
FeatureCollectionType response = request.getResponse();
logger.info("#############################statesSecureGreatherThanRestrictionTest#Features : {}\n", response.getNumberOfFeatures().intValue());
}
use of org.geotoolkit.gml.xml.v311.FeatureCollectionType in project geo-platform by geosdi.
the class WFSGetFeatureTest method c_secureStatesHits.
@Test
public void c_secureStatesHits() throws Exception {
WFSGetFeatureRequest<FeatureCollectionType> request = secureServerConnector.createGetFeatureRequest();
request.setResultType(HITS.value());
request.setTypeName(statesName);
FeatureCollectionType response = request.getResponse();
logger.info("@@@@@@@@@@@@@@@ SECURE STATES Features Found : " + "@@@@@@@@@@@@@@@@@ {}\n\n", response.getNumberOfFeatures());
}
use of org.geotoolkit.gml.xml.v311.FeatureCollectionType in project geo-platform by geosdi.
the class WFSGetFeatureTest method g_statesBBox.
@Test
public void g_statesBBox() throws Exception {
WFSGetFeatureRequest<FeatureCollectionType> request = serverConnector.createGetFeatureRequest();
request.setResultType(ResultTypeType.RESULTS.value());
request.setTypeName(statesName);
request.setPropertyNames(Arrays.asList(new String[] { "STATE_NAME", "PERSONS" }));
request.setBBox(new BBox(-75.102613, 40.212597, -72.361859, 41.512517));
request.setSRS("EPSG:4326");
logger.info("#############################REQUEST_AS_STRING : \n{}\n", request.showRequestAsString());
logger.info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@RESPONSE_AS_STRING : \n{}\n", request.getResponseAsString());
FeatureCollectionType response = request.getResponse();
logger.info("##################################statesBBox#Features : {}\n", response.getNumberOfFeatures().intValue());
}
Aggregations