return String.format("(&%s(%s=%s))", filter, org.osgi.framework.Constants.SERVICE_PID, serviceId);
}
}
private MethodResult invokeMethod(Object service, Method method, Object[] args) {
MethodResult returnTemplate = new MethodResult();
try {
Object result = method.invoke(service, args);
if (method.getReturnType().getName().equals("void")) {
returnTemplate.setType(ReturnType.Void);
} else {
returnTemplate.setType(ReturnType.Object);
returnTemplate.setArg(result);
String resultClassName =
result == null ? method.getReturnType().getName() : result.getClass().getName();
returnTemplate.setClassName(resultClassName);
}
} catch (Exception e) {
LOGGER.warn("Exception in remote method invocation: ", e);
returnTemplate.setType(ReturnType.Exception);
if (e.getClass().equals(InvocationTargetException.class)) {
e = (Exception) e.getCause();
// if it's not an Exception we are in REAL trouble anyway
}
returnTemplate.setArg(e.getCause());
returnTemplate.setClassName(e.getClass().getName());
}
return returnTemplate;
}