/** Encodes a ogc:ServiceExceptionReport to output. */ public void handleServiceException(ServiceException exception, Request request) { boolean verbose = gs.getSettings().isVerboseExceptions(); String charset = gs.getSettings().getCharset(); // first of all check what kind of exception handling we must perform final String exceptions; try { exceptions = (String) request.getKvp().get("EXCEPTIONS"); if (exceptions == null) { // use default handleDefault(exception, request, charset, verbose); return; } } catch (Exception e) { // width and height might be missing handleDefault(exception, request, charset, verbose); return; } if (JSONType.isJsonMimeType(exceptions)) { // use Json format JSONType.handleJsonException(LOGGER, exception, request, charset, verbose, false); } else if (JSONType.useJsonp(exceptions)) { // use JsonP format JSONType.handleJsonException(LOGGER, exception, request, charset, verbose, true); } else { handleDefault(exception, request, charset, verbose); } }
if (JSONType.isJsonMimeType(exceptions)) {
/** Encodes a ogc:ServiceExceptionReport to output. */ @Override public void handleServiceException(ServiceException exception, Request request) { boolean verbose = gs.getSettings().isVerboseExceptions(); String charset = gs.getSettings().getCharset(); setHttpHeaders(exception, request); // first of all check what kind of exception handling we must perform final String exceptions; try { exceptions = (String) request.getKvp().get("EXCEPTIONS"); if (exceptions == null) { // use default super.handleServiceException(exception, request); return; } } catch (Exception e) { super.handleServiceException(exception, request); return; } if (JSONType.isJsonMimeType(exceptions)) { // use Json format JSONType.handleJsonException(LOGGER, exception, request, charset, verbose, false); } else if (JSONType.useJsonp(exceptions)) { // use JsonP format JSONType.handleJsonException(LOGGER, exception, request, charset, verbose, true); } else { super.handleServiceException(exception, request); } }
@Test public void testMimeType() { // MimeType assertNotSame(JSONType.json, JSONType.jsonp); assertTrue(JSONType.isJsonMimeType(JSONType.json)); // enable JsonP programmatically JSONType.setJsonpEnabled(true); // check jsonp is enabled assertTrue(JSONType.useJsonp(JSONType.jsonp)); // disable JsonP JSONType.setJsonpEnabled(false); assertFalse(JSONType.useJsonp(JSONType.jsonp)); }