public boolean destroy(HttpSession session) { final BoundBeanStore beanStore = getBeanStore(); if (beanStore == null) { try { HttpConversationContext conversationContext = getConversationContext(); setBeanStore(new EagerSessionBeanStore(namingScheme, session, getServiceRegistry())); activate(); invalidate(); conversationContext.destroy(session); deactivate(); setBeanStore(null); return true; } finally { cleanup(); } } else { // We are in a request, invalidate it invalidate(); if (beanStore instanceof AttributeBeanStore) { AttributeBeanStore attributeBeanStore = ((AttributeBeanStore) beanStore); if (attributeBeanStore.isAttributeLazyFetchingEnabled()) { // At this moment we have to sync the local bean store and the backing store attributeBeanStore.fetchUninitializedAttributes(); } } getConversationContext().destroy(session); return false; } }
public boolean associate(HttpServletRequest request) { // At this point the bean store should never be set - see also HttpContextLifecycle.nestedInvocationGuard if (getBeanStore() != null) { ContextLogger.LOG.beanStoreLeakDuringAssociation(this.getClass().getName(), request); } // We always associate a new bean store to avoid possible leaks (security threats) setBeanStore(new LazySessionBeanStore(request, namingScheme, getServiceRegistry().getRequired(WeldConfiguration.class).getBooleanProperty( ConfigurationKey.CONTEXT_ATTRIBUTES_LAZY_FETCH), getServiceRegistry())); checkBeanIdentifierIndexConsistency(request); return true; }
@Override public void postContextRegistration(PostContextRegistrationContext ctx) { final BeanIdentifierIndex index = ctx.getServices().get(BeanIdentifierIndex.class); final String contextId = ctx.getContextId(); if (Reflections.isClassLoadable(ServletApiAbstraction.SERVLET_CONTEXT_CLASS_NAME, WeldClassLoaderResourceLoader.INSTANCE)) { // Register the Http contexts if not in Set<Annotation> httpQualifiers = ImmutableSet.<Annotation> builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(HttpLiteral.INSTANCE).build(); ctx.addContext(new ContextHolder<HttpSessionContext>(new HttpSessionContextImpl(contextId, index), HttpSessionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpSessionDestructionContext>(new HttpSessionDestructionContext(contextId, index), HttpSessionDestructionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpConversationContext>(new LazyHttpConversationContextImpl(contextId, ctx.getServices()), HttpConversationContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpRequestContext>(new HttpRequestContextImpl(contextId), HttpRequestContext.class, httpQualifiers)); } }
private void checkBeanIdentifierIndexConsistency(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { BeanIdentifierIndex index = getServiceRegistry().get(BeanIdentifierIndex.class); if (index != null && index.isBuilt()) { Object hash = session.getAttribute(KEY_BEAN_ID_INDEX_HASH); if (hash != null) { if (!index.getIndexHash().equals(hash)) { throw ContextLogger.LOG.beanIdentifierIndexInconsistencyDetected(hash.toString(), index.getDebugInfo()); } } else { session.setAttribute(KEY_BEAN_ID_INDEX_HASH, index.getIndexHash()); } } } }
@Override public void postContextRegistration(PostContextRegistrationContext ctx) { final BeanIdentifierIndex index = ctx.getServices().get(BeanIdentifierIndex.class); final String contextId = ctx.getContextId(); if (Reflections.isClassLoadable(ServletApiAbstraction.SERVLET_CONTEXT_CLASS_NAME, WeldClassLoaderResourceLoader.INSTANCE)) { // Register the Http contexts if not in Set<Annotation> httpQualifiers = ImmutableSet.<Annotation> builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(HttpLiteral.INSTANCE).build(); ctx.addContext(new ContextHolder<HttpSessionContext>(new HttpSessionContextImpl(contextId, index), HttpSessionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpSessionDestructionContext>(new HttpSessionDestructionContext(contextId, index), HttpSessionDestructionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpConversationContext>(new LazyHttpConversationContextImpl(contextId, ctx.getServices()), HttpConversationContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpRequestContext>(new HttpRequestContextImpl(contextId), HttpRequestContext.class, httpQualifiers)); } }
private void checkBeanIdentifierIndexConsistency(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { BeanIdentifierIndex index = getServiceRegistry().get(BeanIdentifierIndex.class); if (index != null && index.isBuilt()) { Object hash = session.getAttribute(KEY_BEAN_ID_INDEX_HASH); if (hash != null) { if (!index.getIndexHash().equals(hash)) { throw ContextLogger.LOG.beanIdentifierIndexInconsistencyDetected(hash.toString(), index.getDebugInfo()); } } else { session.setAttribute(KEY_BEAN_ID_INDEX_HASH, index.getIndexHash()); } } } }
public boolean destroy(HttpSession session) { final BoundBeanStore beanStore = getBeanStore(); if (beanStore == null) { try { HttpConversationContext conversationContext = getConversationContext(); setBeanStore(new EagerSessionBeanStore(namingScheme, session, getServiceRegistry())); activate(); invalidate(); conversationContext.destroy(session); deactivate(); setBeanStore(null); return true; } finally { cleanup(); } } else { // We are in a request, invalidate it invalidate(); if (beanStore instanceof AttributeBeanStore) { AttributeBeanStore attributeBeanStore = ((AttributeBeanStore) beanStore); if (attributeBeanStore.isAttributeLazyFetchingEnabled()) { // At this moment we have to sync the local bean store and the backing store attributeBeanStore.fetchUninitializedAttributes(); } } getConversationContext().destroy(session); return false; } }
public boolean associate(HttpServletRequest request) { // At this point the bean store should never be set - see also HttpContextLifecycle.nestedInvocationGuard if (getBeanStore() != null) { ContextLogger.LOG.beanStoreLeakDuringAssociation(this.getClass().getName(), request); } // We always associate a new bean store to avoid possible leaks (security threats) setBeanStore(new LazySessionBeanStore(request, namingScheme, getServiceRegistry().getRequired(WeldConfiguration.class).getBooleanProperty( ConfigurationKey.CONTEXT_ATTRIBUTES_LAZY_FETCH), getServiceRegistry())); checkBeanIdentifierIndexConsistency(request); return true; }
@Override public void postContextRegistration(PostContextRegistrationContext ctx) { final BeanIdentifierIndex index = ctx.getServices().get(BeanIdentifierIndex.class); final String contextId = ctx.getContextId(); if (Reflections.isClassLoadable(ServletApiAbstraction.SERVLET_CONTEXT_CLASS_NAME, WeldClassLoaderResourceLoader.INSTANCE)) { // Register the Http contexts if not in Set<Annotation> httpQualifiers = ImmutableSet.<Annotation> builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(HttpLiteral.INSTANCE).build(); ctx.addContext(new ContextHolder<HttpSessionContext>(new HttpSessionContextImpl(contextId, index), HttpSessionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpSessionDestructionContext>(new HttpSessionDestructionContext(contextId, index), HttpSessionDestructionContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpConversationContext>(new LazyHttpConversationContextImpl(contextId, ctx.getServices()), HttpConversationContext.class, httpQualifiers)); ctx.addContext(new ContextHolder<HttpRequestContext>(new HttpRequestContextImpl(contextId), HttpRequestContext.class, httpQualifiers)); } }
private void checkBeanIdentifierIndexConsistency(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { BeanIdentifierIndex index = getServiceRegistry().get(BeanIdentifierIndex.class); if (index != null && index.isBuilt()) { Object hash = session.getAttribute(KEY_BEAN_ID_INDEX_HASH); if (hash != null) { if (!index.getIndexHash().equals(hash)) { throw ContextLogger.LOG.beanIdentifierIndexInconsistencyDetected(hash.toString(), index.getDebugInfo()); } } else { session.setAttribute(KEY_BEAN_ID_INDEX_HASH, index.getIndexHash()); } } } }
public boolean destroy(HttpSession session) { final BoundBeanStore beanStore = getBeanStore(); if (beanStore == null) { try { HttpConversationContext conversationContext = getConversationContext(); setBeanStore(new EagerSessionBeanStore(namingScheme, session, getServiceRegistry())); activate(); invalidate(); conversationContext.destroy(session); deactivate(); setBeanStore(null); return true; } finally { cleanup(); } } else { // We are in a request, invalidate it invalidate(); if (beanStore instanceof AttributeBeanStore) { AttributeBeanStore attributeBeanStore = ((AttributeBeanStore) beanStore); if (attributeBeanStore.isAttributeLazyFetchingEnabled()) { // At this moment we have to sync the local bean store and the backing store attributeBeanStore.fetchUninitializedAttributes(); } } getConversationContext().destroy(session); return false; } }
public boolean associate(HttpServletRequest request) { // At this point the bean store should never be set - see also HttpContextLifecycle.nestedInvocationGuard if (getBeanStore() != null) { ContextLogger.LOG.beanStoreLeakDuringAssociation(this.getClass().getName(), request); } // We always associate a new bean store to avoid possible leaks (security threats) setBeanStore(new LazySessionBeanStore(request, namingScheme, getServiceRegistry().getRequired(WeldConfiguration.class).getBooleanProperty( ConfigurationKey.CONTEXT_ATTRIBUTES_LAZY_FETCH), getServiceRegistry())); checkBeanIdentifierIndexConsistency(request); return true; }