@Override public WebBeansContext from(final AppContext appCtx) { return appCtx.getWebBeansContext(); }
private String findPrefix() { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { if (appContext.getClassLoader().equals(loader)) { return appContext.getId(); } for (final WebContext web : appContext.getWebContexts()) { if (web.getClassLoader().equals(loader)) { return appContext.getId(); } } } if (1 == containerSystem.getAppContexts().size()) { return containerSystem.getAppContexts().iterator().next().getId(); } return null; }
@Deprecated public List<BeanContext> getDeployments() { return getBeanContexts(); }
private synchronized void init(final InvocationContext ic) { final AppContext appContext = findAppContext(ic); if (appContext == null) { return; } cache = appContext.get(GovernanceApplicationScopedService.class); if (cache == null) { // bad but chat can we do here? surely a lifecycle issue during bootstrap so fix it lazily cache = new GovernanceApplicationScopedService(appContext.getId()); final GovernanceApplicationScopedService existing = appContext.set(GovernanceApplicationScopedService.class, cache); if (existing != null) { // reset and use it appContext.set(GovernanceApplicationScopedService.class, existing); cache = existing; } } }
public Object beanFromClass(final String appName, final String classname) { final AppContext appContext = appContext(appName); final BeanManager bm = appContext.getBeanManager(); final Class<?> clazz; try { clazz = appContext.getClassLoader().loadClass(classname); } catch (final ClassNotFoundException e) { throw new OpenEJBRuntimeException(e); } final Set<Bean<?>> beans = bm.getBeans(clazz); return instance(bm, beans, clazz); }
final ClassLoader classLoader = appContext.getClassLoader(); return; } else { final WebBeansContext webBeansContext = appContext.getWebBeansContext(); if (webBeansContext != null) { final ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); try { final ServletContext context = appContext.isStandaloneModule() && appContext.getWebContexts().iterator().hasNext() ? appContext.getWebContexts().iterator().next().getServletContext() : null; webBeansContext.getService(ContainerLifecycle.class).stopApplication(context); } finally { final Map<String, Object> cb = appContext.getBindings(); for (final Entry<String, Object> value : cb.entrySet()) { String path = value.getKey(); for (final WebContext webContext : appContext.getWebContexts()) { containerSystem.removeWebContext(webContext); final AsynchronousPool pool = appContext.get(AsynchronousPool.class); if (pool != null) { pool.stop(); contextualJndiReference.removePrefix(appContext.getId()); if (contextualJndiReference.hasNoMorePrefix()) { globalContext.unbind(name);
final AppContext appContext = new AppContext(appInfo.appId, SystemInstance.get(), classLoader, globalJndiContext, appJndiContext, appInfo.standaloneModule); appContext.getProperties().putAll(appInfo.properties); appContext.getInjections().addAll(injections); appContext.getBindings().putAll(globalBindings); appContext.getBindings().putAll(appBindings); appContext.set(AsynchronousPool.class, AsynchronousPool.create(appContext)); new CdiBuilder().build(appInfo, appContext, allDeployments); ensureWebBeansContext(appContext); appJndiContext.bind("app/BeanManager", appContext.getBeanManager()); appContext.getBindings().put("app/BeanManager", appContext.getBeanManager()); bindGlobals(appContext.getBindings()); deployMBean(appContext.getWebBeansContext(), classLoader, mbean, appInfo.jmx, appInfo.appId); deployMBean(appContext.getWebBeansContext(), classLoader, mbean, appInfo.jmx, ejbJarInfo.moduleName); deployMBean(appContext.getWebBeansContext(), classLoader, mbean, appInfo.jmx, appInfo.appId + ".add-lib");
private static String findAppName(final WebBeansContext webBeansContext) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { if (appContext.getWebBeansContext() == webBeansContext) { return appContext.getId(); } for (final WebContext web : appContext.getWebContexts()) { if (web.getWebbeansContext() == webBeansContext) { // ear return web.getId(); } } } return "defaultDelegate"; }
final ClassLoader appContextClassLoader = appContext.getClassLoader(); if (tccl.equals(appContextClassLoader) || appContextClassLoader.equals(tccl)) { final Collection<String> tested = new ArrayList<String>(); for (final BeanContext bean : appContext.getBeanContexts()) { if (BeanContext.Comp.class.equals(bean.getBeanClass())) { final String uniqueId = bean.getModuleContext().getUniqueId(); for (final WebContext web : appContext.getWebContexts()) { final ClassLoader webClassLoader = web.getClassLoader(); if (webClassLoader.equals(tccl) || tccl.equals(webClassLoader)) {
private void validateCdiResourceProducers(final AppContext appContext, final AppInfo info) { if (appContext.getWebBeansContext() == null) { return; if (appContext.isStandaloneModule() && !appContext.getProperties().containsKey("openejb.cdi.skip-resource-validation")) { final Map<String, Object> bindings = appContext.getWebContexts().isEmpty() ? appContext.getBindings() : appContext.getWebContexts().iterator().next().getBindings(); if (bindings != null && appContext.getWebBeansContext() != null && appContext.getWebBeansContext().getBeanManagerImpl().isInUse()) { for (final Bean<?> bean : appContext.getWebBeansContext().getBeanManagerImpl().getBeans()) { if (ResourceBean.class.isInstance(bean)) { final ResourceReference reference = ResourceBean.class.cast(bean).getReference(); final CdiPlugin plugin = CdiPlugin.class.cast(appContext.getWebBeansContext().getPluginLoader().getEjbPlugin()); if (!plugin.isSessionBean(reference.getResourceType())) { // local beans are here and access is O(1) instead of O(n) boolean ok = false; for (final BeanContext bc : appContext.getBeanContexts()) { if (bc.getBusinessLocalInterfaces().contains(reference.getResourceType()) || bc.getBusinessRemoteInterfaces().contains(reference.getResourceType())) {
eagerInitOfLocalBeanProxies(appContext.getBeanContexts(), classLoader); } catch (final Exception e) { logger.error("Unable to deploy collapsed ear in war " + standardContext, e); injections.addAll(appContext.getInjections()); for (final BeanContext bean : appContext.getBeanContexts()) { // TODO: how if the same class in multiple webapps? updateInjections(bean.getInjections(), classLoader, true); webContext.setBindings(new HashMap<String, Object>()); webContext.getInjections().addAll(injections); appContext.getWebContexts().add(webContext); cs.addWebContext(webContext); standardContext.getServletContext().setAttribute("openejb.web.context", webContext); assembler.bindGlobals(appContext.getBindings()); eagerInitOfLocalBeanProxies(beanContexts, standardContext.getLoader().getClassLoader()); webContext.getBindings().putAll(appContext.getBindings()); webContext.getBindings().putAll(getJndiBuilder(classLoader, webAppInfo, injections, appContext.getProperties()).buildBindings(JndiEncBuilder.JndiScope.comp)); final WebBeansContext webBeansContext = appContext.getWebBeansContext(); if (webBeansContext != null && webBeansContext.getBeanManagerImpl().isInUse()) { OpenEJBLifecycle.initializeServletContext(standardContext.getServletContext(), webBeansContext);
private void ensureWebBeansContext(final AppContext appContext) { WebBeansContext webBeansContext = appContext.get(WebBeansContext.class); if (webBeansContext == null) { webBeansContext = appContext.getWebBeansContext(); }else{ if (null == appContext.getWebBeansContext()){ appContext.setWebBeansContext(webBeansContext); } return; } if (webBeansContext == null) { final Map<Class<?>, Object> services = new HashMap<Class<?>, Object>(); services.put(JNDIService.class, new OpenEJBJndiService()); services.put(AppContext.class, appContext); services.put(ScannerService.class, new CdiScanner()); services.put(BeanArchiveService.class, new OpenEJBBeanInfoService()); services.put(ELAdaptor.class, new CustomELAdapter(appContext)); services.put(LoaderService.class, new OptimizedLoaderService(appContext.getProperties())); final Properties properties = new Properties(); properties.setProperty(org.apache.webbeans.spi.SecurityService.class.getName(), ManagedSecurityService.class.getName()); properties.setProperty(ContextsService.class.getName(), CdiAppContextsService.class.getName()); properties.setProperty(ResourceInjectionService.class.getName(), CdiResourceInjectionService.class.getName()); properties.setProperty(TransactionService.class.getName(), OpenEJBTransactionService.class.getName()); webBeansContext = new WebBeansContext(services, properties); appContext.setCdiEnabled(false); appContext.set(WebBeansContext.class, webBeansContext); appContext.setWebBeansContext(webBeansContext); } }
@Override public String toString() { return "ServerCreated{" + "appContext=" + appContext.getId() + '}'; } }
final Set<Injection> injections = new HashSet<Injection>(appContext.getInjections()); injections.addAll(new InjectionBuilder(classLoader).buildInjections(webAppInfo.jndiEnc)); bindings.putAll(appContext.getBindings()); bindings.putAll(new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader, appInfo.properties).buildBindings(JndiEncBuilder.JndiScope.comp)); webContext.setBindings(bindings); webContext.getBindings().putAll(new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader, appInfo.properties).buildBindings(JndiEncBuilder.JndiScope.comp)); webContext.setJndiEnc(WebInitialContext.create(bindings, appContext.getGlobalJndiContext())); webContext.setClassLoader(classLoader); webContext.setId(webAppInfo.moduleId); webContext.setInitialContext(new EmbeddedInitialContext(webContext.getJndiEnc(), webContext.getBindings())); appContext.getWebContexts().add(webContext); cs.addWebContext(webContext); final Assembler assembler = SystemInstance.get().getComponent(Assembler.class); final List<BeanContext> beanContexts = assembler.initEjbs(classLoader, appInfo, appContext, injections, new ArrayList<BeanContext>(), webAppInfo.moduleId); appContext.getBeanContexts().addAll(beanContexts); new CdiBuilder().build(appInfo, appContext, appContext.getBeanContexts(), webContext); assembler.startEjbs(true, beanContexts);
@Override public void init(final ServletConfig servletConfig) throws ServletException { final String contextRoot = servletConfig.getServletContext().getContextPath(); final String context = contextRoot == null || contextRoot.equals("") ? "" : contextRoot.substring(1); app = SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(context); if (app == null) { // could be if we skip EE integration, fake an app app = new AppContext(context, SystemInstance.get(), servletConfig.getServletContext().getClassLoader(), new IvmContext(), new IvmContext(), true); app.set(GovernanceApplicationScopedService.class, new GovernanceApplicationScopedService(app.getId())); final WebContext webContext = new WebContext(app); webContext.setContextRoot(context); webContext.setHost(servletConfig.getServletContext().getServletContextName()); app.getWebContexts().add(webContext); } super.init(servletConfig); SystemInstance.get().fireEvent( new ServerCreated( server, app, app.getWebContexts().iterator().next(), contextRoot)); app = null; }
@Override public void execute(final String cmd) { final String appName = extractAppName(cmd); final ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext ctx : cs.getAppContexts()) { if (appName.equalsIgnoreCase(ctx.getId())) { dumpClassLoader(ctx.getClassLoader()); return; } } streamManager.writeErr("can't find app " + appName); streamManager.writeErr("available apps are:"); for (final AppContext ctx : cs.getAppContexts()) { streamManager.writeErr("- " + ctx.getId()); } }
final Context appContext = application.getAppJndiContext(); final Context globalContext = application.getGlobalJndiContext(); final String appName = application.isStandaloneModule() ? "" : application.getId() + "/"; String moduleName = cdi.getModuleName() + "/"; if (moduleName.startsWith("/")) { application.getBindings().put(globalName, ref); application.getBindings().put("app/" + moduleName + beanName, ref); application.getBindings().put("module/" + beanName, ref);
injections.addAll(appContext.getInjections()); injections.addAll(new InjectionBuilder(classLoader).buildInjections(webAppInfo.jndiEnc)); bindings.putAll(appContext.getBindings()); bindings.putAll(getJndiBuilder(classLoader, webAppInfo, injections).buildBindings(JndiEncBuilder.JndiScope.comp)); webContext.setBindings(bindings); webContext.getInjections().addAll(injections); appContext.getWebContexts().add(webContext); cs.addWebContext(webContext); if (factory != null) { JspApplicationContext applicationCtx = factory.getJspApplicationContext(standardContext.getServletContext()); WebBeansContext context = appContext.getWebBeansContext(); if (context != null && context.getBeanManagerImpl().isInUse()) {
private void doInit(final AppContext context) { if (context.get(ServicesManager.class) != null) { return; } final Thread thread = Thread.currentThread(); final ClassLoader current = thread.getContextClassLoader(); thread.setContextClassLoader(context.getClassLoader()); final ServicesManager servicesManager = new ServicesManager(); final Properties properties = new Properties(SystemInstance.get().getProperties()); properties.putAll(context.getProperties()); try { if (properties.getProperty(BatchArtifactFactory.class.getName()) == null) { properties.setProperty(BatchThreadPoolService.class.getName(), TomEEThreadPoolService.class.getName()); } if (properties.getProperty(BatchArtifactFactory.class.getName()) == null) { properties.setProperty(BatchArtifactFactory.class.getName(), TomEEArtifactFactory.class.getName()); } servicesManager.init(properties); // will look for batchee.properties so need the right classloader } finally { thread.setContextClassLoader(current); } context.set(ServicesManager.class, servicesManager); }
public static <T> T findAppContextOrWeb(final ClassLoader cl, final Transformer<T> transformer) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { final ClassLoader appContextClassLoader = appContext.getClassLoader(); if (appContextClassLoader.equals(cl) || (cl != null && cl.equals(appContextClassLoader))) { // CxfContainerLoader is not symmetric return transformer.from(appContext); } for (final WebContext web : appContext.getWebContexts()) { final ClassLoader webClassLoader = web.getClassLoader(); if (webClassLoader.equals(cl) || (cl != null && cl.equals(webClassLoader))) { return transformer.from(web); } } } return null; }