Search in sources :

Example 26 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyhttp by youngmonkeys.

the class EzyHttpApplicationTest method test.

@Test
public void test() throws Exception {
    // given
    EzyHttpApplication sut = EzyHttpApplication.start(EzyHttpApplicationTest.class);
    ApplicationContext applicationContext = sut.getApplicationContext();
    EzyBeanContext beanContext = applicationContext.getBeanContext();
    // when
    int actualOneProp = beanContext.getProperty("one", int.class);
    boolean managementEnable = beanContext.getProperty("management.enable", boolean.class);
    UserService userService = beanContext.getSingleton(UserService.class);
    ViewContextBuilder viewContextBuilder = beanContext.getSingleton(ViewContextBuilder.class);
    ResourceResolver resourceResolver = beanContext.getSingleton(ResourceResolver.class);
    ResourceDownloadManager resourceDownloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
    // then
    Asserts.assertEquals(1, actualOneProp);
    Asserts.assertTrue(managementEnable);
    Asserts.assertNotNull(userService);
    Asserts.assertNotNull(viewContextBuilder);
    Asserts.assertNotNull(resourceDownloadManager);
    Asserts.assertEquals(4, resourceResolver.getResources().size());
    sut.stop();
}
Also used : ApplicationContext(com.tvd12.ezyhttp.server.core.ApplicationContext) ResourceDownloadManager(com.tvd12.ezyhttp.core.resources.ResourceDownloadManager) EzyHttpApplication(com.tvd12.ezyhttp.server.core.EzyHttpApplication) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) UserService(com.tvd12.ezyhttp.server.core.test.service.UserService) ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) ViewContextBuilder(com.tvd12.ezyhttp.server.core.view.ViewContextBuilder) Test(org.testng.annotations.Test)

Example 27 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyhttp by youngmonkeys.

the class ApplicationContextBuilder method registerComponents.

protected void registerComponents(EzyBeanContext beanContext) {
    Set controllers = new HashSet<>();
    controllers.addAll(beanContext.getSingletons(Controller.class));
    controllers.addAll(beanContext.getSingletonsOf(IRequestController.class));
    controllerManager.addControllers(controllers);
    List exceptionHandlers = beanContext.getSingletons(ExceptionHandler.class);
    exceptionHandlerManager.addExceptionHandlers(exceptionHandlers);
    List<RequestInterceptor> requestInterceptors = beanContext.getSingletons(Interceptor.class);
    requestInterceptors.sort(InterceptorAnnotations.comparator());
    interceptorManager.addRequestInterceptors(requestInterceptors);
    List bodyConverters = beanContext.getSingletons(BodyConvert.class);
    dataConverters.addBodyConverters(bodyConverters);
    List stringConverters = beanContext.getSingletons(StringConvert.class);
    List uncaughtErrorHandlers = beanContext.getSingletonsOf(UnhandledErrorHandler.class);
    List requestResponseWathcers = beanContext.getSingletonsOf(RequestResponseWatcher.class);
    dataConverters.setStringConverters(stringConverters);
    componentManager.setViewContext(buildViewContext(beanContext));
    componentManager.setServerPort(getServerPort(beanContext));
    componentManager.setExposeManagementURIs(isExposeManagementURIs(beanContext));
    componentManager.setManagementPort(getManagementPort(beanContext));
    componentManager.setAsyncDefaultTimeout(getAsyncDefaultTimeout(beanContext));
    componentManager.setUnhandledErrorHandler(uncaughtErrorHandlers);
    componentManager.addRequestResponseWatchers(requestResponseWathcers);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IRequestController(com.tvd12.ezyhttp.server.core.handler.IRequestController) List(java.util.List) ArrayList(java.util.ArrayList) RequestInterceptor(com.tvd12.ezyhttp.server.core.interceptor.RequestInterceptor) Controller(com.tvd12.ezyhttp.server.core.annotation.Controller) IRequestController(com.tvd12.ezyhttp.server.core.handler.IRequestController) HashSet(java.util.HashSet)

Example 28 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntry method setAppRequestController.

private void setAppRequestController(EzyAppContext appContext, EzyBeanContext beanContext) {
    EzyAppSetup setup = appContext.get(EzyAppSetup.class);
    EzyAppRequestController controller = newUserRequestController(beanContext);
    setup.setRequestController(controller);
    Set<String> commands = ((EzyCommandsAware) controller).getCommands();
    appContext.setProperty(COMMANDS, commands);
}
Also used : EzyCommandsAware(com.tvd12.ezyfoxserver.support.controller.EzyCommandsAware) EzyAppSetup(com.tvd12.ezyfoxserver.command.EzyAppSetup) EzyAppRequestController(com.tvd12.ezyfoxserver.app.EzyAppRequestController)

Example 29 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntry method config.

@Override
public void config(EzyPluginContext context) {
    preConfig(context);
    EzyBeanContext beanContext = createBeanContext(context);
    context.setProperty(EzyBeanContext.class, beanContext);
    addEventControllers(context, beanContext);
    setPluginRequestController(context, beanContext);
    postConfig(context);
    postConfig(context, beanContext);
}
Also used : EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext)

Example 30 with EzyBeanContext

use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntry method addEventControllers.

private void addEventControllers(EzyPluginContext context, EzyBeanContext beanContext) {
    EzySetup setup = context.get(EzySetup.class);
    List<Object> eventControllers = beanContext.getSingletons(EzyEventHandler.class);
    sortEventHandlersByPriority(eventControllers);
    for (Object controller : eventControllers) {
        Class<?> handlerType = controller.getClass();
        EzyEventHandler annotation = handlerType.getAnnotation(EzyEventHandler.class);
        String eventName = EzyEventHandlerAnnotations.getEvent(annotation);
        setup.addEventController(EzyEventType.valueOf(eventName), (EzyEventController) controller);
        logger.info("add  event {} controller {}", eventName, controller);
    }
}
Also used : EzyEventHandler(com.tvd12.ezyfox.core.annotation.EzyEventHandler) EzySetup(com.tvd12.ezyfoxserver.command.EzySetup)

Aggregations

EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)25 Test (org.testng.annotations.Test)15 ApplicationContextBuilder (com.tvd12.ezyhttp.server.core.ApplicationContextBuilder)6 ResourceResolver (com.tvd12.ezyhttp.server.core.resources.ResourceResolver)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)6 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)5 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)5 ApplicationContext (com.tvd12.ezyhttp.server.core.ApplicationContext)5 ViewContextBuilder (com.tvd12.ezyhttp.server.core.view.ViewContextBuilder)5 ViewContext (com.tvd12.ezyhttp.server.core.view.ViewContext)4 List (java.util.List)4 Calabash (com.tvd12.calabash.Calabash)3 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)3 EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)3 EzyFeatureCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager)3 EzyRequestCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager)3 MongoClient (com.mongodb.MongoClient)2 StatisticsAware (com.tvd12.calabash.core.statistic.StatisticsAware)2 CalabashBuilder (com.tvd12.calabash.local.CalabashBuilder)2 SimpleEntityMapPersistSetting (com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting)2