Search in sources :

Example 1 with JSONEncodingException

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)));
}
Also used : EncoderResponseUnsupportedException(org.n52.svalbard.encode.exception.EncoderResponseUnsupportedException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 2 with JSONEncodingException

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Test (org.junit.Test)1 CodedException (org.n52.shetland.ogc.ows.exception.CodedException)1 EncoderResponseUnsupportedException (org.n52.svalbard.encode.exception.EncoderResponseUnsupportedException)1