mirror of https://github.com/apache/cloudstack.git
Fix up setting the response object correctly after dispatching the api method call. Begin working on the serialization of the responses which don't include the command name just yet, that's coming.
This commit is contained in:
parent
b42ca89626
commit
4a73639d67
|
|
@ -93,7 +93,7 @@ public class AsyncJobResult {
|
|||
}
|
||||
|
||||
public void setResultObject(Object result) {
|
||||
this.result = SerializerHelper.toSerializedString(result);
|
||||
this.result = SerializerHelper.toSerializedStringOld(result);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import com.google.gson.Gson;
|
|||
public class SerializerHelper {
|
||||
public static final Logger s_logger = Logger.getLogger(SerializerHelper.class.getName());
|
||||
|
||||
public static String toSerializedString(Object result) {
|
||||
public static String toSerializedStringOld(Object result) {
|
||||
if(result != null) {
|
||||
Class<?> clz = result.getClass();
|
||||
Gson gson = GsonHelper.getBuilder().create();
|
||||
|
|
@ -47,6 +47,16 @@ public class SerializerHelper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// FIXME: what about XML response?
|
||||
public static String toSerializedString(Object result) {
|
||||
if (result != null) {
|
||||
Gson gson = GsonHelper.getBuilder().create();
|
||||
|
||||
return gson.toJson(result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object fromSerializedString(String result) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -102,8 +102,12 @@ public class ApiDispatcher {
|
|||
|
||||
try {
|
||||
Method method = mgr.getClass().getMethod(methodName, cmd.getClass());
|
||||
method.invoke(mgr, cmd);
|
||||
return cmd.getId();
|
||||
Object dbObject = method.invoke(mgr, cmd);
|
||||
|
||||
Method getIdMethod = dbObject.getClass().getMethod("getId");
|
||||
Object id = getIdMethod.invoke(dbObject);
|
||||
|
||||
return (Long)id;
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
s_logger.warn("Exception executing method " + methodName + " for command " + cmd.getClass().getSimpleName(), nsme);
|
||||
throw new CloudRuntimeException("Unable to execute method " + methodName + " for command " + cmd.getClass().getSimpleName() + ", unable to find implementation.");
|
||||
|
|
@ -148,7 +152,8 @@ public class ApiDispatcher {
|
|||
|
||||
try {
|
||||
Method method = mgr.getClass().getMethod(methodName, cmd.getClass());
|
||||
method.invoke(mgr, cmd);
|
||||
Object result = method.invoke(mgr, cmd);
|
||||
cmd.setResponseObject(result);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
s_logger.warn("Exception executing method " + methodName + " for command " + cmd.getClass().getSimpleName(), nsme);
|
||||
throw new CloudRuntimeException("Unable to execute method " + methodName + " for command " + cmd.getClass().getSimpleName() + ", unable to find implementation.");
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
|
|||
private Long startEventId;
|
||||
|
||||
public String getResponse(long jobId) {
|
||||
// FIXME: We need a generic response object here, see BaseAsyncCreateCmd
|
||||
return SerializerHelper.toSerializedString(Long.valueOf(jobId));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,8 +151,11 @@ public class AsyncJobManagerImpl implements AsyncJobManager {
|
|||
job.setInstanceId(null);
|
||||
|
||||
// FIXME: do we need to re-serialize here?
|
||||
if(resultObject != null)
|
||||
job.setResult(SerializerHelper.toSerializedString(resultObject));
|
||||
if (resultObject != null) {
|
||||
// job.setResult(SerializerHelper.toSerializedString(resultObject));
|
||||
job.setResult((String)resultObject);
|
||||
}
|
||||
|
||||
job.setLastUpdated(DateUtil.currentGMTTime());
|
||||
_jobDao.update(jobId, job);
|
||||
txt.commit();
|
||||
|
|
|
|||
Loading…
Reference in New Issue