/** * * @param initializationCallback This callback will be executed during initialization */ public void activate(Consumer<HttpServletRequest> initializationCallback) { activate(); if (initializationCallback != null) { this.initializationCallback.set(initializationCallback); } else { // For the case the deactivation was not performed properly this.initializationCallback.set(null); } }
@Override public boolean destroy(HttpSession session) { if (isAssociated()) { checkContextInitialized(); } return super.destroy(session); }
@Override protected void checkContextInitialized() { if (!isInitialized()) { HttpServletRequest request = getRequest(); String cid = ConversationContextActivator.determineConversationId(request, getParameterName()); initialize(cid); if (cid == null) { // transient conversation Consumer<HttpServletRequest> callback = initializationCallback.get(); if (callback != null) { callback.accept(request); } } } } }
@Override public void deactivate() { try { if (isInitialized()) { try { super.deactivate(); } finally { this.initialized.set(null); } } else { // Only deactivate the context, i.e. remove state threadlocal removeState(); } } finally { this.initializationCallback.set(null); } }
@Override public void activate() { if (!isAssociated()) { throw ConversationLogger.LOG.mustCallAssociateBeforeActivate(); } if (!isActive()) { super.setActive(true); } else { ConversationLogger.LOG.contextAlreadyActive(getRequest()); } // Reset the initialized flag - a thread which is not cleaned up properly (e.g. async processing on // Tomcat) may break the lazy initialization otherwise this.initialized.set(null); }
if (!lazyConversationContext.isInitialized()) { lazyConversationContext.deactivate(); processDestructionQueue(request); return;
contexts.add(new ContextHolder<HttpSessionContext>(new HttpSessionContextImpl(contextId, beanIdentifierIndex), HttpSessionContext.class, httpQualifiers)); contexts.add(new ContextHolder<HttpSessionDestructionContext>(new HttpSessionDestructionContext(contextId, beanIdentifierIndex), HttpSessionDestructionContext.class, httpQualifiers)); contexts.add(new ContextHolder<HttpConversationContext>(new LazyHttpConversationContextImpl(contextId, services), HttpConversationContext.class, httpQualifiers)); contexts.add(new ContextHolder<HttpRequestContext>(new HttpRequestContextImpl(contextId), HttpRequestContext.class, httpQualifiers));
private void activate(HttpConversationContext conversationContext, final HttpServletRequest request) { if (lazy && conversationContext instanceof LazyHttpConversationContextImpl) { LazyHttpConversationContextImpl lazyConversationContext = (LazyHttpConversationContextImpl) conversationContext; // Activation API should be improved so that it's possible to pass a callback for later execution lazyConversationContext.activate(lazyInitializationCallback); } else { String cid = determineConversationId(request, conversationContext.getParameterName()); conversationContext.activate(cid); if (cid == null) { // transient conversation conversationInitializedEvent.fire(request); } } }