@Override public BeanManager getBeanManager() { checkContainerState(container); final String callerName = getCallingClassName(); if(callerName.startsWith("org.glassfish.soteria")) { //the Java EE Security RI uses CDI.current() to perform bean lookup, however //as it is part of the container its bean archive does not have visibility to deployment beans //we use this code path to enable it to get the bean manager of the current module //so it can look up the deployment beans it needs to work try { BeanManager bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); if(bm != null) { return bm; } } catch (NamingException e) { //ignore } } final ClassLoader tccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); final Class<?> callerClass = Reflections.loadClass(callerName, tccl); if (callerClass != null) { final BeanDeploymentArchive bda = deployment.getBeanDeploymentArchive(callerClass); if (bda != null) { return new BeanManagerProxy(container.beanDeploymentArchives().get(bda)); } } // fallback for cases when we are unable to load the class or no BeanManager exists yet for the given BDA return rootBeanManager; }
final BeanManager manager = (BeanManager) new InitialContext().lookup(STANDARD_BEAN_MANAGER_JNDI_NAME); if (manager != null && Container.available()) {
@Override public void run() { WeldLogger.DEPLOYMENT_LOGGER.debugf("Weld container cleanup for deployment %s", deploymentName); ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager .setCurrentContextClassLoaderPrivileged(deployment.getModule().getClassLoader()); WeldProvider.containerShutDown(container); container.setState(ContainerState.SHUTDOWN); container.cleanup(); setStarted(false); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl); ModuleGroupSingletonProvider.removeClassLoader(deployment.getModule().getClassLoader()); context.complete(); } } };
public Instance<Context> instance() { // This is safe -- context beans are *always* available return Container.instance().deploymentManager().instance().select(Context.class); }
public void shutdown() { try { // The container must destroy all contexts. // For non-web modules, fire @BeforeDestroyed event fireEventForNonWebModules(Object.class, ContextEvent.APPLICATION_BEFORE_DESTROYED, BeforeDestroyed.Literal.APPLICATION); deploymentManager.instance().select(ApplicationContext.class).get().invalidate(); deploymentManager.instance().select(SingletonContext.class).get().invalidate(); } finally { // fire @Destroyed(ApplicationScope.class) for non-web modules fireEventForNonWebModules(Object.class, ContextEvent.APPLICATION_DESTROYED, Destroyed.Literal.APPLICATION); try { // Finally, the container must fire an event of type BeforeShutdown. BeforeShutdownImpl.fire(deploymentManager); } finally { Container container = Container.instance(contextId); container.setState(ContainerState.SHUTDOWN); container.cleanup(); } } }
public void shutdown() { try { deploymentManager.instance().select(ApplicationContext.class).get().invalidate(); deploymentManager.instance().select(SingletonContext.class).get().invalidate(); BeanDeploymentModules modules = deploymentManager.getServices().get(BeanDeploymentModules.class); if (modules != null) { Container container = Container.instance(contextId); container.setState(ContainerState.SHUTDOWN); container.cleanup();
/** * Always returns the original proxy object that was serialized. * * @return the proxy object * @throws java.io.ObjectStreamException */ Object readResolve() throws ObjectStreamException { Bean<?> bean = Container.instance(contextId).services().get(ContextualStore.class).<Bean<Object>, Object>getContextual(beanId); if (bean == null) { throw BeanLogger.LOG.proxyDeserializationFailure(beanId); } return Container.instance(contextId).deploymentManager().getClientProxyProvider().getClientProxy(bean); }
protected AnnotatedTypeLoader createAnnotatedTypeLoader() { if (classFileServices != null) { // Since FastProcessAnnotatedTypeResolver is installed after BeanDeployers are created, we need to query deploymentManager's services instead of the manager of this deployer final FastProcessAnnotatedTypeResolver resolver = Container.instance(getManager()).deploymentManager().getServices() .get(FastProcessAnnotatedTypeResolver.class); if (resolver != null) { return new FastAnnotatedTypeLoader(getManager(), classTransformer, classFileServices, containerLifecycleEvents, resolver); } } // if FastProcessAnnotatedTypeResolver is not available, fall back to AnnotatedTypeLoader return new AnnotatedTypeLoader(getManager(), classTransformer, containerLifecycleEvents); }
public Bean<?> getBean() { if (bean == null) { if (beanId == null) { throw BeanLogger.LOG.proxyHandlerSerializedForNonSerializableBean(); } bean = Container.instance(contextId).services().get(ContextualStore.class).<Bean<Object>, Object>getContextual(beanId); } return bean; }
private <T> T createClientProxy(Bean<T> bean, Set<Type> types) { BeanIdentifier id = Container.instance(contextId).services().get(ContextualStore.class).putIfAbsent(bean); if (id == null) { throw BeanLogger.LOG.beanIdCreationFailed(bean); } BeanInstance beanInstance = new ContextBeanInstance<T>(bean, id, contextId); TypeInfo typeInfo = TypeInfo.of(types); T proxy = new ClientProxyFactory<T>(contextId, typeInfo.getSuperClass(), types, bean).create(beanInstance); BeanLogger.LOG.createdNewClientProxyType(proxy.getClass(), bean, id); return proxy; }
public InjectionTargetService(BeanManagerImpl beanManager) { this.validator = beanManager.getServices().get(Validator.class); this.producersToValidate = new ConcurrentLinkedQueue<Producer<?>>(); this.injectionTargetsToInitialize = new ConcurrentLinkedQueue<InjectionTargetInitializationContext<?>>(); this.container = Container.instance(beanManager); this.beanManager = beanManager; }
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { if (Container.available(contextId)) { for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : Container.instance(contextId).beanDeploymentArchives().entrySet()) { BeanDeploymentArchive bda = entry.getKey(); if (bda.getId().equals(FLAT_BEAN_DEPLOYMENT_ID) || bda.getId().contains(WEB_INF_CLASSES_FILE_PATH) || bda.getId().contains(WEB_INF_CLASSES)) { return entry.getValue(); } } throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } else { throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } }
public BeanManagerImpl locate() { try { return (BeanManagerImpl) new InitialContext().lookup("java:comp/BeanManager"); } catch (Exception e) { // Try the next method } // Locate via the BDA id "test" for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : Container.instance().beanDeploymentArchives().entrySet()) { if (entry.getKey().getId().equals("test")) { return entry.getValue(); } } throw new IllegalStateException(); }
private static BeanManagerImpl getBeanManager(ServletContext ctx) { BeanDeploymentArchive war = Container.instance().services().get(ServletServices.class).getBeanDeploymentArchive(ctx); if (war == null) { throw new ForbiddenStateException(BEAN_DEPLOYMENT_ARCHIVE_MISSING, ctx); } BeanManagerImpl beanManager = Container.instance().beanDeploymentArchives().get(war); if (beanManager == null) { throw new ForbiddenStateException(BEAN_MANAGER_FOR_ARCHIVE_NOT_FOUND, ctx, war); } return beanManager; }
public AbstractConversationContext(String contextId, ServiceRegistry services) { super(contextId, true); this.parameterName = new AtomicReference<String>(PARAMETER_NAME); WeldConfiguration configuration = services.get(WeldConfiguration.class); this.defaultTimeout = new AtomicLong(configuration.getLongProperty(ConfigurationKey.CONVERSATION_TIMEOUT)); this.concurrentAccessTimeout = new AtomicLong(configuration.getLongProperty(ConfigurationKey.CONVERSATION_CONCURRENT_ACCESS_TIMEOUT)); this.associated = new ThreadLocal<R>(); this.manager = Container.instance(contextId).deploymentManager(); this.beanIdentifierIndex = services.get(BeanIdentifierIndex.class); }
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { if (Container.available(contextId)) { for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : Container.instance(contextId).beanDeploymentArchives().entrySet()) { BeanDeploymentArchive bda = entry.getKey(); if (bda.getId().equals(FLAT_BEAN_DEPLOYMENT_ID) || bda.getId().contains(WEB_INF_CLASSES_FILE_PATH) || bda.getId().contains(WEB_INF_CLASSES)) { return entry.getValue().getCurrent(); } } throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } else { throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } }
if (!deployment.getServices().contains(ExecutorServices.class)) { addWeldService(ExecutorServices.class, executorServicesSupplier.get()); WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(deployment.getModule().getClassLoader()); bootstrap.startContainer(deploymentName, environment, deployment); WeldProvider.containerInitialized(Container.instance(deploymentName), getBeanManager(), deployment); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);