* @param request the request
* @param caller the caller performing the invocation
* @return the result of the invocation
*/
protected Response invoke(Request request, Caller caller) {
Response response;
try {
Object object = getObject(request.getObjID(),
request.getURI());
Method method = request.getMethod();
if (method == null) {
// resolve the method using its id
method = getMethod(object, request.getMethodID());
}
Object[] args = request.getArgs();
if (args == null) {
// deserialize the arguments
args = request.readArgs(method);
}
if (_log.isDebugEnabled()) {
_log.debug("Invoking " + method + " on " + object);
}
_caller.set(caller);
Object result = method.invoke(object, args);
response = new Response(result, method);
} catch (InvocationTargetException exception) {
Throwable target = exception.getTargetException();
if (target == null) {
target = exception;
}
response = new Response(target);
} catch (Throwable exception) {
response = new Response(exception);
} finally {
_caller.set(null);
}
return response;
}