public void initialize(final StartupObject startupObject) {
if (sessionContextClass == null) { // done here cause Cdibuilder trigger this class loading and that's from Warmup so we can't init too early config
sessionContextClass = SystemInstance.get().getProperty("openejb.session-context", "").trim();
}
final AppContext appContext = startupObject.getAppContext();
appContext.setCdiEnabled(hasBeans(startupObject.getAppInfo()));
//initialize owb context, cf geronimo's OpenWebBeansGBean
final Properties properties = new Properties();
final Map<Class<?>, Object> services = new HashMap<Class<?>, Object>();
properties.setProperty(OpenWebBeansConfiguration.APPLICATION_IS_JSP, "true");
properties.setProperty(OpenWebBeansConfiguration.USE_EJB_DISCOVERY, "true");
//from CDI builder
properties.setProperty(OpenWebBeansConfiguration.INTERCEPTOR_FORCE_NO_CHECKED_EXCEPTIONS, "false");
properties.setProperty(SecurityService.class.getName(), ManagedSecurityService.class.getName());
properties.setProperty(OpenWebBeansConfiguration.CONVERSATION_PERIODIC_DELAY, "1800000");
properties.setProperty(OpenWebBeansConfiguration.APPLICATION_SUPPORTS_CONVERSATION, "true");
properties.setProperty(OpenWebBeansConfiguration.IGNORED_INTERFACES, "org.apache.aries.proxy.weaving.WovenProxy");
final String failoverService = startupObject.getAppInfo().properties.getProperty("org.apache.webbeans.spi.FailOverService",
SystemInstance.get().getProperty("org.apache.webbeans.spi.FailOverService",
null));
if (failoverService != null) {
properties.setProperty(OpenWebBeansConfiguration.IGNORED_INTERFACES, failoverService);
}
final boolean tomee = SystemInstance.get().getProperty("openejb.loader", "foo").startsWith("tomcat");
properties.setProperty("org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped", ApplicationScopedBeanInterceptorHandler.class.getName());
if (tomee) {
properties.setProperty("org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped", RequestScopedBeanInterceptorHandler.class.getName());
} else {
properties.setProperty("org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped", NormalScopedBeanInterceptorHandler.class.getName());
}
if (sessionContextClass() != null && tomee) {
properties.setProperty("org.apache.webbeans.proxy.mapping.javax.enterprise.context.SessionScoped", "org.apache.tomee.catalina.cdi.SessionNormalScopeBeanHandler");
}
if (SystemInstance.get().getOptions().get(WEBBEANS_FAILOVER_ISSUPPORTFAILOVER, false)) {
properties.setProperty(WEBBEANS_FAILOVER_ISSUPPORTFAILOVER, "true");
}
properties.putAll(appContext.getProperties());
services.put(AppContext.class, appContext);
services.put(JNDIService.class, new OpenEJBJndiService());
services.put(TransactionService.class, new OpenEJBTransactionService());
services.put(ELAdaptor.class, new CustomELAdapter(appContext));
services.put(ScannerService.class, new CdiScanner());
final LoaderService loaderService = SystemInstance.get().getComponent(LoaderService.class);
if (loaderService == null) {
services.put(LoaderService.class, new OptimizedLoaderService());
} else {
services.put(LoaderService.class, loaderService);
}
optional(services, ConversationService.class, "org.apache.webbeans.jsf.DefaultConversationService");
final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
final ClassLoader cl;
if (oldClassLoader != ThreadSingletonServiceImpl.class.getClassLoader() && ThreadSingletonServiceImpl.class.getClassLoader() != oldClassLoader.getParent()) {
cl = new MultipleClassLoader(oldClassLoader, ThreadSingletonServiceImpl.class.getClassLoader());
} else {
cl = oldClassLoader;
}
Thread.currentThread().setContextClassLoader(cl);
final WebBeansContext webBeansContext;
Object old = null;
try {
if (startupObject.getWebContext() == null) {
webBeansContext = new WebBeansContext(services, properties);
appContext.set(WebBeansContext.class, webBeansContext);
} else {
webBeansContext = new WebappWebBeansContext(services, properties, appContext.getWebBeansContext());
startupObject.getWebContext().setWebbeansContext(webBeansContext);
}
final BeanManagerImpl beanManagerImpl = webBeansContext.getBeanManagerImpl();
beanManagerImpl.addContext(new TransactionContext());
beanManagerImpl.addAdditionalInterceptorBindings(Transactional.class);