use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class PermissionServiceClientProxy method getServiceState.
private ServiceState getServiceState() {
IClientSession session = ClientSessionProvider.currentSession();
Object key = null;
if (session != null) {
key = session.getClass();
}
synchronized (m_stateLock) {
ServiceState data = (ServiceState) m_stateMap.get(key);
if (data == null) {
data = new ServiceState();
m_stateMap.put(key, data);
}
return data;
}
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class DeviceTransformationService method install.
@Override
public void install(IDesktop desktop) {
IClientSession session = ClientSessionProvider.currentSession();
if (session == null) {
throw new IllegalArgumentException("No current session available");
}
if (desktop == null) {
throw new IllegalArgumentException("Desktop must not be null");
}
if (getDeviceTransformer(session) != null) {
// Already installed for the current session
return;
}
IDeviceTransformer data = createDeviceTransformer();
data.setDesktop(desktop);
session.setData(SESSION_DATA_KEY, data);
session.addListener(new P_SessionListener());
LOG.debug("DeviceTransformationService installed for session {}", session);
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class UiSessionTest method doTestLogoutWithBlockingModelDisposal.
/**
* Tests that session invalidation still works even if the model is blocking during its disposal. Especially the
* {@link HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)} method is expected not
* to be blocked by the {@link SessionStore} (the method is invoked by the servlet container and blocking its thread
* could interfere with the application server itself, for example when a background thread is cleaning up timed out
* sessions).
*/
protected void doTestLogoutWithBlockingModelDisposal(final CloseAction openFormCloseAction, boolean expectFormFinallyCompleted, boolean expectSessionActiveAfterwards) throws InterruptedException {
// create new UI session along with client client and HTTP sessions
UiSession uiSession = (UiSession) JsonTestUtility.createAndInitializeUiSession();
final HttpSession httpSession = UiSessionTestUtility.getHttpSession(uiSession);
IClientSession clientSession = uiSession.getClientSession();
assertFalse(uiSession.isDisposed());
// register ui session in session store
final ISessionStore sessionStore = BEANS.get(HttpSessionHelper.class).getSessionStore(httpSession);
sessionStore.registerUiSession(uiSession);
assertThat(sessionStore, is(instanceOf(HttpSessionBindingListener.class)));
// create and start test form in a model job
SessionStoreTestForm form = ModelJobs.schedule(new Callable<SessionStoreTestForm>() {
@Override
public SessionStoreTestForm call() throws Exception {
SessionStoreTestForm f = new SessionStoreTestForm(openFormCloseAction);
f.start();
return f;
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true))).awaitDoneAndGet(1, TimeUnit.SECONDS);
// schedule a job that emulates servlet container that performs session invalidation on session timeout
IFuture<Void> appServerSessionTimeoutFuture = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
httpSession.invalidate();
}
}, Jobs.newInput().withName("simulate session timeout").withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(200, TimeUnit.MILLISECONDS)));
// perform logout on UI session that stops the client session and disposes all model objects.
uiSession.logout();
assertTrue(uiSession.isDisposed());
if (expectFormFinallyCompleted) {
form.awaitDoFinallyCompleted(1, TimeUnit.SECONDS);
} else {
BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
}
appServerSessionTimeoutFuture.awaitDone(3, TimeUnit.SECONDS);
assertTrue(appServerSessionTimeoutFuture.isDone());
if (expectFormFinallyCompleted) {
assertTrue(form.isFinallyCompleted());
BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
} else {
assertFalse(form.isFinallyCompleted());
// The model job was canceled by the SessionStore. Hence we cannot use UiJobs.awaitModelJobs().
// We still sleep some time
SleepUtil.sleepSafe(200, TimeUnit.MILLISECONDS);
}
assertEquals(expectSessionActiveAfterwards, clientSession.isActive());
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class UiSessionTest method testSessionInvalidation.
@Test
public void testSessionInvalidation() throws Exception {
UiSession uiSession = (UiSession) JsonTestUtility.createAndInitializeUiSession();
HttpSession httpSession = UiSessionTestUtility.getHttpSession(uiSession);
IClientSession clientSession = uiSession.getClientSession();
assertFalse(uiSession.isDisposed());
// Don't waste time waiting for client jobs to finish. Test job itself runs inside a client job so we always have to wait until max time
WeakReference<IUiSession> ref = new WeakReference<IUiSession>(uiSession);
ISessionStore sessionStore = BEANS.get(HttpSessionHelper.class).getSessionStore(httpSession);
sessionStore.registerUiSession(uiSession);
JsonTestUtility.endRequest(uiSession);
httpSession.invalidate();
BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
assertFalse(clientSession.isActive());
assertTrue(uiSession.isDisposed());
uiSession = null;
TestingUtility.assertGC(ref);
}
use of org.eclipse.scout.rt.client.IClientSession in project scout.rt by eclipse.
the class UiSessionTest method doTestSessionTimeoutWithBlockingModelDisposal.
/**
* Checks the same problematic as {@link #doTestLogoutWithBlockingModelDisposal(CloseAction, boolean, boolean)} except
* that there is no {@link UiSession#logout()}, but only a {@link HttpSession#invalidate()}, invoked by the servlet
* container due to session timeout.
*/
protected void doTestSessionTimeoutWithBlockingModelDisposal(final CloseAction openFormCloseAction, boolean expectFormFinallyCompleted, boolean expectSessionActiveAfterwards) throws InterruptedException {
// create new UI session along with client client and HTTP sessions
UiSession uiSession = (UiSession) JsonTestUtility.createAndInitializeUiSession();
final HttpSession httpSession = UiSessionTestUtility.getHttpSession(uiSession);
IClientSession clientSession = uiSession.getClientSession();
assertFalse(uiSession.isDisposed());
// register ui session in session store
final ISessionStore sessionStore = BEANS.get(HttpSessionHelper.class).getSessionStore(httpSession);
sessionStore.registerUiSession(uiSession);
assertThat(sessionStore, is(instanceOf(HttpSessionBindingListener.class)));
// create and start test form in a model job
SessionStoreTestForm form = ModelJobs.schedule(new Callable<SessionStoreTestForm>() {
@Override
public SessionStoreTestForm call() throws Exception {
SessionStoreTestForm f = new SessionStoreTestForm(openFormCloseAction);
f.start();
return f;
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true))).awaitDoneAndGet(1, TimeUnit.SECONDS);
// invalidate HTTP session
httpSession.invalidate();
if (expectFormFinallyCompleted) {
form.awaitDoFinallyCompleted(1, TimeUnit.SECONDS);
assertTrue(form.isFinallyCompleted());
BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
} else {
assertFalse(form.isFinallyCompleted());
// We still sleep some time
for (int i = 0; i < 10; i++) {
SleepUtil.sleepSafe(200, TimeUnit.MILLISECONDS);
if (expectSessionActiveAfterwards == clientSession.isActive()) {
break;
}
}
}
assertTrue(uiSession.isDisposed());
assertEquals(expectSessionActiveAfterwards, clientSession.isActive());
}
Aggregations