Skip to content

Commit

Permalink
WELD-587
Browse files Browse the repository at this point in the history
* Test
* Ensure all conversations are made transient when
  session is invalidated
  • Loading branch information
pmuir committed Nov 13, 2010
1 parent ddd6f1b commit 9d7834f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
Expand Up @@ -62,7 +62,7 @@ protected void removeAttribute(String key)
}
else
{
log.trace("Unable to remove " + key + " from session " + this.getSession(false).getId() + " as no session could be obtained");
log.trace("Unable to remove " + key + " from non-existent session");
}
}

Expand Down
Expand Up @@ -8,6 +8,7 @@

import org.jboss.weld.Container;
import org.jboss.weld.context.AbstractBoundContext;
import org.jboss.weld.context.ManagedConversation;
import org.jboss.weld.context.beanstore.NamingScheme;
import org.jboss.weld.context.beanstore.SimpleNamingScheme;
import org.jboss.weld.context.beanstore.http.EagerSessionBeanStore;
Expand Down Expand Up @@ -91,7 +92,14 @@ public boolean destroy(HttpSession session)
invalidate();
if (conversationContext.isActive())
{
getConversationContext().invalidate();
// Make sure *every* conversation is transient so we don't propagate it
for (ManagedConversation conversation : conversationContext.getConversations())
{
if (!conversation.isTransient())
{
conversation.end();
}
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions impl/src/main/java/org/jboss/weld/jsf/WeldPhaseListener.java
Expand Up @@ -28,7 +28,7 @@
import static org.jboss.weld.logging.Category.JSF;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.ConversationMessage.CLEANING_UP_TRANSIENT_CONVERSATION;
import static org.jboss.weld.logging.messages.ConversationMessage.CONVERSATION_ID_ALREADY_IN_USE;
import static org.jboss.weld.logging.messages.ConversationMessage.NO_CONVERSATION_TO_RESTORE;
import static org.jboss.weld.logging.messages.JsfMessage.CLEANING_UP_CONVERSATION;
import static org.jboss.weld.logging.messages.JsfMessage.FOUND_CONVERSATION_FROM_REQUEST;
import static org.jboss.weld.logging.messages.JsfMessage.RESUMING_CONVERSATION;
Expand Down Expand Up @@ -105,7 +105,7 @@ private void activateConversations(FacesContext facesContext)
if (cid != null && conversationContext.getConversation(cid) == null)
{
// Make sure that the conversation already exists
throw new NonexistentConversationException(CONVERSATION_ID_ALREADY_IN_USE, cid);
throw new NonexistentConversationException(NO_CONVERSATION_TO_RESTORE, cid);
}
conversationContext.activate(cid);
}
Expand Down
Expand Up @@ -139,6 +139,23 @@ public void testInvalidateCallsPreDestroy() throws Exception
assertEquals("true", cloudDestroyed);
}

@Test
public void testInvalidateThenRedirect() throws Exception
{
WebClient client = new WebClient();

// Now start a conversation
HtmlPage cloud = client.getPage(getPath("/cloud.jsf"));
cloud = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "hurricane").click();

// Now invalidate the session and redirect
cloud = getFirstMatchingElement(cloud, HtmlSubmitInput.class, "sleet").click();

// Check that we are still working by verifying the page rendered
String cloudName = getFirstMatchingElement(cloud, HtmlSpan.class, "cloudName").getTextContent();
assertEquals(Cloud.NAME, cloudName);
}

@Test
public void testExceptionInPostConstruct() throws Exception
{
Expand Down
Expand Up @@ -97,4 +97,10 @@ public String invalidateSession()
return "sessionInvalidated";
}

public String sleet()
{
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
return "sleet";
}

}
Expand Up @@ -28,6 +28,9 @@
<h:form>
<h:commandButton action="#{cloud.invalidateSession}" value="Invalidate Session" id="invalidateSession" />
</h:form>
<h:form>
<h:commandButton action="#{cloud.sleet}" value="Sleet" id="sleet" />
</h:form>
</f:view>
</body>
</html>
Expand Down
Expand Up @@ -32,6 +32,24 @@
<redirect/>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/cloud.jspx</from-view-id>
<navigation-case>
<from-action>#{cloud.hurricane}</from-action>
<to-view-id>/cloud.jspx</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/cloud.jspx</from-view-id>
<navigation-case>
<from-action>#{cloud.sleet}</from-action>
<to-view-id>/cloud.jspx</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/hailstorm.jspx</from-view-id>
Expand Down

0 comments on commit 9d7834f

Please sign in to comment.