Search in sources :

Example 1 with IClientSession

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;
    }
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 2 with IClientSession

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);
}
Also used : IClientSession(org.eclipse.scout.rt.client.IClientSession)

Example 3 with IClientSession

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());
}
Also used : HttpSession(javax.servlet.http.HttpSession) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Callable(java.util.concurrent.Callable) IClientSession(org.eclipse.scout.rt.client.IClientSession) SessionStoreTestForm(org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm)

Example 4 with IClientSession

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);
}
Also used : HttpSession(javax.servlet.http.HttpSession) WeakReference(java.lang.ref.WeakReference) IClientSession(org.eclipse.scout.rt.client.IClientSession) Test(org.junit.Test)

Example 5 with IClientSession

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());
}
Also used : HttpSession(javax.servlet.http.HttpSession) IClientSession(org.eclipse.scout.rt.client.IClientSession) SessionStoreTestForm(org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm) Callable(java.util.concurrent.Callable)

Aggregations

IClientSession (org.eclipse.scout.rt.client.IClientSession)30 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)11 Test (org.junit.Test)11 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)4 Subject (javax.security.auth.Subject)3 HttpSession (javax.servlet.http.HttpSession)3 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)3 IFuture (org.eclipse.scout.rt.platform.job.IFuture)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 ISession (org.eclipse.scout.rt.shared.ISession)3 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)3 WeakReference (java.lang.ref.WeakReference)2 Locale (java.util.Locale)2 Callable (java.util.concurrent.Callable)2 IMessageBox (org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)2 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)2 JobEventData (org.eclipse.scout.rt.platform.job.listener.JobEventData)2 NlsLocale (org.eclipse.scout.rt.platform.nls.NlsLocale)2 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)2 SessionStoreTestForm (org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm)2