Search in sources :

Example 11 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class ServerRunContextTest method testRunContextsEmpty.

@Test
public void testRunContextsEmpty() {
    RunContext runContext = RunContexts.empty();
    assertThat(runContext, CoreMatchers.instanceOf(ServerRunContext.class));
    ServerRunContext serverCtx = (ServerRunContext) runContext;
    assertNull(serverCtx.getSubject());
    assertNull(serverCtx.getSession());
    assertNull(serverCtx.getUserAgent());
    assertNull(serverCtx.getLocale());
    assertEquals(TransactionScope.REQUIRES_NEW, serverCtx.getTransactionScope());
}
Also used : RunContext(org.eclipse.scout.rt.platform.context.RunContext) Test(org.junit.Test)

Example 12 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class JaxWsRunContextLookup method lookupRunContext.

/**
 * Method invoked to look up the {@link RunContext}, and must not return <code>null</code>.
 */
protected RunContext lookupRunContext(final WebServiceContext webServiceContext) {
    final RunContext runContext = MessageContexts.getRunContext(webServiceContext.getMessageContext());
    if (runContext != null) {
        return runContext;
    }
    if (RunContext.CURRENT.get() != null) {
        return RunContext.CURRENT.get().copy();
    }
    LOG.warn(RUNCONTEXT_MISSING_WARNING);
    return RunContexts.empty();
}
Also used : RunContext(org.eclipse.scout.rt.platform.context.RunContext)

Example 13 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class JobCancelTest method testCancelRunContextPriorSchedulingJob.

/**
 * Tests that a job is not run if the RunMonitor is already cancelled.
 */
@Test
public void testCancelRunContextPriorSchedulingJob() {
    RunContext runContext = RunContexts.copyCurrent();
    // 1. Cancel the RunMonitor
    runContext.getRunMonitor().cancel(false);
    // 2. Schedule the job (should never)
    final AtomicBoolean executed = new AtomicBoolean(false);
    IFuture<Void> future = Jobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            executed.set(true);
        }
    }, Jobs.newInput().withRunContext(runContext));
    future.awaitDone();
    assertFalse(executed.get());
    assertTrue(future.isCancelled());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RunContext(org.eclipse.scout.rt.platform.context.RunContext) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 14 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class SessionFutureFilter method accept.

@Override
public boolean accept(final IFuture<?> future) {
    final RunContext runContext = future.getJobInput().getRunContext();
    if (runContext == null) {
        return false;
    }
    final ISession session = runContext.getAdapter(ISession.class);
    if (session == null) {
        return false;
    }
    return m_session == session;
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) RunContext(org.eclipse.scout.rt.platform.context.RunContext)

Aggregations

RunContext (org.eclipse.scout.rt.platform.context.RunContext)14 Test (org.junit.Test)8 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)6 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)5 Subject (javax.security.auth.Subject)3 Locale (java.util.Locale)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)2 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MessageContext (javax.xml.ws.handler.MessageContext)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 ClientRunContext (org.eclipse.scout.rt.client.context.ClientRunContext)1 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 IFilter (org.eclipse.scout.rt.platform.filter.IFilter)1 IBlockingCondition (org.eclipse.scout.rt.platform.job.IBlockingCondition)1 IFuture (org.eclipse.scout.rt.platform.job.IFuture)1