[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,11 +72,11 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements
* @param privilegeXmlFile * @param privilegeXmlFile
* a {@link File} reference to the XML file containing the configuration for Privilege * a {@link File} reference to the XML file containing the configuration for Privilege
* *
* @return the initialized {@link PrivilegeHandler} where the {@link EncryptionHandler} and * @return the initialized {@link PrivilegeHandler} where the {@link EncryptionHandler} and {@link
* {@link PersistenceHandler} are set and initialized as well * PersistenceHandler} are set and initialized as well
*/ */
private li.strolch.privilege.handler.PrivilegeHandler initializeFromXml(ComponentConfiguration configuration, private li.strolch.privilege.handler.PrivilegeHandler initializeFromXml(ComponentConfiguration configuration,
File privilegeXmlFile) { File privilegeXmlFile) {
// make sure file exists // make sure file exists
if (!privilegeXmlFile.exists()) { if (!privilegeXmlFile.exists()) {

View File

@ -14,7 +14,7 @@ public class StrolchSystemAction extends SystemAction {
public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class); public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class);
private PrivilegedRunnable runnable; private final PrivilegedRunnable runnable;
public StrolchSystemAction(PrivilegedRunnable runnable) { public StrolchSystemAction(PrivilegedRunnable runnable) {
this.runnable = 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.SystemAction;
import li.strolch.privilege.handler.SystemActionWithResult; import li.strolch.privilege.handler.SystemActionWithResult;
import li.strolch.privilege.model.PrivilegeContext; import li.strolch.privilege.model.PrivilegeContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* {@link SystemAction} to run {@link PrivilegedRunnableWithResult} as a system user * {@link SystemAction} to run {@link PrivilegedRunnableWithResult} as a system user
* *
* @author Robert von Burg <eitch@eitchnet.ch>
*
* @param <T> * @param <T>
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/ */
public class StrolchSystemActionWithResult<T> extends SystemActionWithResult<T> { public class StrolchSystemActionWithResult<T> extends SystemActionWithResult<T> {
public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class);
private PrivilegedRunnableWithResult<T> runnable; private PrivilegedRunnableWithResult<T> runnable;
public StrolchSystemActionWithResult(PrivilegedRunnableWithResult<T> runnable) { public StrolchSystemActionWithResult(PrivilegedRunnableWithResult<T> runnable) {
@ -21,6 +25,12 @@ public class StrolchSystemActionWithResult<T> extends SystemActionWithResult<T>
@Override @Override
public T execute(PrivilegeContext privilegeContext) { public T execute(PrivilegeContext privilegeContext) {
return this.runnable.run(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;
}
} }
} }