Search in sources :

Example 1 with AppConfig

use of act.conf.AppConfig in project actframework by actframework.

the class ApiManager method load.

public void load(App app) {
    LOGGER.info("start compiling API book");
    Router router = app.router();
    AppConfig config = app.config();
    Set<Class> controllerClasses = new HashSet<>();
    load(router, null, config, controllerClasses);
    for (NamedPort port : app.config().namedPorts()) {
        router = app.router(port);
        load(router, port, config, controllerClasses);
    }
    if (Act.isDev()) {
        exploreDescriptions(controllerClasses);
    }
}
Also used : AppConfig(act.conf.AppConfig) Router(act.route.Router) NamedPort(act.app.util.NamedPort)

Example 2 with AppConfig

use of act.conf.AppConfig in project actframework by actframework.

the class ActionContext method applyGlobalCorsSetting.

private void applyGlobalCorsSetting() {
    if (this.disableCors) {
        return;
    }
    AppConfig conf = config();
    if (!conf.corsEnabled()) {
        return;
    }
    H.Response r = resp();
    r.addHeaderIfNotAdded(ACCESS_CONTROL_ALLOW_ORIGIN, conf.corsAllowOrigin());
    if (request.method() == H.Method.OPTIONS || !conf.corsOptionCheck()) {
        r.addHeaderIfNotAdded(ACCESS_CONTROL_ALLOW_HEADERS, conf.corsAllowHeaders());
        r.addHeaderIfNotAdded(ACCESS_CONTROL_ALLOW_CREDENTIALS, S.string(conf.corsAllowCredentials()));
        r.addHeaderIfNotAdded(ACCESS_CONTROL_EXPOSE_HEADERS, conf.corsExposeHeaders());
        r.addHeaderIfNotAdded(ACCESS_CONTROL_MAX_AGE, S.string(conf.corsMaxAge()));
    }
}
Also used : AppConfig(act.conf.AppConfig) H(org.osgl.http.H)

Example 3 with AppConfig

use of act.conf.AppConfig in project actframework by actframework.

the class AppClassLoader method preloadLib.

private void preloadLib() {
    final Map<String, byte[]> bytecodeIdx = new HashMap<>();
    final Map<String, Properties> jarConf = new HashMap<>();
    final $.Function<String, Boolean> ignoredClassNames = app().config().appClassTester().negate();
    Jars.F.JarEntryVisitor classNameIndexBuilder = Jars.F.classNameIndexBuilder(bytecodeIdx, ignoredClassNames);
    Jars.F.JarEntryVisitor confIndexBuilder = Jars.F.appConfigFileIndexBuilder(jarConf);
    List<File> jars = FullStackAppBootstrapClassLoader.jars(AppClassLoader.class.getClassLoader());
    for (File jar : jars) {
        Jars.scan(jar, classNameIndexBuilder, confIndexBuilder);
    }
    libClsCache.putAll(bytecodeIdx);
    AppConfig config = app().config();
    config.loadJarProperties(jarConf);
}
Also used : AppConfig(act.conf.AppConfig) org.osgl.$(org.osgl.$) File(java.io.File)

Example 4 with AppConfig

use of act.conf.AppConfig in project actframework by actframework.

the class RouterTestBase method prepareClass.

@BeforeClass
public static void prepareClass() throws Exception {
    AppConfig config = appConfig();
    app = mock(App.class);
    when(app.config()).thenReturn(config);
    when(app.file(anyString())).thenAnswer(new Answer<File>() {

        @Override
        public File answer(InvocationOnMock invocation) throws Throwable {
            String path = (String) invocation.getArguments()[0];
            return new File(BASE, path);
        }
    });
    Field f = App.class.getDeclaredField("INST");
    f.setAccessible(true);
    f.set(null, app);
}
Also used : App(act.app.App) AppConfig(act.conf.AppConfig) Field(java.lang.reflect.Field) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 5 with AppConfig

use of act.conf.AppConfig in project actframework by actframework.

the class ViewManager method load.

public Template load(ActContext context) {
    Template cached = context.cachedTemplate();
    if (null != cached) {
        return cached;
    }
    AppConfig config = context.config();
    Template template;
    String templateContent = context.templateContent();
    if (S.notEmpty(templateContent)) {
        template = getInlineTemplate(context, config, templateContent);
    } else {
        TemplatePathResolver resolver = config.templatePathResolver();
        String path = resolver.resolve(context);
        template = getTemplate(context, config, path);
        if (null == template) {
            String amendedPath = resolver.resolveWithContextMethodPath(context);
            if (S.neq(amendedPath, path)) {
                template = getTemplate(context, config, amendedPath);
                if (null != template) {
                    context.templatePath(amendedPath);
                }
            }
        }
    }
    return template;
}
Also used : AppConfig(act.conf.AppConfig)

Aggregations

AppConfig (act.conf.AppConfig)7 App (act.app.App)2 File (java.io.File)2 NamedPort (act.app.util.NamedPort)1 Router (act.route.Router)1 VarDef (act.view.VarDef)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 BeforeClass (org.junit.BeforeClass)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 org.osgl.$ (org.osgl.$)1 H (org.osgl.http.H)1 RythmEngine (org.rythmengine.RythmEngine)1 ISourceCodeEnhancer (org.rythmengine.extension.ISourceCodeEnhancer)1 ClasspathResourceLoader (org.rythmengine.resource.ClasspathResourceLoader)1