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;
}
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);
}
}
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();
}
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());
}
}
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);
}
Aggregations