use of org.n52.svalbard.encode.json.JSONEncodingException in project arctic-sea by 52North.
the class OwsExceptionReportEncoderTest method testExceptionWithoutCause.
@Test
public void testExceptionWithoutCause() throws JSONEncodingException {
final EncoderResponseUnsupportedException owse = new EncoderResponseUnsupportedException();
owse.setVersion("2.0.0");
final JsonNode json = enc.encodeJSON(owse);
assertThat(json, is(notNullValue()));
final String message = "The encoder response is not supported!";
e.checkThat(json, is(instanceOf(SchemaConstants.Common.EXCEPTION_REPORT)));
e.checkThat(json.path(VERSION).asText(), is(equalTo("2.0.0")));
e.checkThat(json.path(EXCEPTIONS), is(arrayOfLength(1)));
e.checkThat(json.path(EXCEPTIONS).path(0), isObject());
e.checkThat(json.path(EXCEPTIONS).path(0).path(LOCATOR), does(not(exist())));
e.checkThat(json.path(EXCEPTIONS).path(0).path(TEXT).asText(), is(equalTo(message)));
}
use of org.n52.svalbard.encode.json.JSONEncodingException in project arctic-sea by 52North.
the class OwsExceptionReportEncoder method encodeJSON.
@Override
public JsonNode encodeJSON(OwsExceptionReport t) throws JSONEncodingException {
final ObjectNode exceptionReport = Json.nodeFactory().objectNode();
exceptionReport.put(JSONConstants.VERSION, t.getVersion());
final ArrayNode exceptions = exceptionReport.putArray(JSONConstants.EXCEPTIONS);
for (CodedException ce : t.getExceptions()) {
final ObjectNode exception = exceptions.addObject();
exception.put(JSONConstants.CODE, ce.getCode() != null ? ce.getCode().toString() : OwsExceptionCode.NoApplicableCode.toString());
if (ce.getLocator() != null && !ce.getLocator().isEmpty()) {
exception.put(JSONConstants.LOCATOR, ce.getLocator());
}
final String message = getExceptionText(ce);
if (message != null && !message.isEmpty()) {
exception.put(JSONConstants.TEXT, message);
}
if (log.isDebugEnabled()) {
exception.set(STACK_TRACE, encodeStackTrace(ce));
}
}
return exceptionReport;
}
Aggregations