public static Result html() { Result result = status(Result.SC_200_OK); result.contentType(Result.TEXT_HTML); return result; }
/** * Retrieves the language cookie or generates one with a very long max age (ten years). * * @param context * @return The cookie */ private Cookie generateNinjaLanguageCookie() { Cookie cookie = Cookie.builder(applicationCookiePrefix + ninja.utils.NinjaConstant.LANG_COOKIE_SUFFIX, "") .setMaxAge(TEN_YEARS).build(); return cookie; }
@Override public Result setLanguage(String locale, Result result) { Cookie defaultLangCookie = generateNinjaLanguageCookie(); Cookie cookie = Cookie.builder(defaultLangCookie).setValue(locale).build(); result.addCookie(cookie); return result; }
@Override public Result filter(FilterChain chain, Context context) { // if we got no cookies we break: if (context.getSession() == null || context.getSession().get(USERNAME) == null) { Result result = ninja.getForbiddenResult(context); return result; } else { return chain.next(context); } } }
/** * A redirect that uses 303 see other. * * @param url * The url used as redirect target. * @return A nicely configured result with status code 303 and the url set * as Location header. */ public Result redirect(String url) { status(Result.SC_303_SEE_OTHER); addHeader(Result.LOCATION, url); return this; }
/** * Start a server in dev mode and load routes. */ public void startServerInDevMode() { startServer(NinjaMode.dev); }
@Override public void with(Class<?> controllerClass, String controllerMethod) { this.functionalMethod = verifyControllerMethod(controllerClass, controllerMethod); }
/** * Identical to <code>path</code> except the path parameter value will * NOT be url encoded when building the final url. * @param name The path parameter name * @param value The path parameter value * @return A reference to this builder * @see #pathParam(java.lang.String, java.lang.Object) */ public Builder rawPathParam(String name, Object value) { return setPathParam(name, value, true); }
@Override public String toString() { return this.build(); } }
/** * Instructs ninja (and the http container) that it is okay to continue with * the websocket handshake. This sets the HTTP status code to * <code>101 Switching Protocols</code>. Do not include any result via * a render() as writing it out will not be possible if you intend on * switching protocols (e.g. upgrade to a websocket). */ public static Result webSocketContinue() { return status(Result.SC_101_SWITCHING_PROTOCOLS); }
@Override public Session getSessionCookie() { return wrapped.getSessionCookie(); }
public static Result text() { Result result = status(Result.SC_200_OK); result.contentType(Result.TEXT_PLAIN); return result; }
/** * Start a server in test mode and load routes. */ public void startServerInTestMode() { startServer(NinjaMode.test); }
public static Result contentType(String contentType) { Result result = status(Result.SC_200_OK); result.contentType(contentType); return result; }
public static Result TODO() { Result result = status(Result.SC_501_NOT_IMPLEMENTED); result.contentType(Result.APPLICATION_JSON); return result; }