Search in sources :

Example 6 with EzyBeanContext

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

the class EzyUserRequestPluginSingletonControllerTest method test.

@Test
public void test() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzyZoneUserManager zoneUserManager = EzyZoneUserManagerImpl.builder().zoneName("test").build();
    zone.setUserManager(zoneUserManager);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("test");
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimplePlugin plugin = new EzySimplePlugin();
    plugin.setSetting(pluginSetting);
    plugin.setEventControllers(eventControllers);
    ScheduledExecutorService pluginScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimplePluginContext pluginContext = new EzySimplePluginContext();
    pluginContext.setPlugin(plugin);
    pluginContext.setParent(zoneContext);
    pluginContext.setExecutorService(pluginScheduledExecutorService);
    pluginContext.init();
    EzySimplePluginEntry entry = new EzyPluginEntryEx();
    entry.config(pluginContext);
    entry.start();
    handleClientRequest(pluginContext);
    EzyBeanContext beanContext = pluginContext.get(EzyBeanContext.class);
    EzyRequestCommandManager requestCommandManager = beanContext.getSingleton(EzyRequestCommandManager.class);
    EzyFeatureCommandManager featureCommandManager = beanContext.getSingleton(EzyFeatureCommandManager.class);
    Asserts.assertTrue(requestCommandManager.containsCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.isManagementCommand("v1.2.2/hello"));
    Asserts.assertTrue(requestCommandManager.isPaymentCommand("v1.2.2/hello"));
    Asserts.assertEquals(featureCommandManager.getFeatureByCommand("v1.2.2/hello"), "hello.world");
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzySimplePluginEntry(com.tvd12.ezyfoxserver.support.entry.EzySimplePluginEntry) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 7 with EzyBeanContext

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

the class EzySimpleAppEntry method createBeanContext.

protected EzyBeanContext createBeanContext(EzyAppContext context) {
    EzyBindingContext bindingContext = createBindingContext();
    EzyMarshaller marshaller = bindingContext.newMarshaller();
    EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
    EzyResponseFactory appResponseFactory = createAppResponseFactory(context, marshaller);
    ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
    EzyAppSetting appSetting = context.getApp().getSetting();
    EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("appContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("userManager", context.getApp().getUserManager()).addSingleton("appResponseFactory", appResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(appSetting.getActiveProfiles());
    Class[] singletonClasses = getSingletonClasses();
    beanContextBuilder.addSingletonClasses(singletonClasses);
    Class[] prototypeClasses = getPrototypeClasses();
    beanContextBuilder.addPrototypeClasses(prototypeClasses);
    Set<String> scanablePackages = internalGetScanableBeanPackages();
    if (appSetting.getPackageName() != null) {
        scanablePackages.add(appSetting.getPackageName());
    }
    EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyAppEventController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
    beanContextBuilder.scan(scanablePackages);
    setupBeanContext(context, beanContextBuilder);
    return beanContextBuilder.build();
}
Also used : EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyUnmarshaller(com.tvd12.ezyfox.binding.EzyUnmarshaller) EzyMarshaller(com.tvd12.ezyfox.binding.EzyMarshaller) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) EzyReflectionProxy(com.tvd12.ezyfox.reflect.EzyReflectionProxy) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection)

Example 8 with EzyBeanContext

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

the class EzySimpleAppEntry method config.

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

Example 9 with EzyBeanContext

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

the class EzySimpleAppEntry method addEventControllers.

private void addEventControllers(EzyAppContext appContext, EzyBeanContext beanContext) {
    EzySetup setup = appContext.get(EzySetup.class);
    List<Object> eventControllers = beanContext.getSingletons(EzyEventHandler.class);
    sortEventHandlersByPriority(eventControllers);
    for (Object controller : eventControllers) {
        Class<?> controllerType = controller.getClass();
        EzyEventHandler annotation = controllerType.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)

Example 10 with EzyBeanContext

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

the class EzySimplePluginEntry method setPluginRequestController.

private void setPluginRequestController(EzyPluginContext pluginContext, EzyBeanContext beanContext) {
    if (!allowRequest() || getClass().isAnnotationPresent(EzyDisallowRequest.class)) {
        return;
    }
    EzyPluginSetup setup = pluginContext.get(EzyPluginSetup.class);
    EzyPluginRequestController controller = newUserRequestController(beanContext);
    setup.setRequestController(controller);
    Set<String> commands = ((EzyCommandsAware) controller).getCommands();
    pluginContext.setProperty(COMMANDS, commands);
}
Also used : EzyPluginSetup(com.tvd12.ezyfoxserver.command.EzyPluginSetup) EzyCommandsAware(com.tvd12.ezyfoxserver.support.controller.EzyCommandsAware) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyDisallowRequest(com.tvd12.ezyfoxserver.support.annotation.EzyDisallowRequest)

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