From f041232ebeb4bf79506d79313cde2fb07d747e2e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 28 Nov 2012 17:39:21 +0200 Subject: Fixed problems with invalidating the HttpSession during a request (#10411) Change-Id: I121d6999eababb7eaa53ba16fb8ed029cc154a12 --- .../tests/applicationcontext/CloseSession.html | 69 +++++++++++++++++++++- .../tests/applicationcontext/CloseSession.java | 59 +++++++++++++++++- 2 files changed, 124 insertions(+), 4 deletions(-) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.html b/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.html index 99cfededb1..eb6e7681e6 100644 --- a/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.html +++ b/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.html @@ -40,7 +40,7 @@ clickAndWait - vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VButton[0]/domChild[0]/domChild[0] + vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[5]/VButton[0]/domChild[0]/domChild[0] @@ -53,7 +53,7 @@ vaadin=runcomvaadintestsapplicationcontextCloseSession::PID_SLog_row_0 exact:6. Same WrappedSession id? false - + clickAndWait vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0] @@ -64,7 +64,7 @@ //h1 This is a static file - + open /run/com.vaadin.tests.applicationcontext.CloseSession?restartApplication @@ -85,6 +85,69 @@ vaadin=runcomvaadintestsapplicationcontextCloseSession::Root/VNotification[0]/HTML[0]/domChild[0] Session Expired + + + open + /run/com.vaadin.tests.applicationcontext.CloseSession?restartApplication + + + + click + vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VButton[0]/domChild[0]/domChild[0] + + + + click + vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VButton[0]/domChild[0]/domChild[0] + + + + assertText + vaadin=runcomvaadintestsapplicationcontextCloseSession::Root/VNotification[0]/HTML[0]/domChild[0] + Session Expired + + + + open + /run/com.vaadin.tests.applicationcontext.CloseSession?restartApplication + + + + click + vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[7]/VButton[0]/domChild[0]/domChild[0] + + + + pause + 2000 + 2000 + + + click + vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[7]/VButton[0]/domChild[0]/domChild[0] + + + + assertText + vaadin=runcomvaadintestsapplicationcontextCloseSession::Root/VNotification[0]/HTML[0]/domChild[0] + Session Expired + + + + open + /run/com.vaadin.tests.applicationcontext.CloseSession?restartApplication + + + + clickAndWait + vaadin=runcomvaadintestsapplicationcontextCloseSession::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0] + + + + assertText + //h1 + This is a static file + diff --git a/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.java b/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.java index 41cbd42e94..446638f8a2 100644 --- a/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.java +++ b/uitest/src/com/vaadin/tests/applicationcontext/CloseSession.java @@ -16,8 +16,11 @@ package com.vaadin.tests.applicationcontext; +import javax.servlet.http.HttpSession; + import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinService; +import com.vaadin.server.WrappedHttpSession; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; @@ -31,6 +34,8 @@ public class CloseSession extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { + System.out.println("UI " + getUIId() + " inited"); + final int sessionHash = getSession().hashCode(); final String sessionId = request.getWrappedSession().getId(); @@ -75,20 +80,67 @@ public class CloseSession extends AbstractTestUI { getSession().close(); } })); - addComponent(new Button("Just close session", + addComponent(new Button("Just close VaadinSession", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { getSession().close(); } })); + addComponent(new Button("Just close HttpSession", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + getSession().getSession().invalidate(); + } + })); addComponent(new Button("Invalidate HttpSession and reopen page", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { + VaadinService.getCurrentRequest().getWrappedSession() + .invalidate(); getPage().setLocation(reopenUrl); + } + })); + addComponent(new Button( + "Invalidate HttpSession and redirect elsewhere", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { VaadinService.getCurrentRequest().getWrappedSession() .invalidate(); + getPage().setLocation("/statictestfiles/static.html"); + } + })); + addComponent(new Button( + "Invalidate HttpSession in a background thread", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + final HttpSession session = ((WrappedHttpSession) VaadinService + .getCurrentRequest().getWrappedSession()) + .getHttpSession(); + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out + .println("Invalidating session from thread " + + session.getId()); + session.invalidate(); + System.out + .println("Invalidated session from thread " + + session.getId()); + + } + }); + t.start(); } })); } @@ -103,4 +155,9 @@ public class CloseSession extends AbstractTestUI { return Integer.valueOf(9859); } + @Override + public void detach() { + super.detach(); + System.out.println("UI " + getUIId() + " detached"); + } } -- cgit v1.2.3