@Override public void render(@NotNull final String template) { int sep = template.lastIndexOf('.'); if (sep != -1) { String extension = template.substring(sep); final Engine renderEngine = ENGINE.get(extension); if (renderEngine == null) { ctx.fail("No engine registered for extension: " + extension); } else { renderEngine.render(template, ctx); } } else { // when no extension is provided but only 1 engine is available assume that one if (DEFAULT_ENGINE != null) { final Engine renderEngine = ENGINE.get(DEFAULT_ENGINE); renderEngine.render(template, ctx); } else { ctx.fail("Cannot determine the extension of the template"); } } }
@Override public void json(Object bean) { if (bean == null) { end(); } else { try { final String encoded = JSON.encode(bean); setType("application/json; charset=utf-8"); end(encoded); } catch (JsonProcessingException | RuntimeException e) { ctx.fail(INTERNAL_SERVER_ERROR, e); } } }