Search in sources :

Example 31 with PlatformException

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

the class UploadRequestHandler method handleUploadFileRequest.

protected void handleUploadFileRequest(IUiSession uiSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String targetAdapterId) throws IOException, FileUploadException {
    // If client sent ACK#, cleanup response history accordingly
    uiSession.confirmResponseProcessed(getAckSequenceNo(httpServletRequest));
    IBinaryResourceConsumer binaryResourceConsumer = resolveJsonAdapter(uiSession, targetAdapterId);
    if (binaryResourceConsumer == null) {
        // Request was already processed and adapter does not exist anymore
        return;
    }
    if (httpServletRequest.getParameter("legacy") != null) {
        httpServletResponse.setContentType("text/plain");
    }
    // Read uploaded data
    Map<String, String> uploadProperties = new HashMap<String, String>();
    List<BinaryResource> uploadResources = new ArrayList<>();
    try {
        readUploadData(httpServletRequest, binaryResourceConsumer.getMaximumBinaryResourceUploadSize(), uploadProperties, uploadResources);
    } catch (PlatformException ex) {
        // NOSONAR
        writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createUnsafeUploadResponse());
        return;
    }
    // GUI requests for the same session must be processed consecutively
    final ReentrantLock uiSessionLock = uiSession.uiSessionLock();
    uiSessionLock.lock();
    try {
        if (uiSession.isDisposed()) {
            writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createSessionTimeoutResponse());
            return;
        }
        JSONObject jsonResp = uiSession.processFileUpload(httpServletRequest, httpServletResponse, binaryResourceConsumer, uploadResources, uploadProperties);
        if (jsonResp == null) {
            jsonResp = m_jsonRequestHelper.createEmptyResponse();
        }
        writeJsonResponse(httpServletResponse, jsonResp);
    } finally {
        uiSessionLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ArrayList(java.util.ArrayList) IBinaryResourceConsumer(org.eclipse.scout.rt.ui.html.res.IBinaryResourceConsumer)

Example 32 with PlatformException

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

the class RunContextExceptionTranslationTest method test.

@Test
public void test() {
    final Exception error = new Exception("expected JUnit test exception");
    IRunnable runnableWithError = new IRunnable() {

        @Override
        public void run() throws Exception {
            throw error;
        }
    };
    // Test with DefaultRuntimeExceptionTranslator
    try {
        RunContexts.empty().run(runnableWithError);
        fail();
    } catch (PlatformException e) {
        assertSame(error, e.getCause());
    }
    // Test with DefaultRuntimeExceptionTranslator
    try {
        RunContexts.empty().run(runnableWithError, DefaultRuntimeExceptionTranslator.class);
        fail();
    } catch (PlatformException e) {
        assertSame(error, e.getCause());
    }
    // Test with DefaultExceptionTranslator
    try {
        RunContexts.empty().run(runnableWithError, DefaultExceptionTranslator.class);
        fail();
    } catch (RuntimeException e) {
        fail();
    } catch (Exception e) {
        assertSame(error, e);
    }
    // Test with PlatformExceptionTranslator
    try {
        RunContexts.empty().run(runnableWithError, PlatformExceptionTranslator.class);
        fail();
    } catch (PlatformException e) {
        assertSame(error, e.getCause());
    }
}
Also used : 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) Test(org.junit.Test)

Example 33 with PlatformException

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

the class PlatformImplementorTest method testAwaitPlatformStartedFailsInPlatformStopping.

@Test
public void testAwaitPlatformStartedFailsInPlatformStopping() throws Exception {
    final CountDownLatch stoppingLatch = new CountDownLatch(1);
    final CountDownLatch continueStoppingLatch = new CountDownLatch(1);
    // crate platform listener that signals stopping state
    BeanMetaData bean = new BeanMetaData(IPlatformListener.class).withApplicationScoped(true).withInitialInstance(new IPlatformListener() {

        @Override
        public void stateChanged(PlatformEvent event) {
            if (event.getState() == State.PlatformStopping) {
                stoppingLatch.countDown();
                try {
                    continueStoppingLatch.await();
                } catch (InterruptedException e) {
                // nop
                }
            }
        }
    });
    final TestingPlatformImplementor platform = new TestingPlatformImplementor(bean);
    platform.start();
    // expect platform started
    platform.awaitPlatformStarted();
    Future<?> platformStopFuture = s_executor.submit(new Runnable() {

        @Override
        public void run() {
            platform.stop();
        }
    });
    stoppingLatch.await();
    try {
        platform.awaitPlatformStarted();
    } catch (PlatformException e) {
        assertEquals("The platform is stopping.", e.getMessage());
    }
    continueStoppingLatch.countDown();
    platformStopFuture.get();
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) PlatformEvent(org.eclipse.scout.rt.platform.PlatformEvent) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) CountDownLatch(java.util.concurrent.CountDownLatch) IPlatformListener(org.eclipse.scout.rt.platform.IPlatformListener) Test(org.junit.Test)

Example 34 with PlatformException

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

the class JandexInventoryBuilder method readIndex.

/**
 * @param indexUri
 * @return index or null
 */
protected Index readIndex(URI indexUri, InputStream in) {
    try {
        Index index = new IndexReader(in).read();
        LOG.debug("Found pre-built {}", indexUri);
        return index;
    } catch (Exception ex) {
        throw new PlatformException("Error reading index '{}'", indexUri, ex);
    }
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IndexReader(org.jboss.jandex.IndexReader) CompositeIndex(org.jboss.jandex.CompositeIndex) Index(org.jboss.jandex.Index) URISyntaxException(java.net.URISyntaxException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 35 with PlatformException

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

the class JaxWsPlatformListener method installImplementorSpecifics.

protected void installImplementorSpecifics(final IBeanManager beanManager) {
    final String jaxwsImplementor = CONFIG.getPropertyValue(JaxWsImplementorProperty.class);
    if (jaxwsImplementor == null) {
        return;
    }
    try {
        final Class<?> jaxwsImplementorClazz = Class.forName(jaxwsImplementor);
        Assertions.assertTrue(JaxWsImplementorSpecifics.class.isAssignableFrom(jaxwsImplementorClazz), "Implementor class must be of type '{}'.", JaxWsImplementorSpecifics.class.getName());
        // Unregister the Bean first, so it can be registered with @Replace annotation anew.
        beanManager.unregisterClass(jaxwsImplementorClazz);
        beanManager.registerBean(new BeanMetaData(jaxwsImplementorClazz).withReplace(true));
        LOG.info("JAX-WS implementor specific class installed: {}", jaxwsImplementorClazz.getName());
    } catch (final ClassNotFoundException e) {
        throw new PlatformException("Configured JAX-WS implementor specific class", e);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) JaxWsImplementorSpecifics(org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics)

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