Search in sources :

Example 16 with App

use of act.app.App in project actframework by actframework.

the class RequestHandlerProxy method generateHandlers.

private void generateHandlers() {
    ControllerClassMetaInfo ctrlInfo = app.classLoader().controllerClassMetaInfo(controllerClassName);
    ActionMethodMetaInfo actionInfo = ctrlInfo.action(actionMethodName);
    if (null == actionInfo) {
        actionInfo = findActionInfoFromParent(ctrlInfo, actionMethodName);
    }
    webSocketConnectionHandler = tryGenerateWebSocketConnectionHandler(actionInfo);
    // if (null != webSocketConnectionHandler) {
    // return;
    // }
    Act.Mode mode = Act.mode();
    actionHandler = mode.createRequestHandler(actionInfo, app);
    actionMethod = actionHandler.invoker().invokeMethod();
    sessionFree = actionHandler.sessionFree();
    missingAuthenticationHandler = actionHandler.missingAuthenticationHandler();
    csrfFailureHandler = actionHandler.csrfFailureHandler();
    express = actionHandler.express();
    cacheSupport = actionHandler.cacheSupport();
    supportCache = cacheSupport.enabled;
    App app = this.app;
    if (supportCache) {
        cache = app.cache();
    }
    GroupInterceptorMetaInfo interceptorMetaInfo = new GroupInterceptorMetaInfo(actionInfo.interceptors());
    interceptorMetaInfo.mergeFrom(globalFreeStyleInterceptor);
    for (GroupInterceptorMetaInfo freeStyleInterceptor : globalFreeStyleInterceptors) {
        interceptorMetaInfo.mergeFrom(freeStyleInterceptor);
    }
    for (InterceptorMethodMetaInfo info : interceptorMetaInfo.beforeList()) {
        if (!applied(info)) {
            continue;
        }
        BeforeInterceptor interceptor = mode.createBeforeInterceptor(info, app);
        beforeInterceptors.add(interceptor);
        sessionFree = sessionFree && interceptor.sessionFree();
        express = express && interceptor.express();
    }
    for (InterceptorMethodMetaInfo info : interceptorMetaInfo.afterList()) {
        if (!applied(info)) {
            continue;
        }
        AfterInterceptor interceptor = mode.createAfterInterceptor(info, app);
        afterInterceptors.add(interceptor);
        sessionFree = sessionFree && interceptor.sessionFree();
        express = express && interceptor.express();
    }
    for (CatchMethodMetaInfo info : interceptorMetaInfo.catchList()) {
        if (!applied(info)) {
            continue;
        }
        ExceptionInterceptor interceptor = mode.createExceptionInterceptor(info, app);
        exceptionInterceptors.add(interceptor);
        sessionFree = sessionFree && interceptor.sessionFree();
        express = express && interceptor.express();
    }
    Collections.sort(exceptionInterceptors);
    for (InterceptorMethodMetaInfo info : interceptorMetaInfo.finallyList()) {
        if (!applied(info)) {
            continue;
        }
        FinallyInterceptor interceptor = mode.createFinallyInterceptor(info, app);
        finallyInterceptors.add(interceptor);
        sessionFree = sessionFree && interceptor.sessionFree();
        express = express && interceptor.express();
    }
}
Also used : App(act.app.App) Act(act.Act)

Example 17 with App

use of act.app.App in project actframework by actframework.

the class FindBy method initialized.

@Override
protected void initialized() {
    App app = App.instance();
    rawType = spec.rawType();
    notNull = spec.hasAnnotation(NotNull.class);
    findOne = !(Iterable.class.isAssignableFrom(rawType));
    dao = app.dbServiceManager().dao(findOne ? rawType : (Class) spec.typeParams().get(0));
    queryFieldName = S.string(options.get("field"));
    byId = findOne && S.blank(queryFieldName) && (Boolean) options.get("byId");
    resolver = app.resolverManager().resolver(byId ? dao.idType() : (Class) options.get("fieldType"));
    if (null == resolver) {
        throw new IllegalArgumentException("Cannot find String value resolver for type: " + dao.idType());
    }
    requestParamName = S.string(value());
    if (S.blank(requestParamName)) {
        requestParamName = ParamValueLoaderService.bindName(spec);
    }
    if (!byId) {
        if (S.blank(queryFieldName)) {
            queryFieldName = requestParamName;
        }
    }
}
Also used : App(act.app.App) NotNull(javax.validation.constraints.NotNull)

Example 18 with App

use of act.app.App in project actframework by actframework.

the class ReflectedSimpleEventListener method host.

private Object host() {
    if (isStatic) {
        return null;
    } else {
        if (null == host) {
            synchronized (this) {
                if (null == host) {
                    App app = App.instance();
                    host = app.getInstance(hostClass);
                }
            }
        }
        return host;
    }
}
Also used : App(act.app.App)

Example 19 with App

use of act.app.App in project actframework by actframework.

the class ReflectedSimpleEventListener method invoke.

@Override
public void invoke(Object... args) {
    int paramNo = paramTypes.size();
    int argsNo = args.length;
    Object[] realArgs = args;
    if (paramNo != argsNo || providedParamSize > 0) {
        realArgs = new Object[paramNo + providedParamSize];
        System.arraycopy(args, 0, realArgs, 0, Math.min(paramNo, argsNo));
        App app = Act.app();
        for (int i = 0; i < providedParamSize; ++i) {
            realArgs[i + paramNo] = app.getInstance(providedParamTypes.get(i));
        }
    }
    Object host = host();
    if (null == host) {
        $.invokeStatic(method, realArgs);
    } else {
        $.invokeVirtual(host, method, realArgs);
    }
}
Also used : App(act.app.App)

Aggregations

App (act.app.App)19 AppConfig (act.conf.AppConfig)2 SubClassFinder (act.util.SubClassFinder)2 Type (java.lang.reflect.Type)2 Act (act.Act)1 SysEventListenerBase (act.event.SysEventListenerBase)1 DependencyInjector (act.inject.DependencyInjector)1 DuplicateRouteMappingException (act.route.DuplicateRouteMappingException)1 AnnotatedClassFinder (act.util.AnnotatedClassFinder)1 ClassInfoRepository (act.util.ClassInfoRepository)1 ClassNode (act.util.ClassNode)1 Template (act.view.Template)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 ArrayList (java.util.ArrayList)1 NotNull (javax.validation.constraints.NotNull)1 BeforeClass (org.junit.BeforeClass)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1