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();
}
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();
}
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);
}
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);
}
}
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);
}
Aggregations