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