diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index efd42940e67..a10f9ed0b9f 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -120,6 +120,7 @@ public class ApiServer implements HttpRequestHandler { public static final short RESOURCE_DOMAIN_ADMIN_COMMAND = 2; public static final short USER_COMMAND = 8; public static boolean encodeApiResponse = false; + public static String jsonContentType = "text/javascript"; private Properties _apiCommands = null; private ApiDispatcher _dispatcher; private ManagementServer _ms = null; @@ -233,6 +234,11 @@ public class ApiServer implements HttpRequestHandler { } encodeApiResponse = Boolean.valueOf(configDao.getValue(Config.EncodeApiResponse.key())); + + String jsonType = configDao.getValue(Config.JavaScriptDefaultContentType.key()); + if (jsonType != null) { + jsonContentType = jsonType; + } ListenerThread listenerThread = new ListenerThread(this, apiPort); listenerThread.start(); @@ -773,7 +779,7 @@ public class ApiServer implements HttpRequestHandler { BasicHttpEntity body = new BasicHttpEntity(); if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { // JSON response - body.setContentType("text/javascript"); + body.setContentType(jsonContentType); if (responseText == null) { body.setContent(new ByteArrayInputStream("{ \"error\" : { \"description\" : \"Internal Server Error\" } }".getBytes("UTF-8"))); } diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index ec705e3a2fb..4e1fe904584 100755 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -352,7 +352,7 @@ public class ApiServlet extends HttpServlet { private void writeResponse(HttpServletResponse resp, String response, int responseCode, String responseType) { try { if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { - resp.setContentType("text/javascript; charset=UTF-8"); + resp.setContentType(ApiServer.jsonContentType + "; charset=UTF-8"); } else { resp.setContentType("text/xml; charset=UTF-8"); } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 3afab7e2a69..28db5c03eb8 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -273,7 +273,9 @@ public enum Config { DnsBasicZoneUpdates("Advanced", NetworkManager.class, String.class, "network.dns.basiczone.updates", "all", "This parameter can take 2 values: all (default) and pod. It defines if DHCP/DNS requests have to be send to all dhcp servers in cloudstack, or only to the one in the same pod", "all,pod"), ClusterMessageTimeOutSeconds("Advanced", ManagementServer.class, Integer.class, "cluster.message.timeout.seconds", "300", "Time (in seconds) to wait before a inter-management server message post times out.", null), - AgentLoadThreshold("Advanced", ManagementServer.class, Float.class, "agent.load.threshold", "0.7", "Percentage (as a value between 0 and 1) of connected agents after which agent load balancing will start happening", null); + AgentLoadThreshold("Advanced", ManagementServer.class, Float.class, "agent.load.threshold", "0.7", "Percentage (as a value between 0 and 1) of connected agents after which agent load balancing will start happening", null), + + JavaScriptDefaultContentType("Advanced", ManagementServer.class, String.class, "json.content.type", "text/javascript", "Http response content type for .js files (default is text/javascript)", null); private final String _category; private final Class _componentClass; diff --git a/setup/db/db/schema-2211to2212.sql b/setup/db/db/schema-2211to2212.sql index 6a83a917c36..faaf7ae304f 100644 --- a/setup/db/db/schema-2211to2212.sql +++ b/setup/db/db/schema-2211to2212.sql @@ -6,3 +6,5 @@ ALTER TABLE `cloud`.`vm_template` ADD COLUMN `template_tag` varchar(255) COMMENT UPDATE vm_instance SET state='Error' WHERE state='Creating' AND removed IS null; +INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-server', 'json.content.type', 'text/javascript', 'Http response content type for .js files (default is text/javascript)'); +