{
result = invokedMethod.invoke(resource, args);
}
catch (IllegalAccessException e)
{
throw new InternalServerErrorException("Not allowed to reflect on method: " + method.toString(), e);
}
catch (InvocationTargetException e)
{
Throwable cause = e.getCause();
if (validator instanceof GeneralValidatorCDI)
{
GeneralValidatorCDI.class.cast(validator).checkForConstraintViolations(request, e);
}
throw new ApplicationException(cause);
}
catch (IllegalArgumentException e)
{
String msg = "Bad arguments passed to " + method.toString() + " (";
if (args != null)
{
boolean first = false;
for (Object arg : args)
{
if (!first)
{
first = true;
}
else
{
msg += ",";
}
if (arg == null)
{
msg += " null";
continue;
}
msg += " " + arg.getClass().getName() + " " + arg;
}
}
msg += " )";
throw new InternalServerErrorException(msg, e);
}
if (validator != null)
{
validator.validateReturnValue(request, resource, method.getMethod(), result);
}