Search in sources :

Example 1 with ExceptionDocument

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;
}
Also used : ExceptionType(net.opengis.ows.x11.ExceptionType) ExceptionReport(net.opengis.ows.x11.ExceptionReportDocument.ExceptionReport) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) ArrayList(java.util.ArrayList) ExceptionReportDocument(net.opengis.ows.x11.ExceptionReportDocument)

Example 2 with ExceptionDocument

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;
}
Also used : ExceptionType(net.opengis.ows.x11.ExceptionType) PrintStream(java.io.PrintStream) ExceptionDocument(net.opengis.ows.x11.ExceptionDocument) LocalizedString(org.n52.janmayen.i18n.LocalizedString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) OwsLanguageString(org.n52.shetland.ogc.ows.OwsLanguageString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ExceptionType (net.opengis.ows.x11.ExceptionType)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 ExceptionDocument (net.opengis.ows.x11.ExceptionDocument)1 ExceptionReportDocument (net.opengis.ows.x11.ExceptionReportDocument)1 ExceptionReport (net.opengis.ows.x11.ExceptionReportDocument.ExceptionReport)1 LocalizedString (org.n52.janmayen.i18n.LocalizedString)1 MultilingualString (org.n52.janmayen.i18n.MultilingualString)1 OwsLanguageString (org.n52.shetland.ogc.ows.OwsLanguageString)1 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)1