Search in sources :

Example 11 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class BridgeToServerBeanDecorator method ensureRunInServerContext.

protected Object ensureRunInServerContext(final IBeanInvocationContext<T> context) {
    if (PropertyMap.isSet(PropertyMap.PROP_SERVER_SCOPE)) {
        // already in a server scope
        return continueCall(context);
    }
    // bridge to server scope
    ClientNotificationCollector collector = new ClientNotificationCollector();
    ServerRunContext bridgeRunContext = ServerRunContexts.copyCurrent().withClientNotificationCollector(collector).withClientNodeId(INode.ID);
    ISession currentSession = ISession.CURRENT.get();
    IServerSession bridgeSession = null;
    if (currentSession != null) {
        bridgeSession = BEANS.get(ServerSessionProviderWithCache.class).provide(currentSession.getId(), bridgeRunContext);
    }
    Object result = bridgeRunContext.withSession(bridgeSession).call(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                return continueCall(context);
            } catch (Exception e) {
                ITransaction.CURRENT.get().addFailure(e);
                throw e;
            }
        }
    });
    ClientNotificationDispatcher clientNotificationDispatcher = BEANS.get(ClientNotificationDispatcher.class);
    List<ClientNotificationMessage> values = collector.consume();
    if (!values.isEmpty()) {
        clientNotificationDispatcher.dispatchNotifications(values);
    }
    return result;
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) ServerRunContext(org.eclipse.scout.rt.server.context.ServerRunContext) IServerSession(org.eclipse.scout.rt.server.IServerSession) ClientNotificationCollector(org.eclipse.scout.rt.server.clientnotification.ClientNotificationCollector) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) ClientNotificationDispatcher(org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)

Example 12 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class GeneralView method produceBody.

