use of org.geotoolkit.ows.xml.v200.ExceptionReport in project ddf by codice.
the class CswResponseExceptionMapper method fromResponse.
@Override
public CswException fromResponse(Response response) {
CswException cswException = null;
if (response != null) {
if (response.getEntity() instanceof InputStream) {
String msg = null;
try {
InputStream is = (InputStream) response.getEntity();
if (is.markSupported()) {
is.reset();
}
msg = IOUtils.toString(is);
} catch (IOException e) {
LOGGER.info("Unable to parse exception report: {}", e.getMessage());
LOGGER.debug("Unable to parse exception report", e);
}
if (msg != null) {
try {
JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<>();
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);
cswException = convertToCswException(report);
} catch (JAXBException | XMLStreamException e) {
cswException = new CswException("Error received from remote Csw server: " + msg, e);
LOGGER.info("Error parsing the exception report: {}", e.getMessage());
LOGGER.debug("Error parsing the exception report", e);
}
} else {
cswException = new CswException("Error received from remote Csw server.");
}
} else {
cswException = new CswException("Error reading response, entity type not understood: " + response.getEntity().getClass().getName());
}
cswException.setHttpStatus(response.getStatus());
} else {
cswException = new CswException("Error handling response, response is null");
}
return cswException;
}
use of org.geotoolkit.ows.xml.v200.ExceptionReport in project ddf by codice.
the class WfsResponseExceptionMapper method unmarshalResponseEntity.
private WfsException unmarshalResponseEntity(String msg) {
WfsException wfsEx;
try {
JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<>();
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 WfsParseException(msg, e);
}
return wfsEx;
}
use of org.geotoolkit.ows.xml.v200.ExceptionReport in project ddf by codice.
the class CswExceptionMapperTest method testCswExceptionToServiceExceptionReport.
@Test
public void testCswExceptionToServiceExceptionReport() {
CswException exception = new CswException(SERVICE_EXCEPTION_MSG, Status.BAD_REQUEST.getStatusCode());
ExceptionMapper<Throwable> exceptionMapper = new CswExceptionMapper();
Response response = exceptionMapper.toResponse(exception);
assertThat(response.getEntity(), is(instanceOf(ExceptionReport.class)));
ExceptionReport exceptionReport = (ExceptionReport) response.getEntity();
assertThat(Status.BAD_REQUEST.getStatusCode(), is(response.getStatus()));
assertThat(SERVICE_EXCEPTION_MSG, is(exceptionReport.getException().get(0).getExceptionText().get(0)));
assertThat(exceptionReport.getException().get(0).getExceptionCode(), nullValue());
assertThat(exceptionReport.getException().get(0).getLocator(), nullValue());
}
use of org.geotoolkit.ows.xml.v200.ExceptionReport in project ddf by codice.
the class CswExceptionMapperTest 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 org.geotoolkit.ows.xml.v200.ExceptionReport in project geotoolkit by Geomatys.
the class OWSXmlBindingTest method exceptionUnmarshalingTest.
/**
* Test simple Record Marshalling.
*
* @throws JAXBException
*/
@Test
public void exceptionUnmarshalingTest() throws JAXBException {
/*
* Test Unmarshalling exceptionReport 1.1
*/
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ns2:ExceptionReport version=\"1.1.0\" xmlns:ns2=\"http://www.opengis.net/ows/1.1\">" + '\n' + " <ns2:Exception locator=\"parameter1\" exceptionCode=\"InvalidCRS\">" + '\n' + " <ns2:ExceptionText>some error</ns2:ExceptionText>" + '\n' + " </ns2:Exception>" + '\n' + "</ns2:ExceptionReport>" + '\n';
StringReader sr = new StringReader(xml);
ExceptionReport result = (ExceptionReport) unmarshaller.unmarshal(sr);
ExceptionReport expResult = new ExceptionReport("some error", OWSExceptionCode.INVALID_CRS.name(), "parameter1", "1.1.0");
assertEquals(expResult, result);
}
Aggregations