[Minor] Logging of exception in StrolchSystemActionWithResult

This commit is contained in:
Robert von Burg 2018-08-03 22:14:12 +02:00
parent 2eaca7d7d8
commit f6349dde10
3 changed files with 21 additions and 11 deletions

View File

@ -72,8 +72,8 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements
* @param privilegeXmlFile
* a {@link File} reference to the XML file containing the configuration for Privilege
*
* @return the initialized {@link PrivilegeHandler} where the {@link EncryptionHandler} and
* {@link PersistenceHandler} are set and initialized as well
* @return the initialized {@link PrivilegeHandler} where the {@link EncryptionHandler} and {@link
* PersistenceHandler} are set and initialized as well
*/
private li.strolch.privilege.handler.PrivilegeHandler initializeFromXml(ComponentConfiguration configuration,
File privilegeXmlFile) {

View File

@ -14,7 +14,7 @@ public class StrolchSystemAction extends SystemAction {
public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class);
private PrivilegedRunnable runnable;
private final PrivilegedRunnable runnable;
public StrolchSystemAction(PrivilegedRunnable runnable) {
this.runnable = runnable;

View File

@ -3,16 +3,20 @@ package li.strolch.runtime.privilege;
import li.strolch.privilege.handler.SystemAction;
import li.strolch.privilege.handler.SystemActionWithResult;
import li.strolch.privilege.model.PrivilegeContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* {@link SystemAction} to run {@link PrivilegedRunnableWithResult} as a system user
*
* @author Robert von Burg <eitch@eitchnet.ch>
*
* @param <T>
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class StrolchSystemActionWithResult<T> extends SystemActionWithResult<T> {
public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class);
private PrivilegedRunnableWithResult<T> runnable;
public StrolchSystemActionWithResult(PrivilegedRunnableWithResult<T> runnable) {
@ -21,6 +25,12 @@ public class StrolchSystemActionWithResult<T> extends SystemActionWithResult<T>
@Override
public T execute(PrivilegeContext privilegeContext) {
try {
return this.runnable.run(privilegeContext);
} catch (Exception e) {
logger.error("Failed to execute SystemAction for " + privilegeContext.getUsername() + " due to " + e
.getMessage(), e);
throw e;
}
}
}