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;
}
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(" remoteUser: " + p.getRequest().getRemoteUser());
p.br();
Principal remotePrincipal = p.getRequest().getUserPrincipal();
if (remotePrincipal != null) {
p.print(" userPrincipal: " + remotePrincipal.getName() + " [" + remotePrincipal.getClass().getSimpleName() + "]");
} else {
p.print(" userPrincipal: null");
}
p.br();
try {
SecurityManager sm = System.getSecurityManager();
p.print(" SecurityManager: " + sm);
p.br();
Subject subject = Subject.getSubject(AccessController.getContext());
p.print(" 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(" 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);
}
}
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);
}
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);
}
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);
}
Aggregations