Skip to content

Commit f8a483f

Browse files
committed
api: Include cloudstack-version in both xml and json api response
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
1 parent 59fc89a commit f8a483f

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

api/src/org/apache/cloudstack/api/BaseCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ public String buildResponse(ServerApiException apiException, String responseType
308308
StringBuffer sb = new StringBuffer();
309309
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
310310
// JSON response
311-
sb.append("{ \"" + getCommandName() + "\" : { " + "\"@attributes\":{\"cloud-stack-version\":\"" + _mgr.getVersion() + "\"},");
311+
sb.append("{ \"" + getCommandName() + "\" : { " + "\"@attributes\":{\"cloudstack-version\":\"" + _mgr.getVersion() + "\"},");
312312
sb.append("\"errorcode\" : \"" + apiException.getErrorCode() + "\", \"description\" : \"" + apiException.getDescription() + "\" } }");
313313
} else {
314314
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
315315
sb.append("<" + getCommandName() + ">");
316316
sb.append("<errorcode>" + apiException.getErrorCode() + "</errorcode>");
317317
sb.append("<description>" + escapeXml(apiException.getDescription()) + "</description>");
318-
sb.append("</" + getCommandName() + " cloud-stack-version=\"" + _mgr.getVersion() + "\">");
318+
sb.append("</" + getCommandName() + " cloudstack-version=\"" + _mgr.getVersion() + "\">");
319319
}
320320
return sb.toString();
321321
}
@@ -326,10 +326,10 @@ public String buildResponse(List<Pair<String, Object>> tagList, String responseT
326326

327327
// set up the return value with the name of the response
328328
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
329-
prefixSb.append("{ \"" + getCommandName() + "\" : { \"@attributes\":{\"cloud-stack-version\":\"" + _mgr.getVersion() + "\"},");
329+
prefixSb.append("{ \"" + getCommandName() + "\" : { \"@attributes\":{\"cloudstack-version\":\"" + _mgr.getVersion() + "\"},");
330330
} else {
331331
prefixSb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
332-
prefixSb.append("<" + getCommandName() + " cloud-stack-version=\"" + _mgr.getVersion() + "\">");
332+
prefixSb.append("<" + getCommandName() + " cloudstack-version=\"" + _mgr.getVersion() + "\">");
333333
}
334334

335335
int i = 0;

server/src/com/cloud/api/ApiServlet.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,13 @@ private String getLoginSuccessResponse(HttpSession session, String responseType)
411411
}
412412
}
413413
}
414-
sb.append(" } }");
414+
sb.append(" }");
415+
sb.append(", \"cloudstack-version\": \"");
416+
sb.append(ApiDBUtils.getVersion());
417+
sb.append("\" }");
415418
} else {
416419
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
417-
sb.append("<loginresponse cloud-stack-version=\"" + ApiDBUtils.getVersion() + "\">");
420+
sb.append("<loginresponse cloudstack-version=\"" + ApiDBUtils.getVersion() + "\">");
418421
sb.append("<timeout>" + inactiveInterval + "</timeout>");
419422
Enumeration attrNames = session.getAttributeNames();
420423
if (attrNames != null) {
@@ -441,10 +444,13 @@ private String getLoginSuccessResponse(HttpSession session, String responseType)
441444
private String getLogoutSuccessResponse(String responseType) {
442445
StringBuffer sb = new StringBuffer();
443446
if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
444-
sb.append("{ \"logoutresponse\" : { \"description\" : \"success\" } }");
447+
sb.append("{ \"logoutresponse\" : { \"description\" : \"success\" }");
448+
sb.append(", \"cloudstack-version\": \"");
449+
sb.append(ApiDBUtils.getVersion());
450+
sb.append("\" }");
445451
} else {
446452
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
447-
sb.append("<logoutresponse cloud-stack-version=\"" + ApiDBUtils.getVersion() + "\">");
453+
sb.append("<logoutresponse cloudstack-version=\"" + ApiDBUtils.getVersion() + "\">");
448454
sb.append("<description>success</description>");
449455
sb.append("</logoutresponse>");
450456
}

server/src/com/cloud/api/response/ApiResponseSerializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public static String toJSONSerializedString(ResponseObject result) {
122122
sb.append("{ }");
123123
}
124124
}
125-
sb.append(" }");
125+
sb.append(", \"cloudstack-version\": \"");
126+
sb.append(ApiDBUtils.getVersion());
127+
sb.append("\" }");
126128
return sb.toString();
127129
}
128130
return null;
@@ -131,7 +133,7 @@ public static String toJSONSerializedString(ResponseObject result) {
131133
private static String toXMLSerializedString(ResponseObject result) {
132134
StringBuilder sb = new StringBuilder();
133135
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
134-
sb.append("<").append(result.getResponseName()).append(" cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\">");
136+
sb.append("<").append(result.getResponseName()).append(" cloudstack-version=\"").append(ApiDBUtils.getVersion()).append("\">");
135137

136138
if (result instanceof ListResponse) {
137139
Integer count = ((ListResponse) result).getCount();

0 commit comments

Comments
 (0)