/** * @see Beans#isActive(Class) */ public static <S extends Annotation> boolean isActive(BeanManager beanManager, Class<S> scope) { try { return beanManager.getContext(scope).isActive(); } catch (Exception ignore) { logger.log(FINEST, "Ignoring thrown exception; given scope is very unlikely active anyway.", ignore); return false; } }
/** * @see Beans#isActive(Class) */ public static <S extends Annotation> boolean isActive(BeanManager beanManager, Class<S> scope) { try { return beanManager.getContext(scope).isActive(); } catch (Exception ignore) { logger.log(FINEST, "Ignoring thrown exception; given scope is very unlikely active anyway.", ignore); return false; } }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!jsr299Manager.getContext(ApplicationScoped.class).isActive()) { throw new ServletException("Application context is not active"); } else { chain.doFilter(request, response); } }
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (!jsr299Manager.getContext(SessionScoped.class).isActive()) { throw new ServletException("Session is not active"); } else { super.service(req, resp); } }
@PostConstruct public void construct() { try { dependentContextActiveDuringPostConstruct = beanManager.getContext(Dependent.class).isActive(); } catch (ContextNotActiveException e) { dependentContextActiveDuringPostConstruct = false; } }
public void testConversationContextIsActive() { try { result = beanManager.getContext(ConversationScoped.class).isActive(); } catch (ContextNotActiveException expected) { result = false; } }
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (!jsr299Manager.getContext(ApplicationScoped.class).isActive()) { throw new ServletException("Application context is not active"); } else { super.service(req, resp); } }
/** * Returns true if given scope is active in current context. */ public static <S extends Annotation> boolean isScopeActive(Class<S> scope) { BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance()); try { Context context = beanManager.getContext(scope); return context.isActive(); } catch (ContextNotActiveException ignore) { return false; } }
/** * Returns true if given scope is active in current context. */ public static <S extends Annotation> boolean isScopeActive(Class<S> scope) { BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance()); try { Context context = beanManager.getContext(scope); return context.isActive(); } catch (ContextNotActiveException ignore) { return false; } }
@Test @SpecAssertion(section = AFTER_BEAN_DISCOVERY, id = "f") public void testAddContext() { Context context = getCurrentManager().getContext(SuperScoped.class); assertNotNull(context); assertTrue(context.isActive()); assertTrue(context instanceof SuperContext); }
@PostConstruct public void init() { if (beanManager != null && beanManager.getContext(ApplicationScoped.class).isActive() && service != null && service.ping()) { isApplicationContextActiveDuringPostConstruct = true; } }
@PostConstruct public void init() { if (beanManager != null && beanManager.getContext(ApplicationScoped.class).isActive() && service != null && service.ping()) { isApplicationContextActiveDuringPostConstruct = true; } }
private void checkRequestContextActive() throws ServletException { if (beanManager == null || !beanManager.getContext(RequestScoped.class).isActive() || simpleBean == null) { throw new ServletException("Request context is not active"); } // Check bean invocation simpleBean.getId(); }
public void contextInitialized(ServletContextEvent sce) { boolean result = manager.getContext(ApplicationScoped.class).isActive(); this.result.setApplicationScopeActiveForServletContextListener(result); }
public void sessionCreated(HttpSessionEvent hsc) { boolean result = manager.getContext(ApplicationScoped.class).isActive(); this.result.setApplicationScopeActiveForHttpSessionListener(result); }
public void requestInitialized(ServletRequestEvent sre) { boolean result = manager.getContext(ApplicationScoped.class).isActive(); this.result.setApplicationScopeActiveForServletRequestListener(result); }
public static void ensureRequestScope(final ContextsService cs, final ServletRequestListener listener) { final Context reqCtx = cs.getCurrentContext(RequestScoped.class); if (reqCtx == null || !cs.getCurrentContext(RequestScoped.class).isActive()) { listener.requestInitialized(null); FAKE_REQUEST.set(true); } }
@Test(groups = { "contexts" }, expectedExceptions = { ContextNotActiveException.class }) @SpecAssertion(section = "6.2", id = "m") public void testInvokingGetOnInactiveContextFails() { Context sessionContext = getCurrentManager().getContext(SessionScoped.class); assert sessionContext.isActive(); setContextInactive(sessionContext); Contextual<MySessionBean> mySessionBean = getBeans(MySessionBean.class).iterator().next(); sessionContext.get(mySessionBean); }
private boolean ensureRequestScope() { Context context = this.lifeCycle.getContextService().getCurrentContext(RequestScoped.class); if (context == null || !context.isActive()) { requestInitialized(null); return true; } return false; }
@Test(groups = { "contexts" }) @SpecAssertions({ @SpecAssertion(section = "6.2", id = "ha"), @SpecAssertion(section = "6.4", id = "g") }) public void testContextIsActive() { assert getCurrentManager().getContext(Dependent.class).isActive(); }