public Object invoke(Invocation invocation) throws Exception {
String methodName;
if (invocation.getMethod() != null)
{
methodName = invocation.getMethod().getName();
}
else
{
methodName = "< no method >";
}
boolean trace = log.isTraceEnabled();
if (trace)
{
log.trace("Start method=" + methodName);
}
// Log call details
if (callLogging)
{
StringBuffer str = new StringBuffer("Invoke: ");
if (invocation.getId() != null)
{
str.append("[");
str.append(invocation.getId().toString());
str.append("] ");
}
str.append(methodName);
str.append("(");
Object[] args = invocation.getArguments();
if (args != null)
{
for (int i = 0; i < args.length; i++)
{
if (i > 0)
{
str.append(",");
}
str.append(args[i]);
}
}
str.append(")");
log.debug(str.toString());
}
try
{
return getNext().invoke(invocation);
}
catch(Throwable e)
{
throw handleException(e, invocation);
}
finally
{
if (trace)
{
log.trace("End method=" + methodName);
}
}
}
This method logs the method, calls the next invoker, and handles
any exception. |