Search in sources :

Example 21 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class JmsPublishSubscribeMessageService method initializeService.

@PostConstruct
protected void initializeService() {
    try {
        @SuppressWarnings("squid:S1149") Hashtable<Object, Object> env = new Hashtable<>();
        setupInitialContextEnvironment(env);
        InitialContext context = new InitialContext(env.isEmpty() ? null : env);
        m_connectionFactory = (ConnectionFactory) context.lookup(CONFIG.getPropertyValue(JndiConnectionFactory.class));
        m_destination = (Destination) context.lookup(CONFIG.getPropertyValue(PublishSubscribeTopic.class));
    } catch (NamingException e) {
        throw new PlatformException("cannot setup jms", e);
    }
}
Also used : JndiConnectionFactory(org.eclipse.scout.rt.server.jms.clustersync.JmsPublishSubscribeMessageProperties.JndiConnectionFactory) PublishSubscribeTopic(org.eclipse.scout.rt.server.jms.clustersync.JmsPublishSubscribeMessageProperties.PublishSubscribeTopic) Hashtable(java.util.Hashtable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) PostConstruct(javax.annotation.PostConstruct)

Example 22 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class ClientExceptionHandler method showExceptionInternal.

protected void showExceptionInternal(final Throwable t) {
    final IClientSession session = ClientSessionProvider.currentSession();
    if (session == null) {
        return;
    }
    if (session.getDesktop() == null || !session.getDesktop().isOpened()) {
        return;
    }
    // Prevent loops while displaying the exception.
    final Semaphore loopDetectionSemaphore = getLoopDetectionSemaphore(session);
    if (loopDetectionSemaphore.tryAcquire()) {
        try {
            // Synchronize with the model thread if not applicable.
            if (ModelJobs.isModelThread()) {
                showException(t);
            } else {
                try {
                    ModelJobs.schedule(new IRunnable() {

                        @Override
                        public void run() throws Exception {
                            showException(t);
                        }
                    }, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withExceptionHandling(null, true).withName("Visualizing PlatformException")).awaitDone();
                } catch (final ThreadInterruptedError e) {
                // NOSONAR
                // NOOP
                }
            }
        } finally {
            loopDetectionSemaphore.release();
        }
    } else {
        Exception e = new Exception("Stacktrace and suppressed exception");
        // add original exception for analysis
        e.addSuppressed(t);
        LOG.warn("Loop detection in {}", getClass().getName(), e);
        if (ModelJobs.isModelThread()) {
            IMessageBox msgBox = MessageBoxes.createOk().withSeverity(IStatus.ERROR).withHeader(TEXTS.get("Error"));
            if (t instanceof VetoException) {
                IProcessingStatus status = ((VetoException) t).getStatus();
                msgBox.withHeader(status.getTitle()).withBody(status.getBody());
            }
            msgBox.show();
        }
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IProcessingStatus(org.eclipse.scout.rt.platform.exception.IProcessingStatus) IClientSession(org.eclipse.scout.rt.client.IClientSession) ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) Semaphore(java.util.concurrent.Semaphore) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IMessageBox(org.eclipse.scout.rt.client.ui.messagebox.IMessageBox)

Example 23 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class AbstractForm method startInternal.

/**
 * This method is called from the implemented handler methods in a explicit form subclass
 */
protected IForm startInternal(final IFormHandler handler) {
    ClientRunContexts.copyCurrent().withForm(this).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            if (isBlockingInternal()) {
                throw new IllegalStateException("The form " + getFormId() + " has already been started");
            }
            // Ensure that boolean is set not only once by the constructor
            setFormLoading(true);
            setHandler(handler);
            m_closeType = IButton.SYSTEM_TYPE_NONE;
            m_blockingCondition.setBlocking(true);
            try {
                initForm();
                loadStateInternal();
                // if form was disposed during initForm() or loadStateInternal()
                if (!isBlockingInternal()) {
                    return;
                }
                if (getHandler().isGuiLess()) {
                    // make sure the form is storing since it is not showing
                    storeStateInternal();
                    markSaved();
                    doFinally();
                    disposeFormInternal();
                    return;
                }
            } catch (RuntimeException | PlatformError e) {
                disposeFormInternal();
                PlatformException pe = BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", AbstractForm.this.getClass().getName());
                if (pe instanceof VetoException) {
                    VetoException ve = (VetoException) pe;
                    interceptOnVetoException(ve, ve.getStatus().getCode());
                }
                throw pe;
            }
            setButtonsArmed(true);
            setCloseTimerArmed(true);
            setFormStarted(true);
            // Notify the UI to display this form.
            if (isShowOnStart()) {
                IDesktop desktop = getDesktop();
                if (desktop == null || !desktop.isOpened()) {
                    throw new ProcessingException("There is no desktop or it is not open in the UI.");
                } else {
                    desktop.showForm(AbstractForm.this);
                }
            }
        }
    });
    return this;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 24 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class AbstractForm method throwVetoExceptionInternal.

/**
 * do not use or override this internal method
 */
protected void throwVetoExceptionInternal(final RuntimeException e) {
    PlatformException pe = BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
    if (pe instanceof VetoException && !pe.isConsumed()) {
        VetoException ve = (VetoException) pe;
        interceptOnVetoException(ve, ve.getStatus().getCode());
        // if it was not re-thrown it is assumed to be consumed
        ve.consume();
    }
    throw e;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 25 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class FinalValueTest method testLazySetWithException.

@Test
public void testLazySetWithException() throws Exception {
    FinalValue<String> s = new FinalValue<>();
    try {
        s.setIfAbsent(new Callable<String>() {

            @Override
            public String call() throws Exception {
                throw new Exception("expected JUnit test exception");
            }
        });
        fail("expecting PlatformException");
    } catch (PlatformException expected) {
    }
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Aggregations

PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)35 Test (org.junit.Test)13 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)9 IOException (java.io.IOException)8 FileInputStream (java.io.FileInputStream)4 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)4 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 TestLookupCall (org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)3 File (java.io.File)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)2