oos = new ObjectOutputStream(new BufferedOutputStream(socket
.getOutputStream()));
MethodRequest mr = (MethodRequest)ois.readObject();
MethodResponse mresp = null;
String objectId = mr.getObjectId();
if (StringUtils.isNotEmpty(objectId)) {
// do the dispatching
Object remote = remoteObjects.get(objectId);
if (remote != null) {
String methodName = mr.getMethodName();
if (StringUtils.isNotEmpty(methodName)) {
Object[] params = mr.getParams();
try {
// execute method and reply
Object retVal = MethodUtils.invokeMethod(
remote, methodName, params);
mresp = new MethodResponse(
MethodResponse.ResultCode.SUCCESS,
retVal, null);
} catch (NoSuchMethodException nsme) {
// server error, no such method
mresp = new MethodResponse(
MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
null, new SimpleRpcException("no such method m=" + methodName));
} catch (IllegalAccessException iae) {
// server error, method not accessible
mresp = new MethodResponse(
MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
null, new SimpleRpcException("method not accessible, m=" + methodName));
} catch (InvocationTargetException ite) {
// real business object exception
mresp = new MethodResponse(
MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
null, ite.getTargetException());
}
} else {
// server error, invalid method name
mresp = new MethodResponse(
MethodResponse.ResultCode.REMOTE_OBJECT_EXCEPTION,
null, new SimpleRpcException("no such method m=" + methodName));
}
} else {
// return server error, could not find object
mresp = new MethodResponse(
MethodResponse.ResultCode.SERVER_ERROR,
null, new SimpleRpcException("object not found objectId=" + objectId));
}
} else {
// return server error, invalid key
mresp = new MethodResponse(
MethodResponse.ResultCode.SERVER_ERROR,
null, new SimpleRpcException("invalid objectId=" + objectId));
}
// write response