/** * Does actually not work */ @Override @Asynchronous public void startAsynchronous(final IWorkflowListener listener) { try { CdiContextAwareRunnable runnable = new CdiContextAwareRunnable(this.newWorkflowRunnable(listener)); // runnable.addContext(RequestScoped.class); runnable.addContext(SessionScoped.class); // runnable.addContext(ApplicationScoped.class); runnable.addContext(ConversationScoped.class); runnable.run(); } catch (WorkflowException e) { LOG.error(e.getMessage(), e); } }
public boolean isPassivatingScope() { final CdiEjbBean<?> bean = get(CdiEjbBean.class); if (bean == null) { return true; } if (ConversationScoped.class == bean.getScope()) { try { return !bean.getWebBeansContext().getConversationManager().getConversationBeanReference().isTransient(); } catch (final RuntimeException re) { // conversation not found for instance so act as @RequestScoped return false; } } return true; }
@Before public void startConversation() { final WebBeansContext webBeansContext = WebBeansContext.currentInstance(); webBeansContext.registerService(ConversationService.class, new ConversationService() { @Override public String getConversationId() { return "conversation-test"; } @Override public String generateConversationId() { return "cid_1"; } }); webBeansContext.getService(ContextsService.class).startContext(ConversationScoped.class, null); }
@Override public void startContexts() { wrapped.startContexts(); if (isManualScopeHandling()) { for (ExternalContainer externalContainer : CdiTestRunner.getActiveExternalContainers()) { externalContainer.startScope(Singleton.class); externalContainer.startScope(ApplicationScoped.class); externalContainer.startScope(RequestScoped.class); externalContainer.startScope(SessionScoped.class); externalContainer.startScope(ConversationScoped.class); } } }
@Override public void stopContexts() { if (isManualScopeHandling()) { for (ExternalContainer externalContainer : CdiTestRunner.getActiveExternalContainers()) { externalContainer.stopScope(ConversationScoped.class); externalContainer.stopScope(SessionScoped.class); externalContainer.stopScope(RequestScoped.class); externalContainer.stopScope(ApplicationScoped.class); externalContainer.stopScope(Singleton.class); } } wrapped.stopContexts(); }
@Override public void startContext(Class<? extends Annotation> scopeClass) { if (scopeClass.isAssignableFrom(ApplicationScoped.class)) { startApplicationScope(); } else if (scopeClass.isAssignableFrom(SessionScoped.class)) { startSessionScope(); } else if (scopeClass.isAssignableFrom(RequestScoped.class)) { startRequestScope(); } else if (scopeClass.isAssignableFrom(ConversationScoped.class)) { startConversationScope(); } }
public void stopContext(Class<? extends Annotation> scopeClass) { if (scopeClass.isAssignableFrom(ApplicationScoped.class)) { stopApplicationScope(); } else if (scopeClass.isAssignableFrom(SessionScoped.class)) { stopSessionScope(); } else if (scopeClass.isAssignableFrom(RequestScoped.class)) { stopRequestScope(); } else if (scopeClass.isAssignableFrom(ConversationScoped.class)) { stopConversationScope(); } }
@Override public void startContext(Class<? extends Annotation> scopeClass) { if (scopeClass.isAssignableFrom(ApplicationScoped.class)) { startApplicationScope(); } else if (scopeClass.isAssignableFrom(SessionScoped.class)) { startSessionScope(); } else if (scopeClass.isAssignableFrom(RequestScoped.class)) { startRequestScope(); } else if (scopeClass.isAssignableFrom(ConversationScoped.class)) { startConversationScope(null); } }
@Override public void stopContext(Class<? extends Annotation> scopeClass) { if (scopeClass.isAssignableFrom(ApplicationScoped.class)) { stopApplicationScope(); } else if (scopeClass.isAssignableFrom(SessionScoped.class)) { stopSessionScope(); } else if (scopeClass.isAssignableFrom(RequestScoped.class)) { stopRequestScope(); } else if (scopeClass.isAssignableFrom(ConversationScoped.class)) { stopConversationScope(); } }
@Deployment public static WebArchive createDeployment() { String url = SimpleGetApi.class.getName() + "/mp-rest/url=http://localhost:8080"; String url2 = MyConversationScopedApi.class.getName() + "/mp-rest/url=http://localhost:8080"; String scope = SimpleGetApi.class.getName() + "/mp-rest/scope=" + ConversationScoped.class.getName(); JavaArchive jar = ShrinkWrap.create(JavaArchive.class) .addClasses(SimpleGetApi.class, MyConversationScopedApi.class) .addAsManifestResource(new StringAsset(url + "\n" + scope + "\n" + url2), "microprofile-config.properties") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); return ShrinkWrap.create(WebArchive.class) .addAsLibrary(jar) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); }
@Bean @ConditionalOnProperty(value = "jsf.scope-configurer.cdi.enabled", havingValue = "true", matchIfMissing = true) public static BeanFactoryPostProcessor cdiScopeAnnotationsConfigurer(Environment environment) { CustomScopeAnnotationConfigurer scopeAnnotationConfigurer = new CustomScopeAnnotationConfigurer(); scopeAnnotationConfigurer.setOrder(environment.getProperty("jsf.scope-configurer.cdi.order", Integer.class, Ordered.LOWEST_PRECEDENCE)); scopeAnnotationConfigurer.addMapping(RequestScoped.class, WebApplicationContext.SCOPE_REQUEST); scopeAnnotationConfigurer.addMapping(SessionScoped.class, WebApplicationContext.SCOPE_SESSION); scopeAnnotationConfigurer.addMapping(ConversationScoped.class, WebApplicationContext.SCOPE_SESSION); scopeAnnotationConfigurer.addMapping(ApplicationScoped.class, WebApplicationContext.SCOPE_APPLICATION); return scopeAnnotationConfigurer; }
@ExtensionManaged @Produces @ConversationScoped public EntityManager produce() { EntityManager entityManager = entityManagerFactory.createEntityManager(); // .. do somthing with entity manager return entityManager; }
@Produces @ConversationScoped @PersistenceUnit @Default public EntityManagerFactory getEntityManagerFactory() { return emf; }
@Produces @Main @ConversationScoped public EntityManager create() { return this.emfA.createEntityManager(); }
/** * Produces the selected item for the current context * @return */ @Produces @SelectedItem @Named("selectedItem") @ConversationScoped public Item getCurrentItem() { if(item == null) { item = new Item(); } return item; }
/** * Returns the current bid * @return current bid */ @Produces @CurrentBid @Named("currentBid") @ConversationScoped public Bid getCurrentBid() { Bid bid = new Bid(); if(user instanceof BazaarAccount) { bid.setBidder((BazaarAccount)user); } bid.setItem(item); return bid; }
protected void submit(Runnable runnable) { CdiContextAwareRunnable contextRunnable = new CdiContextAwareRunnable(runnable); contextRunnable.addContext(RequestScoped.class); contextRunnable.addContext(SessionScoped.class); contextRunnable.addContext(ConversationScoped.class); this.service.submit(contextRunnable); }
@Test public void cannotBeAManagedBeanBecauseOfWas() { assertNull(getAnnotation(ApplicationScoped.class)); assertNull(getAnnotation(Dependent.class)); assertNull(getAnnotation(SessionScoped.class)); assertNull(getAnnotation(RequestScoped.class)); assertNull(getAnnotation(ConversationScoped.class)); }
private void startCdiContexts(final String name) { final WebBeansContext wbc = this.container.getAppContexts(name).getWebBeansContext(); if (wbc != null && wbc.getBeanManagerImpl().isInUse()) { final MockHttpSession session = new MockHttpSession(); wbc.getContextsService().startContext(RequestScoped.class, null); wbc.getContextsService().startContext(SessionScoped.class, session); wbc.getContextsService().startContext(ConversationScoped.class, null); SESSIONS.put(name, session); } }
private void stopCdiContexts(final String name) { try { final HttpSession session = SESSIONS.remove(name); if (session != null) { final WebBeansContext wbc = container.getAppContexts(container.getInfo(name).appId).getWebBeansContext(); if (wbc != null && wbc.getBeanManagerImpl().isInUse()) { wbc.getContextsService().startContext(RequestScoped.class, null); wbc.getContextsService().startContext(SessionScoped.class, session); wbc.getContextsService().startContext(ConversationScoped.class, null); } } } catch (final Exception e) { // no-op } }
public static void stopContexts(final ContextsService contextsService, final ServletContext servletContext, final HttpSession session) throws Exception { contextsService.endContext(SessionScoped.class, session); contextsService.endContext(RequestScoped.class, null); contextsService.endContext(ConversationScoped.class, null); if (CdiAppContextsService.class.isInstance(contextsService)) { CdiAppContextsService.class.cast(contextsService).removeThreadLocals(); } }
@ConversationScoped public void setTextConversation(String textConversation) { this.textConversation = textConversation; }
@Test public void testHasConversationScoped() { Set<Bean<?>> beans = beanManager.getBeans(SimpleGetApi.class, RestClient.LITERAL); Bean<?> resolved = beanManager.resolve(beans); assertEquals(resolved.getScope(), ConversationScoped.class); }
@Test public void testHasConversationScopedWhenAnnotated() { Set<Bean<?>> beans = beanManager.getBeans(MyConversationScopedApi.class, RestClient.LITERAL); Bean<?> resolved = beanManager.resolve(beans); assertEquals(resolved.getScope(), ConversationScoped.class); }
@Produces @ConversationScoped public EntityManager create() { return emf.createEntityManager(); }
@Produces @DataRepository @ConversationScoped public EntityManager produceEntityManager() { return getEntityManagerFactory().createEntityManager(); }
@Produces @Default @ConversationScoped public EntityManager create() { return entityManagerFactory.createEntityManager(); }
public static void startContexts(final ContextsService contextsService, final ServletContext servletContext, final HttpSession session) throws Exception { contextsService.startContext(SessionScoped.class, session); contextsService.startContext(RequestScoped.class, null); contextsService.startContext(ConversationScoped.class, null); }
@Override public void stopApplication(final Object endObject) { logger.debug("OpenWebBeans Container is stopping."); try { // Fire shut down if (WebappBeanManager.class.isInstance(beanManager)) { WebappBeanManager.class.cast(beanManager).beforeStop(); } webBeansContext.getContextsService().endContext(RequestScoped.class, endObject); webBeansContext.getContextsService().endContext(ConversationScoped.class, endObject); webBeansContext.getContextsService().endContext(SessionScoped.class, endObject); webBeansContext.getContextsService().endContext(ApplicationScoped.class, endObject); webBeansContext.getContextsService().endContext(Singleton.class, endObject); // clean up the EL caches after each request ELContextStore elStore = ELContextStore.getInstance(false); if (elStore != null) { elStore.destroyELContextStore(); } this.beanManager.fireEvent(new BeforeShutdownImpl(), true); // this will now even destroy the ExtensionBeans and other internal stuff this.contextsService.destroy(endObject); //Unbind BeanManager if (jndiService != null) { jndiService.unbind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME); } //Free all plugin resources ((CdiPlugin) webBeansContext.getPluginLoader().getEjbPlugin()).clearProxies(); webBeansContext.getPluginLoader().shutDown(); //Clear extensions webBeansContext.getExtensionLoader().clear(); //Delete Resolutions Cache beanManager.getInjectionResolver().clearCaches(); //Delete AnnotateTypeCache webBeansContext.getAnnotatedElementFactory().clear(); //After Stop //Clear the resource injection service final ResourceInjectionService injectionServices = webBeansContext.getService(ResourceInjectionService.class); if (injectionServices != null) { injectionServices.clear(); } //Comment out for commit OWB-502 //ContextFactory.cleanUpContextFactory(); CdiAppContextsService.class.cast(contextsService).removeThreadLocals(); WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); // Clear BeanManager this.beanManager.clear(); // Clear singleton list WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); } catch (final Exception e) { logger.error("An error occured while stopping the container.", e); } }
@After public void stopConversation() { WebBeansContext.currentInstance().getService(ContextsService.class).endContext(ConversationScoped.class, null); }
private void startConversationScope() { ContextsService contextsService = getContextsService(); contextsService.startContext(ConversationScoped.class, null); }
private void stopConversationScope() { ContextsService contextsService = getContextsService(); contextsService.endContext(ConversationScoped.class, null); }