Search in sources :

Example 26 with PlatformException

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

the class ServiceOperationInvoker method invoke.

/**
 * Invoke the service associated with the {@link ServiceTunnelRequest}. <br>
 * Must be called within a transaction.
 */
@SuppressWarnings("squid:S1193")
public ServiceTunnelResponse invoke(final RunContext runContext, final ServiceTunnelRequest serviceReq) {
    final long t0 = System.nanoTime();
    ServiceTunnelResponse response;
    try {
        response = runContext.call(new Callable<ServiceTunnelResponse>() {

            @Override
            public ServiceTunnelResponse call() throws Exception {
                return invokeInternal(serviceReq);
            }
        }, DefaultExceptionTranslator.class);
    } catch (Exception e) {
        // Associate the exception with context information about the service call.
        if (e instanceof PlatformException) {
            ((PlatformException) e).withContextInfo("service.name", serviceReq.getServiceInterfaceClassName()).withContextInfo("service.operation", serviceReq.getOperation());
        }
        // Handle the exception.
        handleException(e);
        // Prepare ServiceTunnelResponse.
        response = new ServiceTunnelResponse(interceptException(e));
    }
    response.setProcessingDuration(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t0));
    LOG.debug("TIME {}.{} {}ms", serviceReq.getServiceInterfaceClassName(), serviceReq.getOperation(), response.getProcessingDuration());
    return response;
}
Also used : DefaultExceptionTranslator(org.eclipse.scout.rt.platform.exception.DefaultExceptionTranslator) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse) Callable(java.util.concurrent.Callable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Example 27 with PlatformException

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

the class DefaultAuthToken method createUnsignedData.

protected byte[] createUnsignedData() {
    try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        HexOutputStream hex = new HexOutputStream(bytes)) {
        hex.write(m_userId.getBytes(StandardCharsets.UTF_8));
        bytes.write(partsDelimiter());
        bytes.write(Long.toHexString(m_validUntil).getBytes());
        if (m_customArgs != null) {
            for (String arg : m_customArgs) {
                bytes.write(partsDelimiter());
                hex.write(arg.getBytes(StandardCharsets.UTF_8));
            }
        }
        return bytes.toByteArray();
    } catch (IOException ex) {
        throw new PlatformException("unexpected behaviour", ex);
    }
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HexOutputStream(org.eclipse.scout.rt.platform.util.HexUtility.HexOutputStream) IOException(java.io.IOException)

Example 28 with PlatformException

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

the class AbstractServiceTunnel method invokeService.

public Object invokeService(ServiceTunnelRequest request) {
    final long t0 = System.nanoTime();
    checkAlreadyCancelled(request);
    beforeTunnel(request);
    ServiceTunnelResponse response = tunnel(request);
    afterTunnel(t0, response);
    // Exception handling
    Throwable t = response.getException();
    if (t != null) {
        // Associate the exception with context information about the service call (without arg values due to security reasons).
        RuntimeException serviceException = interceptException(t);
        if (serviceException instanceof PlatformException) {
            ((PlatformException) serviceException).withContextInfo("remote-service.name", request.getServiceInterfaceClassName()).withContextInfo("remote-service.operation", request.getOperation());
        }
        // Combine local and remote stacktraces.
        StackTraceElement[] trace1 = serviceException.getStackTrace();
        StackTraceElement[] trace2 = new Exception().getStackTrace();
        StackTraceElement[] both = new StackTraceElement[trace1.length + trace2.length];
        System.arraycopy(trace1, 0, both, 0, trace1.length);
        System.arraycopy(trace2, 0, both, trace1.length, trace2.length);
        serviceException.setStackTrace(both);
        throw serviceException;
    }
    BEANS.get(ServiceUtility.class).updateHolderArguments(request.getArgs(), response.getOutVars(), false);
    return response.getData();
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 29 with PlatformException

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

the class JobExceptionTranslationTest method testWithImplicitExceptionTranslator.

@Test
public void testWithImplicitExceptionTranslator() {
    final Exception error = new Exception("expected JUnit test exception");
    IFuture<Void> future = Jobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            throw error;
        }
    }, Jobs.newInput());
    try {
        future.awaitDoneAndGet();
        fail("PlatformException expected");
    } 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) ExecutionException(java.util.concurrent.ExecutionException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) Test(org.junit.Test)

Example 30 with PlatformException

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

the class JobAsyncExceptionTest method testExceptionInCallable.

@Test(expected = PlatformException.class)
public void testExceptionInCallable() throws Exception {
    P_JobManager jobManager = new P_JobManager();
    IFuture<Void> future = jobManager.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            throw new PlatformException("Expected test exception");
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()));
    future.awaitDone();
    Assert.assertTrue(jobManager.e1 instanceof PlatformException);
    Assert.assertTrue(jobManager.e2 instanceof CallableChainHandledException);
    Assert.assertTrue(jobManager.e3 instanceof PlatformException);
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) CallableChainHandledException(org.eclipse.scout.rt.platform.job.internal.CallableChainHandledException) CallableChainHandledException(org.eclipse.scout.rt.platform.job.internal.CallableChainHandledException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) 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