use of io.javalin.core.plugin.PluginInitLifecycleViolationException 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());
}
Aggregations