Search in sources :

Example 1 with ContextResolver

use of io.javalin.http.ContextResolver in project javalin by tipsy.

the class JavalinConfig method applyUserConfig.

public static void applyUserConfig(Javalin app, JavalinConfig config, Consumer<JavalinConfig> userConfig) {
    // apply user config to the default config
    userConfig.accept(config);
    AtomicBoolean anyHandlerAdded = new AtomicBoolean(false);
    app.events(listener -> {
        listener.handlerAdded(x -> anyHandlerAdded.set(true));
        listener.wsHandlerAdded(x -> anyHandlerAdded.set(true));
    });
    config.getPluginsExtending(PluginLifecycleInit.class).forEach(plugin -> {
        plugin.init(app);
        if (anyHandlerAdded.get()) {
            // check if any "init" added a handler
            throw new PluginInitLifecycleViolationException(((Plugin) plugin).getClass());
        }
    });
    config.inner.plugins.values().forEach(plugin -> plugin.apply(app));
    if (config.enforceSsl) {
        app.before(SecurityUtil::sslRedirect);
    }
    config.inner.appAttributes.putIfAbsent(JSON_MAPPER_KEY, new JavalinJackson());
    app.attribute(maxRequestSizeKey, config.maxRequestSize);
    config.inner.appAttributes.putIfAbsent(CONTEXT_RESOLVER_KEY, new ContextResolver());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PluginInitLifecycleViolationException(io.javalin.core.plugin.PluginInitLifecycleViolationException) JavalinJackson(io.javalin.plugin.json.JavalinJackson) PluginLifecycleInit(io.javalin.core.plugin.PluginLifecycleInit) SecurityUtil(io.javalin.core.security.SecurityUtil) ContextResolver(io.javalin.http.ContextResolver)

Example 2 with ContextResolver

use of io.javalin.http.ContextResolver in project javalin by tipsy.

the class JavalinConfig method contextResolvers.

public void contextResolvers(@NotNull Consumer<ContextResolver> userResolver) {
    ContextResolver finalResolver = new ContextResolver();
    userResolver.accept(finalResolver);
    inner.appAttributes.put(CONTEXT_RESOLVER_KEY, finalResolver);
}
Also used : ContextResolver(io.javalin.http.ContextResolver)

Aggregations

ContextResolver (io.javalin.http.ContextResolver)2 PluginInitLifecycleViolationException (io.javalin.core.plugin.PluginInitLifecycleViolationException)1 PluginLifecycleInit (io.javalin.core.plugin.PluginLifecycleInit)1 SecurityUtil (io.javalin.core.security.SecurityUtil)1 JavalinJackson (io.javalin.plugin.json.JavalinJackson)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1