api: Include cloudstack-version in both xml and json api response

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2012-12-16 21:37:03 -08:00
parent 59fc89abe3
commit f8a483fc5a
3 changed files with 18 additions and 10 deletions

View File

@ -308,14 +308,14 @@ public abstract class BaseCmd {
StringBuffer sb = new StringBuffer();
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
// JSON response
sb.append("{ \"" + getCommandName() + "\" : { " + "\"@attributes\":{\"cloud-stack-version\":\"" + _mgr.getVersion() + "\"},");
sb.append("{ \"" + getCommandName() + "\" : { " + "\"@attributes\":{\"cloudstack-version\":\"" + _mgr.getVersion() + "\"},");
sb.append("\"errorcode\" : \"" + apiException.getErrorCode() + "\", \"description\" : \"" + apiException.getDescription() + "\" } }");
} else {
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
sb.append("<" + getCommandName() + ">");
sb.append("<errorcode>" + apiException.getErrorCode() + "</errorcode>");
sb.append("<description>" + escapeXml(apiException.getDescription()) + "</description>");
sb.append("</" + getCommandName() + " cloud-stack-version=\"" + _mgr.getVersion() + "\">");
sb.append("</" + getCommandName() + " cloudstack-version=\"" + _mgr.getVersion() + "\">");
}
return sb.toString();
}
@ -326,10 +326,10 @@ public abstract class BaseCmd {
// set up the return value with the name of the response
if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
prefixSb.append("{ \"" + getCommandName() + "\" : { \"@attributes\":{\"cloud-stack-version\":\"" + _mgr.getVersion() + "\"},");
prefixSb.append("{ \"" + getCommandName() + "\" : { \"@attributes\":{\"cloudstack-version\":\"" + _mgr.getVersion() + "\"},");
} else {
prefixSb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
prefixSb.append("<" + getCommandName() + " cloud-stack-version=\"" + _mgr.getVersion() + "\">");
prefixSb.append("<" + getCommandName() + " cloudstack-version=\"" + _mgr.getVersion() + "\">");
}
int i = 0;

View File

@ -411,10 +411,13 @@ public class ApiServlet extends HttpServlet {
}
}
}
sb.append(" } }");
sb.append(" }");
sb.append(", \"cloudstack-version\": \"");
sb.append(ApiDBUtils.getVersion());
sb.append("\" }");
} else {
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
sb.append("<loginresponse cloud-stack-version=\"" + ApiDBUtils.getVersion() + "\">");
sb.append("<loginresponse cloudstack-version=\"" + ApiDBUtils.getVersion() + "\">");
sb.append("<timeout>" + inactiveInterval + "</timeout>");
Enumeration attrNames = session.getAttributeNames();
if (attrNames != null) {
@ -441,10 +444,13 @@ public class ApiServlet extends HttpServlet {
private String getLogoutSuccessResponse(String responseType) {
StringBuffer sb = new StringBuffer();
if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
sb.append("{ \"logoutresponse\" : { \"description\" : \"success\" } }");
sb.append("{ \"logoutresponse\" : { \"description\" : \"success\" }");
sb.append(", \"cloudstack-version\": \"");
sb.append(ApiDBUtils.getVersion());
sb.append("\" }");
} else {
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
sb.append("<logoutresponse cloud-stack-version=\"" + ApiDBUtils.getVersion() + "\">");
sb.append("<logoutresponse cloudstack-version=\"" + ApiDBUtils.getVersion() + "\">");
sb.append("<description>success</description>");
sb.append("</logoutresponse>");
}

View File

@ -122,7 +122,9 @@ public class ApiResponseSerializer {
sb.append("{ }");
}
}
sb.append(" }");
sb.append(", \"cloudstack-version\": \"");
sb.append(ApiDBUtils.getVersion());
sb.append("\" }");
return sb.toString();
}
return null;
@ -131,7 +133,7 @@ public class ApiResponseSerializer {
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("\">");
sb.append("<").append(result.getResponseName()).append(" cloudstack-version=\"").append(ApiDBUtils.getVersion()).append("\">");
if (result instanceof ListResponse) {
Integer count = ((ListResponse) result).getCount();