From ab6c8f7986923e73567383379696afe1db01d9d2 Mon Sep 17 00:00:00 2001 From: Vijayendra Bhamidipati Date: Fri, 11 May 2012 14:44:24 -0700 Subject: [PATCH] Bug CS-14853: CloudStack list APIs are listing incorrect IDs for all the entities when API response set to "xml". works fine for "json" Bug 14071: queryAsyncJobResult in xml format gives incorrect UUIDs back Description: CS-14853 is the same bug as 14071, but seen in Bonita branch owing to the fix not being merged from master. So putting in the same fix to 3.0.x branch. Description of fix follows. Incorrectly removed part of the XML serializer that serialized the IdentityProxy object in normal responses, when putting in support for serialization of lists of IdentityProxy objects in exception responses as part of the code changes put in for bug 13217, resulting in this bug. Putting it back in place. --- .../api/response/ApiResponseSerializer.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/api/response/ApiResponseSerializer.java b/server/src/com/cloud/api/response/ApiResponseSerializer.java index 721fa0aad56..1feab79f23b 100644 --- a/server/src/com/cloud/api/response/ApiResponseSerializer.java +++ b/server/src/com/cloud/api/response/ApiResponseSerializer.java @@ -207,6 +207,7 @@ public class ApiResponseSerializer { } serializeResponseObjXML(sb, subObj); } else if (value instanceof IdentityProxy) { + // Only exception reponses carry a list of IdentityProxy objects. IdentityProxy idProxy = (IdentityProxy)value; String id = (idProxy.getValue() != null ? String.valueOf(idProxy.getValue()) : ""); if(!id.isEmpty()) { @@ -233,7 +234,20 @@ public class ApiResponseSerializer { sb.append(""); } } else if (fieldValue instanceof Date) { - sb.append("<" + serializedName.value() + ">" + BaseCmd.getDateString((Date) fieldValue) + ""); + sb.append("<" + serializedName.value() + ">" + BaseCmd.getDateString((Date) fieldValue) + ""); + } else if (fieldValue instanceof IdentityProxy) { + IdentityProxy idProxy = (IdentityProxy)fieldValue; + String id = (idProxy.getValue() != null ? String.valueOf(idProxy.getValue()) : ""); + if(!id.isEmpty()) { + IdentityDao identityDao = new IdentityDaoImpl(); + if(idProxy.getTableName() != null) { + id = identityDao.getIdentityUuid(idProxy.getTableName(), id); + } else { + s_logger.warn("IdentityProxy sanity check issue, invalid IdentityProxy table name found in class: " + obj.getClass().getName()); + } + } + if(id != null && !id.isEmpty()) + sb.append("<" + serializedName.value() + ">" + id + ""); } else { String resultString = escapeSpecialXmlChars(fieldValue.toString()); if (!(obj instanceof ExceptionResponse)) {