use of com.haulmont.cuba.core.global.RemoteException in project cuba by cuba-platform.
the class DesktopTimer method handleTimerException.
protected void handleTimerException(RuntimeException ex) {
if (ExceptionUtils.indexOfType(ex, java.net.ConnectException.class) > -1) {
// If a ConnectException occurred, just log it and ignore
log.warn("onTimer error: " + ex.getMessage());
} else {
// Otherwise throw the exception, but first search for NoUserSessionException in chain,
// if found - stop the timer
int reIdx = ExceptionUtils.indexOfType(ex, RemoteException.class);
if (reIdx > -1) {
RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(ex).get(reIdx);
for (RemoteException.Cause cause : re.getCauses()) {
// noinspection ThrowableResultOfMethodCallIgnored
if (cause.getThrowable() instanceof NoUserSessionException) {
log.warn("NoUserSessionException in timer, timer will be stopped");
disposeTimer();
break;
}
}
} else if (ExceptionUtils.indexOfThrowable(ex, NoUserSessionException.class) > -1) {
log.warn("NoUserSessionException in timer, timer will be stopped");
disposeTimer();
}
throw ex;
}
}
use of com.haulmont.cuba.core.global.RemoteException in project cuba by cuba-platform.
the class AbstractExceptionHandler method handle.
@Override
public boolean handle(ErrorEvent event, App app) {
Throwable exception = event.getThrowable();
// noinspection unchecked
List<Throwable> list = ExceptionUtils.getThrowableList(exception);
for (Throwable throwable : list) {
if (classNames.contains(throwable.getClass().getName()) && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) {
doHandle(app, throwable.getClass().getName(), throwable.getMessage(), throwable);
return true;
}
if (throwable instanceof RemoteException) {
RemoteException remoteException = (RemoteException) throwable;
for (RemoteException.Cause cause : remoteException.getCauses()) {
if (classNames.contains(cause.getClassName()) && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) {
doHandle(app, cause.getClassName(), cause.getMessage(), cause.getThrowable());
return true;
}
}
}
}
return false;
}
use of com.haulmont.cuba.core.global.RemoteException in project cuba by cuba-platform.
the class ServiceInterceptorTest method testNewThread.
@Test
public void testNewThread() throws Exception {
ServiceInterceptorTestService service = AppBeans.get(ServiceInterceptorTestService.class);
UserSessions userSessions = AppBeans.get(UserSessions.class);
// workaround for test security setup
Field startedField = AppContext.class.getDeclaredField("started");
startedField.setAccessible(true);
startedField.set(null, true);
AppContext.setSecurityContext(AppContext.NO_USER_CONTEXT);
UserSession userSession = new UserSession(AppContext.NO_USER_CONTEXT.getSessionId(), new User(), Collections.emptyList(), Locale.ENGLISH, true);
userSessions.add(userSession);
try {
appender.getMessages().clear();
service.declarativeTransactionNewThread();
assertEquals(0, appender.getMessages().stream().filter(s -> s.contains("from another service")).count());
appender.getMessages().clear();
try {
service.executeWithExceptionNewThread();
} catch (Exception e) {
assertTrue(e instanceof RemoteException && ((RemoteException) e).getFirstCauseException() instanceof TestingService.TestException);
}
} finally {
userSessions.remove(userSession);
startedField.set(null, false);
}
}
use of com.haulmont.cuba.core.global.RemoteException in project cuba by cuba-platform.
the class ServiceInterceptorTest method testExceptionHandling.
@Test
public void testExceptionHandling() throws Exception {
TestingService service1 = AppBeans.get(TestingService.class);
ServiceInterceptorTestService service2 = AppBeans.get(ServiceInterceptorTestService.class);
appender.getMessages().clear();
try {
service1.executeWithException();
} catch (Exception e) {
assertTrue(e instanceof RemoteException && ((RemoteException) e).getFirstCauseException() instanceof TestingService.TestException);
}
appender.getMessages().clear();
try {
service2.executeWithException();
} catch (Exception e) {
assertTrue(e instanceof RemoteException && ((RemoteException) e).getFirstCauseException() instanceof TestingService.TestException);
}
}
use of com.haulmont.cuba.core.global.RemoteException in project cuba by cuba-platform.
the class CubaTimer method handleOnTimerException.
protected void handleOnTimerException(RuntimeException e) {
int reIdx = ExceptionUtils.indexOfType(e, RemoteException.class);
if (reIdx > -1) {
RemoteException re = (RemoteException) ExceptionUtils.getThrowableList(e).get(reIdx);
for (RemoteException.Cause cause : re.getCauses()) {
// noinspection ThrowableResultOfMethodCallIgnored
if (cause.getThrowable() instanceof NoUserSessionException) {
log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId());
stop();
break;
}
}
} else if (ExceptionUtils.indexOfThrowable(e, NoUserSessionException.class) > -1) {
log.warn("NoUserSessionException in timer {}, timer will be stopped", getLoggingTimerId());
stop();
}
throw e;
}
Aggregations