use of ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionReport in project ddf by codice.
the class WfsResponseExceptionMapper method convertToWfsException.
private WfsException convertToWfsException(ServiceExceptionReport report) {
WfsException wfsException = null;
List<ServiceExceptionType> list = new ArrayList<ServiceExceptionType>(report.getServiceException());
if (list.size() > 0) {
Collections.reverse(list);
StringBuilder exceptionMsg = new StringBuilder();
for (ServiceExceptionType serviceException : list) {
exceptionMsg.append(serviceException.getValue());
}
wfsException = new WfsException(exceptionMsg.toString());
}
if (null == wfsException) {
wfsException = new WfsException("Empty Service Exception Report (version = " + report.getVersion() + ")");
}
return wfsException;
}
use of ogc.schema.opengis.wfs.exception.v_1_0_0.ServiceExceptionReport in project ddf by codice.
the class WfsResponseExceptionMapper method fromResponse.
public WfsException fromResponse(Response response) {
WfsException wfsEx = null;
if (response != null) {
if (response.getEntity() instanceof InputStream) {
String msg = null;
try {
InputStream is = (InputStream) response.getEntity();
is.reset();
msg = IOUtils.toString(is);
} catch (IOException e) {
wfsEx = new WfsException("Error reading Response" + (msg != null ? ": " + msg : ""), e);
}
if (msg != null) {
try {
JAXBElementProvider<ServiceExceptionReport> provider = new JAXBElementProvider<ServiceExceptionReport>();
Unmarshaller um = provider.getJAXBContext(ServiceExceptionReport.class, ServiceExceptionReport.class).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(msg));
ServiceExceptionReport report = (ServiceExceptionReport) um.unmarshal(xmlStreamReader);
wfsEx = convertToWfsException(report);
} catch (JAXBException | XMLStreamException e) {
wfsEx = new WfsException("Error parsing Response: " + msg, e);
}
}
} else {
wfsEx = new WfsException("Error reading response, entity type not understood: " + response.getEntity().getClass().getName());
}
if (wfsEx != null) {
wfsEx.setHttpStatus(response.getStatus());
}
} else {
wfsEx = new WfsException("Error handling response, response is null");
}
return wfsEx;
}
Aggregations