use of net.opengis.ows.v_1_0_0.ExceptionReport in project ddf by codice.
the class TestCswExceptionMapper method testThrowableExceptionToServiceExceptionReport.
@Test
public void testThrowableExceptionToServiceExceptionReport() {
NullPointerException npe = new NullPointerException();
ExceptionMapper<Throwable> exceptionMapper = new CswExceptionMapper();
Response response = exceptionMapper.toResponse(npe);
assertThat(response.getEntity(), is(instanceOf(ExceptionReport.class)));
ExceptionReport exceptionReport = (ExceptionReport) response.getEntity();
assertThat(Status.BAD_REQUEST.getStatusCode(), is(response.getStatus()));
assertThat(XML_PARSE_FAIL_MSG, is(exceptionReport.getException().get(0).getExceptionText().get(0)));
assertThat(CswConstants.MISSING_PARAMETER_VALUE, is(exceptionReport.getException().get(0).getExceptionCode()));
assertThat(exceptionReport.getException().get(0).getLocator(), nullValue());
IllegalArgumentException iae = new IllegalArgumentException();
exceptionMapper = new CswExceptionMapper();
response = exceptionMapper.toResponse(iae);
assertThat(response.getEntity(), is(instanceOf(ExceptionReport.class)));
exceptionReport = (ExceptionReport) response.getEntity();
assertThat(Status.BAD_REQUEST.getStatusCode(), is(response.getStatus()));
assertThat(XML_PARSE_FAIL_MSG, is(exceptionReport.getException().get(0).getExceptionText().get(0)));
assertThat(CswConstants.MISSING_PARAMETER_VALUE, is(exceptionReport.getException().get(0).getExceptionCode()));
assertThat(exceptionReport.getException().get(0).getLocator(), nullValue());
}
use of net.opengis.ows.v_1_0_0.ExceptionReport 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<ExceptionReport> provider = new JAXBElementProvider<ExceptionReport>();
Unmarshaller um = provider.getJAXBContext(ExceptionReport.class, ExceptionReport.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));
ExceptionReport report = (ExceptionReport) 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());
}
wfsEx.setHttpStatus(response.getStatus());
} else {
wfsEx = new WfsException("Error handling response, response is null");
}
return wfsEx;
}
Aggregations