@Override
public void produceBody(HtmlComponent p) {
    // menu
    String monitoringStatusMessage = createMonitoringQuickLink(p);
    // infos
    String title = CONFIG.getPropertyValue(ApplicationNameProperty.class);
    String version = CONFIG.getPropertyValue(ApplicationVersionProperty.class);
    p.print("Product: name=" + title + ", version=" + version);
    p.br();
    p.br();
    p.print("Date: " + new Date());
    p.br();
    p.print("You connect from: " + p.getRequest().getRemoteAddr() + " / " + p.getRequest().getRemoteHost());
    p.p();
    HttpSession session = p.getRequest().getSession(false);
    if (session != null) {
        p.print("Session ID: " + session.getId());
        p.br();
        p.print("Session Created: " + new Date(session.getCreationTime()));
    } else {
        p.print("There is no HTTP-Session needed ");
    }
    p.br();
    IServerSession serverSession = ServerSessionProvider.currentSession();
    if (serverSession != null) {
        p.print("Session ID (ThreadContext): " + serverSession.getId());
    } else {
        p.print("There is no Session found");
    }
    p.br();
    p.print("JAAS Context");
    p.br();
    p.print("&nbsp;&nbsp;remoteUser: " + p.getRequest().getRemoteUser());
    p.br();
    Principal remotePrincipal = p.getRequest().getUserPrincipal();
    if (remotePrincipal != null) {
        p.print("&nbsp;&nbsp;userPrincipal: " + remotePrincipal.getName() + " [" + remotePrincipal.getClass().getSimpleName() + "]");
    } else {
        p.print("&nbsp;&nbsp;userPrincipal: null");
    }
    p.br();
    try {
        SecurityManager sm = System.getSecurityManager();
        p.print("&nbsp;&nbsp;SecurityManager: " + sm);
        p.br();
        Subject subject = Subject.getSubject(AccessController.getContext());
        p.print("&nbsp;&nbsp;Subject: " + VerboseUtility.dumpObject(subject));
        p.br();
        if (subject != null) {
            int i1 = 0;
            for (Iterator it1 = subject.getPrincipals().iterator(); it1.hasNext(); ) {
                Principal principal = (Principal) it1.next();
                if (principal != null) {
                    p.print("&nbsp;&nbsp;&nbsp;&nbsp;principal[" + i1 + "]=" + principal.getName() + " [" + principal.getClass().getName() + "]");
                    p.br();
                }
                i1++;
            }
        }
    } catch (Exception e) {
        p.print("Exception: " + e);
        p.br();
    }
    p.br();
    if (monitoringStatusMessage != null) {
        p.raw(monitoringStatusMessage);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Iterator(java.util.Iterator) IServerSession(org.eclipse.scout.rt.server.IServerSession) Date(java.util.Date) Principal(java.security.Principal) Subject(javax.security.auth.Subject)

Example 13 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class ServerSessionCacheTest method testParallelRequestsWithSameIds.

@Test
public void testParallelRequestsWithSameIds() {
    final TestHttpSession httpSession1 = new TestHttpSession();
    final TestHttpSession httpSession2 = new TestHttpSession();
    final ServerSessionCache cache = BEANS.get(ServerSessionCache.class);
    final IServerSessionLifecycleHandler sessionSupplier1 = new IServerSessionLifecycleHandler() {

        @Override
        public IServerSession create() {
            return new AbstractServerSession(true) {

                private static final long serialVersionUID = 1L;
            };
        }

        @Override
        public void destroy(IServerSession session) {
        }

        @Override
        public String getId() {
            return "id1";
        }
    };
    final IServerSessionLifecycleHandler sessionSupplier2 = new IServerSessionLifecycleHandler() {

        @Override
        public IServerSession create() {
            return new AbstractServerSession(true) {

                private static final long serialVersionUID = 1L;
            };
        }

        @Override
        public void destroy(IServerSession session) {
        }

        @Override
        public String getId() {
            return "id1";
        }
    };
    IFuture<IServerSession> f1 = Jobs.schedule(new Callable<IServerSession>() {

        @Override
        public IServerSession call() throws Exception {
            return cache.getOrCreate(sessionSupplier1, httpSession1);
        }
    }, Jobs.newInput());
    IFuture<IServerSession> f2 = Jobs.schedule(new Callable<IServerSession>() {

        @Override
        public IServerSession call() throws Exception {
            return cache.getOrCreate(sessionSupplier2, httpSession2);
        }
    }, Jobs.newInput());
    IServerSession session2 = f2.awaitDoneAndGet();
    IServerSession session1 = f1.awaitDoneAndGet();
    assertSame(session1, session2);
}
Also used : AbstractServerSession(org.eclipse.scout.rt.server.AbstractServerSession) IServerSession(org.eclipse.scout.rt.server.IServerSession) TestHttpSession(org.eclipse.scout.rt.testing.server.TestHttpSession) Test(org.junit.Test)

Example 14 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class ServerSessionCacheTest method testGetExisting.

/**
 * Tests the lookup, if a server session already exists on the {@link HttpSession}.
 */
@Test
public void testGetExisting() {
    HttpSession httpSession = mock(HttpSession.class);
    when(httpSession.getAttribute(IServerSession.class.getName())).thenReturn(m_testScoutSession);
    IServerSession session = BEANS.get(ServerSessionCache.class).getOrCreate(new FixedServerSessionLifecycleHandler(), httpSession);
    assertSame(m_testScoutSession, session);
}
Also used : TestHttpSession(org.eclipse.scout.rt.testing.server.TestHttpSession) HttpSession(javax.servlet.http.HttpSession) IServerSession(org.eclipse.scout.rt.server.IServerSession) Test(org.junit.Test)

Example 15 with IServerSession

use of org.eclipse.scout.rt.server.IServerSession in project scout.rt by eclipse.

the class ServerSessionCacheTest method testNewSessionCreated.

/**
 * Tests the lookup: If no server session exists on the {@link HttpSession}, a new scout session should be created.
 */
@Test
public void testNewSessionCreated() {
    HttpSession httpSession = spy(HttpSession.class);
    IServerSession session = BEANS.get(ServerSessionCache.class).getOrCreate(new FixedServerSessionLifecycleHandler(), httpSession);
    assertNotNull(session);
    // new server session should be stored on httpsession
    verify(httpSession).setAttribute(IServerSession.class.getName(), m_testScoutSession);
}
Also used : TestHttpSession(org.eclipse.scout.rt.testing.server.TestHttpSession) HttpSession(javax.servlet.http.HttpSession) IServerSession(org.eclipse.scout.rt.server.IServerSession) Test(org.junit.Test)

Aggregations

IServerSession (org.eclipse.scout.rt.server.IServerSession)18 Test (org.junit.Test)12 TestHttpSession (org.eclipse.scout.rt.testing.server.TestHttpSession)6 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)4 Subject (javax.security.auth.Subject)3 HttpSession (javax.servlet.http.HttpSession)3 ISession (org.eclipse.scout.rt.shared.ISession)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2 WebMethod (javax.jws.WebMethod)2 BooleanHolder (org.eclipse.scout.rt.platform.holders.BooleanHolder)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 ITransaction (org.eclipse.scout.rt.platform.transaction.ITransaction)2 IClientNotificationService (org.eclipse.scout.rt.shared.clientnotification.IClientNotificationService)2 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)2 Principal (java.security.Principal)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 ClientNotificationDispatcher (org.eclipse.scout.rt.client.clientnotification.ClientNotificationDispatcher)1