use of net.opengis.ows.x11.ExceptionDocument in project arctic-sea by 52North.
the class OwsEncoderv110 method encodeOwsExceptionReport.
private ExceptionReportDocument encodeOwsExceptionReport(final OwsExceptionReport owsExceptionReport) {
ExceptionReportDocument erd = ExceptionReportDocument.Factory.newInstance(getXmlOptions());
ExceptionReport er = erd.addNewExceptionReport();
// er.setLanguage("en");
er.setVersion(owsExceptionReport.getVersion());
List<ExceptionType> exceptionTypes = new ArrayList<>(owsExceptionReport.getExceptions().size());
owsExceptionReport.getExceptions().stream().map(this::encodeOwsException).map(ExceptionDocument::getException).forEach(exceptionTypes::add);
er.setExceptionArray(exceptionTypes.toArray(new ExceptionType[exceptionTypes.size()]));
N52XmlHelper.setSchemaLocationsToDocument(erd, Collections.singletonList(N52XmlHelper.getSchemaLocationForOWS110()));
return erd;
}
use of net.opengis.ows.x11.ExceptionDocument in project arctic-sea by 52North.
the class OwsEncoderv110 method encodeOwsException.
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
private ExceptionDocument encodeOwsException(CodedException owsException) {
ExceptionDocument exceptionDoc = ExceptionDocument.Factory.newInstance(getXmlOptions());
ExceptionType exceptionType = exceptionDoc.addNewException();
String exceptionCode;
if (owsException.getCode() == null) {
exceptionCode = OwsExceptionCode.NoApplicableCode.toString();
} else {
exceptionCode = owsException.getCode().toString();
}
exceptionType.setExceptionCode(exceptionCode);
if (owsException.getLocator() != null) {
exceptionType.setLocator(owsException.getLocator());
}
final StringBuilder exceptionText = new StringBuilder();
if (owsException.getMessage() != null) {
exceptionText.append(owsException.getMessage());
exceptionText.append("\n");
}
if (owsException.getCause() != null) {
exceptionText.append("[EXEPTION]: \n");
final String localizedMessage = owsException.getCause().getLocalizedMessage();
final String message = owsException.getCause().getMessage();
if (localizedMessage != null && message != null) {
if (!message.equals(localizedMessage)) {
exceptionText.append(message).append('\n');
}
exceptionText.append(localizedMessage).append('\n');
} else if (localizedMessage != null) {
exceptionText.append(localizedMessage).append('\n');
} else if (message != null) {
exceptionText.append(message).append('\n');
}
if (includeStackTraceInExceptionReport) {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
owsException.getCause().printStackTrace(new PrintStream(os));
exceptionText.append(os.toString());
}
}
exceptionType.addExceptionText(exceptionText.toString());
return exceptionDoc;
}
Aggregations