Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WELD-2626 honour resetHttpSessionAttributeOnBeanAccess in AbstractConversationC… #1983

Merged
merged 1 commit into from
May 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public abstract class AbstractConversationContext<R, S> extends AbstractBoundCon
private final AtomicLong defaultTimeout;
private final AtomicLong concurrentAccessTimeout;

private final boolean resetHttpSessionAttributeOnBeanAccess;

private final ThreadLocal<R> associated;

private final BeanManagerImpl manager;
Expand All @@ -100,6 +102,7 @@ public AbstractConversationContext(String contextId, ServiceRegistry services) {
this.associated = new ThreadLocal<R>();
this.manager = Container.instance(contextId).deploymentManager();
this.beanIdentifierIndex = services.get(BeanIdentifierIndex.class);
this.resetHttpSessionAttributeOnBeanAccess = configuration.getBooleanProperty(ConfigurationKey.RESET_HTTP_SESSION_ATTR_ON_BEAN_ACCESS);
}

@Override
Expand Down Expand Up @@ -159,16 +162,16 @@ public boolean dissociate(R request) {

protected void copyConversationIdGeneratorAndConversationsToSession() {
final R request = getRequest();
if(request == null) {
if (request == null) {
return;
}
// If necessary, store the conversation id generator and conversation map in the session
Object conversationIdGenerator = getRequestAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME);
if(conversationIdGenerator != null && getSessionAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, false) == null) {
if (conversationIdGenerator != null && getSessionAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, false) == null) {
setSessionAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, conversationIdGenerator, false);
}
Object conversationMap = getRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME);
if(conversationMap != null && getSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, false) == null) {
if (conversationMap != null && (resetHttpSessionAttributeOnBeanAccess || getSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, false) == null)) {
setSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap, false);
}
}
Expand Down Expand Up @@ -224,7 +227,7 @@ protected void initialize(String cid) {
boolean lock = lock(conversation);
if (lock) {
// WELD-1690 Don't associate a conversation which was ended (race condition)
if(conversation.isTransient()) {
if (conversation.isTransient()) {
associateRequestWithNewConversation();
throw ConversationLogger.LOG.noConversationFoundToRestore(cid);
}
Expand Down Expand Up @@ -428,7 +431,7 @@ protected ConversationIdGenerator getConversationIdGenerator() {
Object conversationIdGenerator = getRequestAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME);
if (conversationIdGenerator == null) {
conversationIdGenerator = getSessionAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, false);
if(conversationIdGenerator == null) {
if (conversationIdGenerator == null) {
conversationIdGenerator = new ConversationIdGenerator();
setRequestAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, conversationIdGenerator);
setSessionAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, conversationIdGenerator, false);
Expand Down Expand Up @@ -471,12 +474,15 @@ private Map<String, ManagedConversation> getConversationMap() {
checkContextInitialized();
final R request = getRequest();
Object conversationMap = getRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME);
if(conversationMap == null) {
if (conversationMap == null) {
conversationMap = getSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, false);
if (conversationMap == null) {
conversationMap = Collections.synchronizedMap(new HashMap<String, ManagedConversation>());
setRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap);
setSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap, false);
} else if (resetHttpSessionAttributeOnBeanAccess) {
setRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap);
setSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap, false);
} else {
setRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap);
}
Expand Down