[Minor] better exception handling if Service returns null service result
This commit is contained in:
parent
19c7a120ca
commit
aa5ac4f7da
|
@ -17,6 +17,7 @@ package li.strolch.service;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.runtime.agent.api.ComponentContainer;
|
import li.strolch.runtime.agent.api.ComponentContainer;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -61,7 +62,14 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return internalDoService(argument);
|
U serviceResult = internalDoService(argument);
|
||||||
|
if (serviceResult == null) {
|
||||||
|
String msg = "Service {0} is not properly implemented as it returned a null result!"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, this.getClass().getName());
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return serviceResult;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
@ -97,10 +105,10 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
* Internal method to perform the {@link Service}. The implementor does not need to handle exceptions as this is
|
* Internal method to perform the {@link Service}. The implementor does not need to handle exceptions as this is
|
||||||
* done in the {@link #doService(ServiceArgument)} which calls this method
|
* done in the {@link #doService(ServiceArgument)} which calls this method
|
||||||
*
|
*
|
||||||
* @param argument
|
* @param arg
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract U internalDoService(T argument);
|
protected abstract U internalDoService(T arg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
|
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
|
||||||
|
|
|
@ -76,6 +76,11 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa
|
||||||
// then perform the service
|
// then perform the service
|
||||||
service.setContainer(getContainer());
|
service.setContainer(getContainer());
|
||||||
U serviceResult = service.doService(argument);
|
U serviceResult = service.doService(argument);
|
||||||
|
if (serviceResult == null) {
|
||||||
|
String msg = "Service {0} is not properly implemented as it returned a null result!"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, service);
|
||||||
|
throw new StrolchException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
// log the result
|
// log the result
|
||||||
long end = System.nanoTime();
|
long end = System.nanoTime();
|
||||||
|
|
Loading…
Reference in New Issue