mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch 'bugfix/CID-1191682'
This commit is contained in:
commit
d7f5a2705e
@ -100,8 +100,8 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||||||
if (paramObj == null) {
|
if (paramObj == null) {
|
||||||
if (parameterAnnotation.required()) {
|
if (parameterAnnotation.required()) {
|
||||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
|
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
|
||||||
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) +
|
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) +
|
||||||
" due to missing parameter " + parameterAnnotation.name());
|
" due to missing parameter " + parameterAnnotation.name());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -115,17 +115,17 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||||||
parameterAnnotation.name());
|
parameterAnnotation.name());
|
||||||
}
|
}
|
||||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
|
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
|
||||||
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " +
|
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " +
|
||||||
parameterAnnotation.name());
|
parameterAnnotation.name());
|
||||||
} catch (final ParseException parseEx) {
|
} catch (final ParseException parseEx) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
|
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
|
||||||
}
|
}
|
||||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " +
|
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " +
|
||||||
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation");
|
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation");
|
||||||
} catch (final InvalidParameterValueException invEx) {
|
} catch (final InvalidParameterValueException invEx) {
|
||||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
|
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
|
||||||
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
|
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
|
||||||
} catch (final CloudRuntimeException cloudEx) {
|
} catch (final CloudRuntimeException cloudEx) {
|
||||||
s_logger.error("CloudRuntimeException", cloudEx);
|
s_logger.error("CloudRuntimeException", cloudEx);
|
||||||
// FIXME: Better error message? This only happens if the API command is not executable, which typically
|
// FIXME: Better error message? This only happens if the API command is not executable, which typically
|
||||||
@ -133,7 +133,7 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||||||
// there was
|
// there was
|
||||||
// and IllegalAccessException setting one of the parameters.
|
// and IllegalAccessException setting one of the parameters.
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " +
|
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " +
|
||||||
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
|
cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
//check access on the resource this field points to
|
//check access on the resource this field points to
|
||||||
@ -157,46 +157,46 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||||||
// Check if the parameter type is a single
|
// Check if the parameter type is a single
|
||||||
// Id or list of id's/name's
|
// Id or list of id's/name's
|
||||||
switch (fieldType) {
|
switch (fieldType) {
|
||||||
case LIST:
|
case LIST:
|
||||||
final CommandType listType = parameterAnnotation.collectionType();
|
final CommandType listType = parameterAnnotation.collectionType();
|
||||||
switch (listType) {
|
switch (listType) {
|
||||||
case LONG:
|
|
||||||
case UUID:
|
|
||||||
final List<Long> listParam = (List<Long>) field.get(cmd);
|
|
||||||
for (final Long entityId : listParam) {
|
|
||||||
for (final Class entity : entityList) {
|
|
||||||
final Object entityObj = _entityMgr.findById(entity, entityId);
|
|
||||||
if(entityObj != null){
|
|
||||||
entitiesToAccess.put(entityObj, checkAccess.accessType());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
/*
|
|
||||||
* case STRING: List<String> listParam = new
|
|
||||||
* ArrayList<String>(); listParam =
|
|
||||||
* (List)field.get(cmd); for(String entityName:
|
|
||||||
* listParam){ ControlledEntity entityObj =
|
|
||||||
* (ControlledEntity )daoClassInstance(entityId);
|
|
||||||
* entitiesToAccess.add(entityObj); } break;
|
|
||||||
*/
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LONG:
|
case LONG:
|
||||||
case UUID:
|
case UUID:
|
||||||
for (final Class entity : entityList) {
|
final List<Long> listParam = (List<Long>) field.get(cmd);
|
||||||
final Object entityObj = _entityMgr.findById(entity, (Long) field.get(cmd));
|
for (final Long entityId : listParam) {
|
||||||
if(entityObj != null){
|
for (final Class entity : entityList) {
|
||||||
entitiesToAccess.put(entityObj, checkAccess.accessType());
|
final Object entityObj = _entityMgr.findById(entity, entityId);
|
||||||
break;
|
if(entityObj != null){
|
||||||
|
entitiesToAccess.put(entityObj, checkAccess.accessType());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/*
|
||||||
|
* case STRING: List<String> listParam = new
|
||||||
|
* ArrayList<String>(); listParam =
|
||||||
|
* (List)field.get(cmd); for(String entityName:
|
||||||
|
* listParam){ ControlledEntity entityObj =
|
||||||
|
* (ControlledEntity )daoClassInstance(entityId);
|
||||||
|
* entitiesToAccess.add(entityObj); } break;
|
||||||
|
*/
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LONG:
|
||||||
|
case UUID:
|
||||||
|
for (final Class entity : entityList) {
|
||||||
|
final Object entityObj = _entityMgr.findById(entity, (Long) field.get(cmd));
|
||||||
|
if(entityObj != null){
|
||||||
|
entitiesToAccess.put(entityObj, checkAccess.accessType());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,11 +204,11 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
|
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
|
||||||
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
|
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
|
||||||
" is not accessible]");
|
" is not accessible]");
|
||||||
} catch (final IllegalAccessException e) {
|
} catch (final IllegalAccessException e) {
|
||||||
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
|
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
|
||||||
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
|
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
|
||||||
" is not accessible]");
|
" is not accessible]");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -248,118 +248,119 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
final CommandType fieldType = annotation.type();
|
final CommandType fieldType = annotation.type();
|
||||||
switch (fieldType) {
|
switch (fieldType) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
|
field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
|
||||||
break;
|
break;
|
||||||
case DATE:
|
case DATE:
|
||||||
// This piece of code is for maintaining backward compatibility
|
// This piece of code is for maintaining backward compatibility
|
||||||
// and support both the date formats(Bug 9724)
|
// and support both the date formats(Bug 9724)
|
||||||
// Do the date messaging for ListEventsCmd only
|
// Do the date messaging for ListEventsCmd only
|
||||||
if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd ||
|
if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd ||
|
||||||
cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd) {
|
cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd) {
|
||||||
final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
|
final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
|
||||||
if (isObjInNewDateFormat) {
|
if (isObjInNewDateFormat) {
|
||||||
final DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
|
final DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
|
||||||
synchronized (newFormat) {
|
synchronized (newFormat) {
|
||||||
field.set(cmdObj, newFormat.parse(paramObj.toString()));
|
field.set(cmdObj, newFormat.parse(paramObj.toString()));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final DateFormat format = BaseCmd.INPUT_FORMAT;
|
|
||||||
synchronized (format) {
|
|
||||||
Date date = format.parse(paramObj.toString());
|
|
||||||
if (field.getName().equals("startDate")) {
|
|
||||||
date = messageDate(date, 0, 0, 0);
|
|
||||||
} else if (field.getName().equals("endDate")) {
|
|
||||||
date = messageDate(date, 23, 59, 59);
|
|
||||||
}
|
|
||||||
field.set(cmdObj, date);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final DateFormat format = BaseCmd.INPUT_FORMAT;
|
final DateFormat format = BaseCmd.INPUT_FORMAT;
|
||||||
synchronized (format) {
|
synchronized (format) {
|
||||||
format.setLenient(false);
|
Date date = format.parse(paramObj.toString());
|
||||||
field.set(cmdObj, format.parse(paramObj.toString()));
|
if (field.getName().equals("startDate")) {
|
||||||
}
|
date = messageDate(date, 0, 0, 0);
|
||||||
}
|
} else if (field.getName().equals("endDate")) {
|
||||||
break;
|
date = messageDate(date, 23, 59, 59);
|
||||||
case FLOAT:
|
|
||||||
// Assuming that the parameters have been checked for required before now,
|
|
||||||
// we ignore blank or null values and defer to the command to set a default
|
|
||||||
// value for optional parameters ...
|
|
||||||
if (paramObj != null && isNotBlank(paramObj.toString())) {
|
|
||||||
field.set(cmdObj, Float.valueOf(paramObj.toString()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case INTEGER:
|
|
||||||
// Assuming that the parameters have been checked for required before now,
|
|
||||||
// we ignore blank or null values and defer to the command to set a default
|
|
||||||
// value for optional parameters ...
|
|
||||||
if (paramObj != null && isNotBlank(paramObj.toString())) {
|
|
||||||
field.set(cmdObj, Integer.valueOf(paramObj.toString()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LIST:
|
|
||||||
final List listParam = new ArrayList();
|
|
||||||
final StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
|
|
||||||
while (st.hasMoreTokens()) {
|
|
||||||
final String token = st.nextToken();
|
|
||||||
final CommandType listType = annotation.collectionType();
|
|
||||||
switch (listType) {
|
|
||||||
case INTEGER:
|
|
||||||
listParam.add(Integer.valueOf(token));
|
|
||||||
break;
|
|
||||||
case UUID:
|
|
||||||
if (token.isEmpty())
|
|
||||||
break;
|
|
||||||
final Long internalId = translateUuidToInternalId(token, annotation);
|
|
||||||
listParam.add(internalId);
|
|
||||||
break;
|
|
||||||
case LONG: {
|
|
||||||
listParam.add(Long.valueOf(token));
|
|
||||||
}
|
}
|
||||||
break;
|
field.set(cmdObj, date);
|
||||||
case SHORT:
|
|
||||||
listParam.add(Short.valueOf(token));
|
|
||||||
case STRING:
|
|
||||||
listParam.add(token);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
field.set(cmdObj, listParam);
|
} else {
|
||||||
break;
|
final DateFormat format = BaseCmd.INPUT_FORMAT;
|
||||||
case UUID:
|
synchronized (format) {
|
||||||
final Long internalId = translateUuidToInternalId(paramObj.toString(), annotation);
|
format.setLenient(false);
|
||||||
field.set(cmdObj, internalId);
|
field.set(cmdObj, format.parse(paramObj.toString()));
|
||||||
break;
|
}
|
||||||
case LONG:
|
}
|
||||||
field.set(cmdObj, Long.valueOf(paramObj.toString()));
|
break;
|
||||||
break;
|
case FLOAT:
|
||||||
case SHORT:
|
// Assuming that the parameters have been checked for required before now,
|
||||||
field.set(cmdObj, Short.valueOf(paramObj.toString()));
|
// we ignore blank or null values and defer to the command to set a default
|
||||||
break;
|
// value for optional parameters ...
|
||||||
case STRING:
|
if (paramObj != null && isNotBlank(paramObj.toString())) {
|
||||||
if ((paramObj != null)) {
|
field.set(cmdObj, Float.valueOf(paramObj.toString()));
|
||||||
if (paramObj.toString().length() > annotation.length()) {
|
}
|
||||||
s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
|
break;
|
||||||
throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
|
case INTEGER:
|
||||||
} else {
|
// Assuming that the parameters have been checked for required before now,
|
||||||
field.set(cmdObj, paramObj.toString());
|
// we ignore blank or null values and defer to the command to set a default
|
||||||
}
|
// value for optional parameters ...
|
||||||
|
if (paramObj != null && isNotBlank(paramObj.toString())) {
|
||||||
|
field.set(cmdObj, Integer.valueOf(paramObj.toString()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LIST:
|
||||||
|
final List listParam = new ArrayList();
|
||||||
|
final StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
|
||||||
|
while (st.hasMoreTokens()) {
|
||||||
|
final String token = st.nextToken();
|
||||||
|
final CommandType listType = annotation.collectionType();
|
||||||
|
switch (listType) {
|
||||||
|
case INTEGER:
|
||||||
|
listParam.add(Integer.valueOf(token));
|
||||||
|
break;
|
||||||
|
case UUID:
|
||||||
|
if (token.isEmpty())
|
||||||
|
break;
|
||||||
|
final Long internalId = translateUuidToInternalId(token, annotation);
|
||||||
|
listParam.add(internalId);
|
||||||
|
break;
|
||||||
|
case LONG: {
|
||||||
|
listParam.add(Long.valueOf(token));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TZDATE:
|
case SHORT:
|
||||||
field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
|
listParam.add(Short.valueOf(token));
|
||||||
break;
|
break;
|
||||||
case MAP:
|
case STRING:
|
||||||
default:
|
listParam.add(token);
|
||||||
field.set(cmdObj, paramObj);
|
break;
|
||||||
break;
|
}
|
||||||
|
}
|
||||||
|
field.set(cmdObj, listParam);
|
||||||
|
break;
|
||||||
|
case UUID:
|
||||||
|
final Long internalId = translateUuidToInternalId(paramObj.toString(), annotation);
|
||||||
|
field.set(cmdObj, internalId);
|
||||||
|
break;
|
||||||
|
case LONG:
|
||||||
|
field.set(cmdObj, Long.valueOf(paramObj.toString()));
|
||||||
|
break;
|
||||||
|
case SHORT:
|
||||||
|
field.set(cmdObj, Short.valueOf(paramObj.toString()));
|
||||||
|
break;
|
||||||
|
case STRING:
|
||||||
|
if ((paramObj != null)) {
|
||||||
|
if (paramObj.toString().length() > annotation.length()) {
|
||||||
|
s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
|
||||||
|
throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
|
||||||
|
} else {
|
||||||
|
field.set(cmdObj, paramObj.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TZDATE:
|
||||||
|
field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
|
||||||
|
break;
|
||||||
|
case MAP:
|
||||||
|
default:
|
||||||
|
field.set(cmdObj, paramObj);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (final IllegalAccessException ex) {
|
} catch (final IllegalAccessException ex) {
|
||||||
s_logger.error("Error initializing command " + cmdObj.getCommandName() + ", field " + field.getName() + " is not accessible.");
|
s_logger.error("Error initializing command " + cmdObj.getCommandName() + ", field " + field.getName() + " is not accessible.");
|
||||||
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() +
|
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() +
|
||||||
" is not accessible]");
|
" is not accessible]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +439,7 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||||||
if (s_logger.isDebugEnabled())
|
if (s_logger.isDebugEnabled())
|
||||||
s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
|
s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
|
||||||
throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid +
|
throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid +
|
||||||
" due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
|
" due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
|
||||||
}
|
}
|
||||||
return internalId;
|
return internalId;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user