use of net.opengis.ows.v_1_0_0.ExceptionReport in project ddf by codice.
the class CswResponseExceptionMapper method convertToCswException.
private CswException convertToCswException(ExceptionReport report) {
CswException cswException = null;
List<ExceptionType> list = report.getException();
for (ExceptionType exceptionType : list) {
String exceptionCode = exceptionType.getExceptionCode();
String locator = exceptionType.getLocator();
List<String> exceptionText = exceptionType.getExceptionText();
StringBuilder exceptionMsg = new StringBuilder();
// Exception code is required per CSW schema, but check it anyway
if (StringUtils.isNotBlank(exceptionCode)) {
exceptionMsg.append("exceptionCode = " + exceptionCode + "\n");
} else {
exceptionMsg.append("exceptionCode = UNSPECIFIED");
}
// Locator and exception text(s) are both optional
if (StringUtils.isNotBlank(locator)) {
exceptionMsg.append("locator = " + locator + "\n");
}
if (!CollectionUtils.isEmpty(exceptionText)) {
for (String text : exceptionText) {
exceptionMsg.append(text);
}
}
cswException = new CswException(exceptionMsg.toString());
}
if (null == cswException) {
cswException = new CswException("Empty Exception Report (version = " + report.getVersion() + ")");
}
return cswException;
}
use of net.opengis.ows.v_1_0_0.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 net.opengis.ows.v_1_0_0.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 net.opengis.ows.v_1_0_0.ExceptionReport in project ddf by codice.
the class WfsResponseExceptionMapper method convertToWfsException.
private WfsException convertToWfsException(ExceptionReport report) {
WfsException wfsException = null;
List<ExceptionType> list = new ArrayList<>(report.getException());
if (!list.isEmpty()) {
Collections.reverse(list);
StringBuilder exceptionMsg = new StringBuilder();
for (ExceptionType serviceException : list) {
exceptionMsg.append(serviceException.getExceptionText());
}
wfsException = new WfsException(exceptionMsg.toString());
}
if (null == wfsException) {
wfsException = new WfsException("Empty Service Exception Report (version = " + report.getVersion() + ")");
}
return wfsException;
}
use of net.opengis.ows.v_1_0_0.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());
}
Aggregations