/** * Implicitly generates a hashmap as object being rendered and adds * this key, value pair. If the object being rendered is already a hashmap * it simply adds this key value pair to it. * * @param key The key to use. * @param value The value to use. * @return The Result for chaining. */ public Result render(String key, Object value) { render(new AbstractMap.SimpleEntry<String, Object>(key, value)); return this; }
render(renderable);
public static Result noContent() { return status(Result.SC_204_NO_CONTENT) .render(Result.NO_HTTP_BODY); }
render(renderable);
/** * Serves resources from the assets directory of your application. * * For instance: * A request to /robots.txt will be served from /assets/robots.txt. * Request to /public/css/app.css will be served from /assets/css/app.css. * */ public Result serveWebJars() { Object renderable = new Renderable() { @Override public void render(Context context, Result result) { String fileName = getFileNameFromPathOrReturnRequestPath(context); URL url = getStaticFileFromMetaInfResourcesDir(fileName); streamOutUrlEntity(url, context, result); } }; return Results.ok().render(renderable); }
/** * Serves resources from the assets directory of your application. * * For instance: * route: /robots.txt * A request to /robots.txt will be served from /assets/robots.txt. * * You can also use a path like the following to serve files: * route: /assets/{fileName: .*} * * matches * /assets/app/app.css * and will return * /assets/app/app.css (from your jar). * */ public Result serveStatic() { Object renderable = new Renderable() { @Override public void render(Context context, Result result) { String fileName = getFileNameFromPathOrReturnRequestPath(context); URL url = getStaticFileFromAssetsDir(fileName); streamOutUrlEntity(url, context, result); } }; return Results.ok().render(renderable); }
/** * A redirect that uses 303 see other. * * The redirect does NOT need a template and does NOT * render a text in the Http body by default. * * If you wish to do so please * remove the {@link NoHttpBody} that is set as renderable of * the Result. * * @param url * The url used as redirect target. * @return A nicely configured result with status code 303 and the url set * as Location header. Renders no Http body by default. */ public static Result redirect(String url) { Result result = status(Result.SC_303_SEE_OTHER); result.addHeader(Result.LOCATION, url); result.render(Result.NO_HTTP_BODY); return result; }
/** * A redirect that uses 307 see other. * * The redirect does NOT need a template and does NOT * render a text in the Http body by default. * * If you wish to do so please * remove the {@link NoHttpBody} that is set as renderable of * the Result. * * @param url * The url used as redirect target. * @return A nicely configured result with status code 307 and the url set * as Location header. Renders no Http body by default. */ public static Result redirectTemporary(String url) { Result result = status(Result.SC_307_TEMPORARY_REDIRECT); result.addHeader(Result.LOCATION, url); result.render(Result.NO_HTTP_BODY); return result; }
DiagnosticErrorBuilder.build400BadRequestDiagnosticError(exception, true); return Results.badRequest().render(diagnosticError); .supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML) .fallbackContentType(Result.TEXT_HTML) .render(message) .template( ninjaProperties.getWithDefault(
: DiagnosticErrorBuilder.build404NotFoundDiagnosticError(true); return Results.notFound().render(diagnosticError); .supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML) .fallbackContentType(Result.TEXT_HTML) .render(message) .template( ninjaProperties.getWithDefault(
: DiagnosticErrorBuilder.build403ForbiddenDiagnosticError(); return Results.forbidden().render(diagnosticError); .supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML) .fallbackContentType(Result.TEXT_HTML) .render(message) .template( ninjaProperties.getWithDefault(
DiagnosticErrorBuilder.build401UnauthorizedDiagnosticError(); return Results.unauthorized().render(diagnosticError); .supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML) .fallbackContentType(Result.TEXT_HTML) .render(message) .template( ninjaProperties.getWithDefault(
DiagnosticErrorBuilder.build500InternalServerErrorDiagnosticError(exception, true, underlyingResult); return Results.internalServerError().render(diagnosticError); .supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML) .fallbackContentType(Result.TEXT_HTML) .render(message) .template( ninjaProperties.getWithDefault(
result.render((Context context1, Result result1) -> { context1.finalizeHeadersWithoutFlashAndSessionCookie(result1); context1.setAttribute(WebSocketUtils.ATTRIBUTE_ENDPOINT, targetObject);
public Result getRenderingExceptionResult(Context context, RenderingException exception, Result underlyingResult) { if (isDiagnosticsEnabled()) { // prefer provided title and underlying cause DiagnosticError diagnosticError = DiagnosticErrorBuilder .buildDiagnosticError( (exception.getTitle() == null ? "Rendering exception" : exception.getTitle()), (exception.getCause() == null ? exception : exception.getCause()), exception.getSourcePath(), exception.getLineNumber(), underlyingResult); return Results.internalServerError().render(diagnosticError); } return getInternalServerErrorResult(context, exception, underlyingResult); }