Github user DaanHoogland commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/1021#discussion_r45461347
--- Diff: server/src/com/cloud/api/response/ApiResponseSerializer.java ---
@@ -127,53 +151,74 @@ public static String
toJSONSerializedString(ResponseObject result) {
} else {
sb.append("{}");
}
+ String logStr = logBuilder.toJson(result);
+ if (logStr != null && !logStr.isEmpty()) {
+ logStr = unescape(logStr);
+ if (result instanceof AsyncJobResponse || result
instanceof CreateCmdResponse || result instanceof AuthenticationCmdResponse) {
+ log.append(logStr);
+ } else {
+
log.append("{\"").append(result.getObjectName()).append("\":").append(logStr).append("}");
+ }
+ } else {
+ log.append("{}");
+ }
}
sb.append("}");
+ log.append("}");
return sb.toString();
}
return null;
}
- private static String toXMLSerializedString(ResponseObject result) {
- StringBuilder sb = new StringBuilder();
- sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- sb.append("<").append(result.getResponseName()).append("
cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\">");
+ private static String toXMLSerializedString(ResponseObject result,
StringBuilder log) {
+ if (result != null && log != null) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ sb.append("<").append(result.getResponseName()).append("
cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\">");
+ log.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ log.append("<").append(result.getResponseName()).append("
cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\">");
- if (result instanceof ListResponse) {
- Integer count = ((ListResponse)result).getCount();
+ if (result instanceof ListResponse) {
+ Integer count = ((ListResponse)result).getCount();
- if (count != null && count != 0) {
-
sb.append("<").append(ApiConstants.COUNT).append(">").append(((ListResponse)result).getCount()).append("</").append(ApiConstants.COUNT).append(">");
- }
- List<? extends ResponseObject> responses =
((ListResponse)result).getResponses();
- if ((responses != null) && !responses.isEmpty()) {
- for (ResponseObject obj : responses) {
- serializeResponseObjXML(sb, obj);
+ if (count != null && count != 0) {
+
sb.append("<").append(ApiConstants.COUNT).append(">").append(((ListResponse)result).getCount()).append("</").append(ApiConstants.COUNT).append(">");
+
log.append("<").append(ApiConstants.COUNT).append(">").append(((ListResponse)result).getCount()).append("</").append(ApiConstants.COUNT).append(">");
+ }
+ List<? extends ResponseObject> responses =
((ListResponse)result).getResponses();
+ if ((responses != null) && !responses.isEmpty()) {
+ for (ResponseObject obj : responses) {
+ serializeResponseObjXML(sb, log, obj);
+ }
}
- }
- } else {
- if (result instanceof CreateCmdResponse || result instanceof
AsyncJobResponse || result instanceof AuthenticationCmdResponse) {
- serializeResponseObjFieldsXML(sb, result);
} else {
- serializeResponseObjXML(sb, result);
+ if (result instanceof CreateCmdResponse || result
instanceof AsyncJobResponse || result instanceof AuthenticationCmdResponse) {
+ serializeResponseObjFieldsXML(sb, log, result);
+ } else {
+ serializeResponseObjXML(sb, log, result);
+ }
}
- }
- sb.append("</").append(result.getResponseName()).append(">");
- return sb.toString();
+ sb.append("</").append(result.getResponseName()).append(">");
+ log.append("</").append(result.getResponseName()).append(">");
--- End diff --
@koushik-das I see this happening in a few places. I'm fine with it but
from a performance point of view it might not be optimal.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---