javax.enterprise.context.ConversationScoped Java Examples
The following examples show how to use
javax.enterprise.context.ConversationScoped.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CDIContextTest.java From microprofile-context-propagation with Apache License 2.0 | 6 votes |
/** * Set some state on Conversation scoped bean and verify * the state is cleared on the thread where the other task runs. * * If the CDI context in question is not active, the test is deemed successful as there is no propagation to be done. * * @throws Exception indicates test failure */ @Test public void testCDIMECtxClearsConversationScopedBeans() throws Exception { // check if given context is active, if it isn't test ends successfully try { bm.getContext(ConversationScoped.class); } catch (ContextNotActiveException e) { return; } ManagedExecutor propagatedNone = ManagedExecutor.builder() .propagated() // none .cleared(ThreadContext.ALL_REMAINING) .build(); Instance<ConversationScopedBean> selectedInstance = instance.select(ConversationScopedBean.class); assertTrue(selectedInstance.isResolvable()); try { checkCDIPropagation(false, "testCDI_ME_Ctx_Clear-CONVERSATION", propagatedNone, selectedInstance.get()); } finally { propagatedNone.shutdown(); } }
Example #2
Source File: WeldContextControl.java From deltaspike with Apache License 2.0 | 6 votes |
@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(); } }
Example #3
Source File: WeldContextControl.java From deltaspike with Apache License 2.0 | 6 votes |
@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); } }
Example #4
Source File: OpenWebBeansContextControl.java From deltaspike with Apache License 2.0 | 6 votes |
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(); } }
Example #5
Source File: OpenWebBeansContextControl.java From deltaspike with Apache License 2.0 | 6 votes |
@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(); } }
Example #6
Source File: ContextControlDecorator.java From deltaspike with Apache License 2.0 | 6 votes |
@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(); }
Example #7
Source File: ContextControlDecorator.java From deltaspike with Apache License 2.0 | 6 votes |
@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); } } }
Example #8
Source File: StatefulConversationScopedTOMEE1138Test.java From tomee with Apache License 2.0 | 6 votes |
@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); }
Example #9
Source File: BeanContext.java From tomee with Apache License 2.0 | 6 votes |
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; }
Example #10
Source File: HasConversationScopeTest.java From microprofile-rest-client with Apache License 2.0 | 6 votes |
@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(); String configKeyScope = "myConfigKey/mp-rest/scope=" + ConversationScoped.class.getName(); String simpleName = HasConversationScopeTest.class.getSimpleName(); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, simpleName + ".jar") .addClasses(SimpleGetApi.class, MyConversationScopedApi.class, ConfigKeyClient.class) .addAsManifestResource(new StringAsset(url + "\n" + scope + "\n" + url2 + "\n" + configKeyScope), "microprofile-config.properties") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); return ShrinkWrap.create(WebArchive.class, simpleName + ".war") .addAsLibrary(jar) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); }
Example #11
Source File: CDIContextTest.java From microprofile-context-propagation with Apache License 2.0 | 6 votes |
/** * Set some state on Conversation scoped beans and verify * the state is propagated to the thread where the other task runs. * * If the CDI context in question is not active, the test is deemed successful as there is no propagation to be done. * * @throws Exception indicates test failure */ @Test public void testCDIMECtxPropagatesConversationScopedBean() throws Exception { // check if given context is active, if it isn't test ends successfully try { bm.getContext(ConversationScoped.class); } catch (ContextNotActiveException e) { return; } ManagedExecutor propagateCDI = ManagedExecutor.builder().propagated(ThreadContext.CDI) .cleared(ThreadContext.ALL_REMAINING) .build(); Instance<ConversationScopedBean> selectedInstance = instance.select(ConversationScopedBean.class); assertTrue(selectedInstance.isResolvable()); try { checkCDIPropagation(true, "testCDI_ME_Ctx_Propagate-CONVERSATION", propagateCDI, selectedInstance.get()); } finally { propagateCDI.shutdown(); } }
Example #12
Source File: EmbeddedTomEEContainer.java From tomee with Apache License 2.0 | 5 votes |
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 } }
Example #13
Source File: EmbeddedTomEEContainer.java From tomee with Apache License 2.0 | 5 votes |
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); } }
Example #14
Source File: ScopeHelper.java From tomee with Apache License 2.0 | 5 votes |
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(); } }
Example #15
Source File: CdiScopeAnnotationsAutoConfiguration.java From joinfaces with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(value = "joinfaces.scope-configurer.cdi.enabled", havingValue = "true", matchIfMissing = true) public static CustomScopeAnnotationConfigurer cdiScopeAnnotationsConfigurer(Environment environment) { CustomScopeAnnotationConfigurer scopeAnnotationConfigurer = new CustomScopeAnnotationConfigurer(); scopeAnnotationConfigurer.setOrder(environment.getProperty("joinfaces.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; }
Example #16
Source File: ScopeHelper.java From tomee with Apache License 2.0 | 4 votes |
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); }
Example #17
Source File: OpenEJBLifecycle.java From tomee with Apache License 2.0 | 4 votes |
@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); } }
Example #18
Source File: EntityManagerProducer.java From HotswapAgentExamples with GNU General Public License v2.0 | 4 votes |
@Produces @ConversationScoped public EntityManager create() { return emf.createEntityManager(); }
Example #19
Source File: StatefulConversationScopedTOMEE1138Test.java From tomee with Apache License 2.0 | 4 votes |
@After public void stopConversation() { WebBeansContext.currentInstance().getService(ContextsService.class).endContext(ConversationScoped.class, null); }
Example #20
Source File: HasConversationScopeTest.java From microprofile-rest-client with Apache License 2.0 | 4 votes |
@Test public void testHasConversationScopedWhenAnnotated() { Set<Bean<?>> beans = beanManager.getBeans(MyConversationScopedApi.class, RestClient.LITERAL); Bean<?> resolved = beanManager.resolve(beans); assertEquals(resolved.getScope(), ConversationScoped.class); }
Example #21
Source File: HasConversationScopeTest.java From microprofile-rest-client with Apache License 2.0 | 4 votes |
@Test public void testHasConversationScopedFromConfigKey() { Set<Bean<?>> beans = beanManager.getBeans(ConfigKeyClient.class, RestClient.LITERAL); Bean<?> resolved = beanManager.resolve(beans); assertEquals(resolved.getScope(), ConversationScoped.class); }
Example #22
Source File: HasConversationScopeTest.java From microprofile-rest-client with Apache License 2.0 | 4 votes |
@Test public void testHasConversationScoped() { Set<Bean<?>> beans = beanManager.getBeans(SimpleGetApi.class, RestClient.LITERAL); Bean<?> resolved = beanManager.resolve(beans); assertEquals(resolved.getScope(), ConversationScoped.class); }
Example #23
Source File: OpenWebBeansContextControl.java From deltaspike with Apache License 2.0 | 4 votes |
private void startConversationScope() { ContextsService contextsService = getContextsService(); contextsService.startContext(ConversationScoped.class, null); }
Example #24
Source File: OpenWebBeansContextControl.java From deltaspike with Apache License 2.0 | 4 votes |
private void stopConversationScope() { ContextsService contextsService = getContextsService(); contextsService.endContext(ConversationScoped.class, null); }