in webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java [393:470]
protected void destroyRequestContext(Object endObject)
{
//Get context
ServletRequestContext context = getRequestContext(false);
if (context == null)
{
return;
}
// cleanup open conversations first
if (supportsConversation)
{
destroyOutdatedConversations(conversationContexts.get());
}
if (context.getPropagatedSessionContext() != null)
{
SessionContext sessionContext = context.getPropagatedSessionContext();
Object payload = null;
if (context.getServletRequest() != null)
{
payload = context.getHttpSession();
if (payload == null)
{
// in tomcat it will be null if invalidate was called
payload = context.getServletRequest().getSession(false);
}
}
webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
payload != null ? payload : new Object(), BeforeDestroyedLiteral.INSTANCE_SESSION_SCOPED);
sessionContext.destroy();
webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
}
Object payload = null;
if (shouldFireRequestLifecycleEvents())
{
if (endObject != null && endObject instanceof ServletRequestEvent)
{
payload = ((ServletRequestEvent) endObject).getServletRequest();
}
webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
payload != null ? payload : new Object(), BeforeDestroyedLiteral.INSTANCE_REQUEST_SCOPED);
}
context.destroy();
// clean up the EL caches after each request
ELContextStore elStore = ELContextStore.getInstance(false);
if (elStore != null)
{
elStore.destroyELContextStore();
}
if (shouldFireRequestLifecycleEvents())
{
webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
payload != null ? payload : new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
}
// clean the proxy cache ThreadLocals
RequestScopedBeanInterceptorHandler.removeThreadLocals();
SessionScopedBeanInterceptorHandler.removeThreadLocals();
//Clear thread locals
requestContexts.set(null);
requestContexts.remove();
}